sid.msm

Estimate models with the method of simulated moments (MSM).

The method of simulated moments is developed by 1, 2, and 3 and an estimation technique where the distance between the moments of the actual data and the moments implied by the model parameters is minimized.

References:

1

McFadden, D. (1989). A method of simulated moments for estimation of discrete response models without numerical integration. Econometrica: Journal of the Econometric Society, 995-1026.

2

Lee, B. S., & Ingram, B. F. (1991). Simulation estimation of time-series models. Journal of Econometrics, 47(2-3), 197-205.

3

Duffie, D., & Singleton, K. (1993). Simulated Moments Estimation of Markov Models of Asset Prices. Econometrica, 61(4), 929-952.

Module Contents

Functions

get_msm_func(simulate, calc_moments, empirical_moments, replace_nans, weighting_matrix=None, additional_outputs=None)

Get the msm function.

_msm(params, simulate, calc_moments, empirical_moments, replace_nans, weighting_matrix, additional_outputs)

The MSM criterion function.

get_diag_weighting_matrix(empirical_moments, weights=None)

Create a diagonal weighting matrix from weights.

get_flat_moments(empirical_moments)

Compute the empirical moments flat indexes.

_harmonize_input(data)

Harmonize different types of inputs by turning all inputs into dicts.

_flatten_index(data)

Flatten the index as a combination of the former index and the columns.

_is_diagonal(mat)

Check if the matrix is diagonal.

_is_dict_of_callables(x)

get_msm_func(simulate, calc_moments, empirical_moments, replace_nans, weighting_matrix=None, additional_outputs=None)[source]

Get the msm function.

Parameters
  • simulate (callable) – Function which accepts parameters and returns simulated data.

  • calc_moments (callable or dict) – Function(s) used to calculate simulated moments. If it is a dictionary, it must have the same keys as empirical_moments

  • empirical_moments (pandas.DataFrame or pandas.Series or dict) – One pandas object or a dictionary of pandas objects with empirical moments.

  • replace_nans (callable or list) – Functions(s) specifying how to handle NaNs in simulated_moments. Must match structure of empirical_moments. Exception: If only one replacement function is specified, it will be used on all sets of simulated moments.

  • weighting_matrix (numpy.ndarray) – Square matrix of dimension (NxN) with N denoting the number of empirical_moments. Used to weight squared moment errors.

  • additional_outputs (dict or None) – Dictionary of functions. Each function is evaluated on the output of the simulate function and the result is saved in the output dictionary of the msm function.

Returns

MSM function where all arguments except the parameter

vector are set.

Return type

msm_func (callable)

_msm(params, simulate, calc_moments, empirical_moments, replace_nans, weighting_matrix, additional_outputs)[source]

The MSM criterion function.

This function will be prepared by get_msm_func() and have all its arguments except params attached to it.

get_diag_weighting_matrix(empirical_moments, weights=None)[source]

Create a diagonal weighting matrix from weights.

Parameters
  • empirical_moments (pandas.DataFrame or pandas.Series or dict or list) – Contains the empirical moments calculated for the observed data. Moments should be saved to pandas.DataFrame or pandas.Series that can either be passed to the function directly or as items of a list or dictionary.

  • weights (pandas.DataFrame or pandas.Series or dict or list) – Contains weights (usually variances) of empirical moments. Must match structure of empirical_moments i.e. if empirical_moments is a list of pandas.DataFrame, weights be list of pandas.DataFrames as well where each DataFrame entry contains the weight for the corresponding moment in empirical_moments.

Returns

Array contains a diagonal weighting matrix.

Return type

(numpy.ndarray)

get_flat_moments(empirical_moments)[source]

Compute the empirical moments flat indexes.

Parameters

empirical_moments (pandas.DataFrame or pandas.Series or dict or list) – Containing pandas.DataFrame or pandas.Series. Contains the empirical moments calculated for the observed data. Moments should be saved to pandas.DataFrame or pandas.Series that can either be passed to the function directly or as items of a list or dictionary.

Returns

Vector of empirical_moments with flat

index.

Return type

flat_empirical_moments (pandas.DataFrame)

_harmonize_input(data)[source]

Harmonize different types of inputs by turning all inputs into dicts.

_flatten_index(data)[source]

Flatten the index as a combination of the former index and the columns.

_is_diagonal(mat)[source]

Check if the matrix is diagonal.

_is_dict_of_callables(x)[source]