Nonlinear simulations#

The main functionality of nonlinear simulations is provided by the function econpizza.PizzaModel.find_path() The main arguments are either shock or init_state, which allows to specify an economic shock as a tuple of the shock name (as specified in shocks in the YAML) and the size of the shock, or a vector of initial states, respectively. The function econpizza.PizzaModel.get_distributions() allows to retrieve the full nonlinear sequence of the distribution.

Note

All numerical methods are subject to numerical errors. To reduce these, you can decrease the numerical tolerance tol. However, this should not be below the tolerance level used for the steady state search.

Hint

A sufficient condition for convergence of the solution routine is that the generalized eigenvalues of the sequence space Jacobian and its steady-state pendant are all positive. [1] If the procedure does not converge, the use_solid_solver=True flag can be used to check if the model solves when using a conventional Newton method with the true Jacobian (this may take quite a while).

econpizza.PizzaModel.find_path(self, shock=None, init_state=None, init_dist=None, pars=None, horizon=200, use_solid_solver=False, skip_jacobian=False, verbose=True, raise_errors=True, **newton_args)#

Find the expected trajectory given an initial state.

Parameters:
  • shock (tuple, optional) – shock in period 0 as in (shock_name_as_str, shock_size)

  • init_state (array, optional) – initial state, defaults to the steady state values

  • init_dist (array, optional) – initial distribution, defaults to the steady state distribution

  • pars (dict, optional) – alternative parameters. Warning: do only change those parameters that are invariant to the steady state.

  • horizon (int, optional) – number of periods until the system is assumed to be back in the steady state. Defaults to 200

  • use_solid_solver (bool, optional) – calculate the full jacobian and use a standard Newton method. Defaults to False

  • skip_jacobian (bool, optional) – whether to skip the calculation of the steady state sequence space Jacobian. If True, the last cached Jacobian will be used. Defaults to False

  • verbose (bool, optional) – degree of verbosity. 0/False is silent. Defaults to False

  • raise_errors (bool, optional) – whether to raise errors as exceptions, or just inform about them. Defaults to True

  • newton_args (optional) – any additional arguments to be passed on to the Newton solver (see the documentations of the solvers)

Returns:

  • x (array) – array of the trajectory

  • flag (bool) – Error flag. Returns False if the solver was successful, otherwise returns True

If the model has heterogeneous agents, the routine will automatically compute the steady state sequence space Jacobian. This can be skipped using the skip_jacobian flag.

Any additional argument will be passed on to the specific Newton method. For models with heterogeneous agents this is econpizza.utilities.newton.newton_for_jvp():

econpizza.utilities.newton.newton_for_jvp(jvp_func, jacobian, x_init, verbose, tol=1e-08, maxit=20, nsteps=30, factor=1.5)#

Newton solver for heterogeneous agents models as described in the paper.

Parameters:
  • tol (float, optional) – tolerance of the Newton method, defaults to 1e-8

  • maxit (int, optional) – maximum of iterations for the Newton method, defaults to 20

  • nsteps (int, optional) – number of function evaluations per Newton iteration, defaults to 30

  • factor (float, optional) – dampening factor (gamma in the paper), Defaults to 1.5

For models with representative agents, the Newton method is econpizza.utilities.newton.newton_for_banded_jac():

econpizza.utilities.newton.newton_for_banded_jac(jav_func, nvars, horizon, X, shocks, verbose, maxit=30, tol=1e-08)#

Newton solver for representative agents models.

Parameters:
  • tol (float, optional) – tolerance of the Newton method, defaults to 1e-8

  • maxit (int, optional) – maximum of iterations for the Newton method, defaults to 20

If use_solid_solver is set to True, the Newton method newton_jax_jit from the grgrjax package is used.

The function econpizza.PizzaModel.get_distributions() allows to retrieve the sequence of distributions and decision variables. To that end it requires the shocks and initial distribution together with the trajectory of aggregated variables as input.

econpizza.PizzaModel.get_distributions(self, trajectory, init_dist=None, shock=None, pars=None)#

Get all disaggregated variables for a given trajectory of aggregate variables.

Note that the output objects do, other than the result from find_path with stacking, not include the time-T objects and that the given distribution is as from the beginning of each period.

Parameters:
  • trajectory (array) – a _full_ trajectory of aggregate variables

  • init_dist (array, optional) – the initial distribution. Defaults to the steady state distribution

  • shock (array, optional) – shock in period 0 as in (shock_name_as_str, shock_size). Defaults to no shock

Returns:

rdict – a dictionary of the distributions

Return type:

dict

Footnotes