cge_modeling.base.cge.CGEModel.simulate#

CGEModel.simulate(initial_state, final_values=None, final_delta=None, final_delta_pct=None, use_euler_approximation=True, use_optimizer=True, optimizer_mode='root', n_iter_euler=10000, compile_kwargs=None, save_results=False, overwrite=False, output_path='results/', simulation_name=None, verbose=True, **optimizer_kwargs)#

Simulate a shock to the model economy by computing the equilibrium state of the economy at the provided post-shock values.

Parameters:
initial_state: dict[str, np.ndarray]

A dictionary of initial values for the model variables and parameters. The keys should be the names of the variables and parameters, and the values should be numpy arrays of the same shape as the variable or parameter.

Warning

The inital state must represent a model equlibrium! This will be checked automatically

before simulation begins, and an error will be raised if the initial state does not represent an equlibrium.

final_values: dict[str, np.ndarray], optional

A dictionary of exact final values for a subset of model parameters. The keys should be the names of the parameters to be changed, and the values should be numpy arrays of the same shape as the parameter.

Exactly one of final_values, final_delta, or final_delta_pct must be provided.

final_delta: dict[str, np.ndarray], optional

A dictionary of changes to be applied to a subset of the model parameters. Changes are added to the initial values, so that positive values increase the parameter value and negative values decrease the parameter. The keys should be the names of the parameters to be changed, and the values should be numpy arrays of the same shape as the parameter.

Exactly one of final_values, final_delta, or final_delta_pct must be provided.

final_delta_pct: dict[str, np.ndarray], optional

A dictionary of percentage changes to be applied to a subset of the model parameters. Values provided are multipled by the initial values, so that values greater than 1.00 represent precentage increases, and values less than 1.00 represent percentage decreases. The keys should be the names of the parameters to be changed, and the values should be numpy arrays of the same shape as the parameter.

Exactly one of final_values, final_delta, or final_delta_pct must be provided.

use_euler_approximation: bool, optional

Whether to use the Euler approximation to compute the final state of the economy. Defaults to True. If use_optimizer is also true, the Euler approximation will be used as the initial guess for the optimizer.

use_optimizer: bool, optional

Whether to use a numerical optimizer to compute the final state of the economy. Defaults to True. If use_euler_approximation is also true, the Euler approximation will be used as the initial guess for the optimizer.

optimizer_mode: str, optional

The type of optimizer to use. One of ‘root’ or ‘minimize’. Ignored if use_optimizer is False. Defaults to ‘root’.

n_iter_euler: int

The number of iterations to use when computing the Euler approximation. Defaults to 10,000. Ignored if use_euler_approximation is False.

compile_kwargs: dict, optional

Additional keyword arguments to pass to the compile method. See the docstring for compile for details.

optimizer_kwargs: dict, optional

Additional keyword arguments to pass to the optimizer. See the docstring for scipy.optimize.root or scipy.optimize.minimize for details.

save_results: bool, optional

If True, result object will be pickled and saved. Defaults to True.

output_path: str, optional

The path to save the result object. Defaults to ‘results’.

simulation_name: str, optional

The name of the simulation. Defaults to ‘{date}-{time}’. Used to name the saved result object.

verbose: bool, default True

If True, display status messages about the simulation.

Returns:
result: Result or InferenceData

A Result object containing the initial and final values of the model variables and parameters. If use_euler_approximation is True, an InferenceData object containing the Euler approximation will be returned instead.