gEconpy.model.model.impulse_response_function#

gEconpy.model.model.impulse_response_function(model, T=None, R=None, simulation_length=40, shock_size=None, shock_cov=None, shock_trajectory=None, return_individual_shocks=None, orthogonalize_shocks=False, random_seed=None, **solve_model_kwargs)#

Generate impulse response functions (IRF) from state space model dynamics.

An impulse response function represents the dynamic response of the state space model to an instantaneous shock applied to the system. This function calculates the IRF based on either provided shock specifications or the posterior state covariance matrix.

Parameters:
model: Model

DSGE Model object

T: np.ndarray, optional

Transition matrix of the solved system. If None, this will be computed using the model’s solve_model method.

R: np.ndarray, optional

Selection matrix of the solved system. If None, this will be computed using the model’s solve_model method.

simulation_lengthint, optional

The number of periods to compute the IRFs over. The default is 40.

shock_sizefloat, array, or dict; default=None

The size of the shock applied to the system. If specified, it will create a covariance matrix for the shock with diagonal elements equal to shock_size:

  • If float, the covariance matrix will be the identity matrix scaled by shock_size.

  • If array, the covariance matrix will be diag(shock_size). In this case, the length of the provided array must match the number of shocks in the state space model.

  • If dictionary, a diagonal matrix will be created with entries corresponding to the keys in the dictionary. Shocks that are not specified will be set to zero.

Only one of use_stationary_cov, shock_cov, shock_size, or shock_trajectory can be specified.

shock_covOptional[np.ndarray], default=None

A user-specified covariance matrix for the shocks. It should be a 2D numpy array with dimensions (n_shocks, n_shocks), where n_shocks is the number of shocks in the state space model.

Only one of use_stationary_cov, shock_cov, shock_size, or shock_trajectory can be specified.

shock_trajectoryOptional[np.ndarray], default=None

A pre-defined trajectory of shocks applied to the system. It should be a 2D numpy array with dimensions (n, n_shocks), where n is the number of time steps and k_posdef is the number of shocks in the state space model.

Only one of use_stationary_cov, shock_cov, shock_size, or shock_trajectory can be specified.

return_individual_shocks: bool, optional

If True, an IRF will be computed separately for each shock in the model. An additional dimension will be added to the output DataArray to show each shock. This is only valid if shock_size is a scalar, dictionary, or if the covariance matrix is diagonal.

If not specified, this will be set to True if shock_size if the above conditions are met.

orthogonalize_shocksbool, default=False

If True, orthogonalize the shocks using Cholesky decomposition when generating the impulse response. This option is ignored if shock_trajectory or shock_size are used, or if the covariance matrix is diagonal.

random_seedint, RandomState or Generator, optional

Seed for the random number generator.

**solve_model_kwargs

Arguments forwarded to the solve_model method. Ignored if T and R are provided.

Returns:
xr.DataArray

The IRFs for each variable in the model.