gEconpy.solvers.gensys.gensys#

gEconpy.solvers.gensys.gensys(g0, g1, c, psi, pi, div=None, tol=1e-08, return_all_matrices=True)#

Christopher Sim’s gensys.

Solves rational expectations equations by partitioning the system into stable and unstable roots, then eliminating the unstable roots via QZ decomposition, as described in [1].

System given as:

\begin{aligned} G_0 \cdot y_t &= G_1 \cdot y_{t-1} + c \\ &\quad + \psi \cdot z_t + \pi \cdot \eta_t \end{aligned}

with \(z_t\) an exogenous variable process and \(\eta_t\) being endogenously determined one-step-ahead expectational errors.

Returned system is:

\begin{aligned} y_t &= G_1 \cdot y_{t-1} + C + \text{impact} \cdot z_t \\ &\quad + ywt \cdot (I - fmat \cdot L^{-1})^{-1} \cdot fwt \cdot z_{t+1} \end{aligned}

If \(z_t\) is i.i.d., the last term drops out. If div is omitted from argument list, a \(div > 1\) is calculated.

Parameters:
g0np.ndarray

Coefficient matrix of the dynamic system corresponding to the time-t variables.

g1np.ndarray

Coefficient matrix of the dynamic system corresponding to the time t-1 variables.

cnp.ndarray

Vector of constant terms.

psinp.ndarray

Coefficient matrix of the dynamic system corresponding to the exogenous shock terms.

pinp.ndarray

Coefficient matrix of the dynamic system corresponding to the endogenously determined expectational errors.

divfloat, optional

Accepted for backward compatibility but ignored. The njit core uses the scipy “ouc” sort (strict unit circle, threshold 1.0). Sims’s dynamic shrink-toward-1 heuristic is only needed for eigenvalues in (1.0, 1.01] and is empirically absent from well-posed DSGE models.

tolfloat, optional

Level of floating point precision. Default 1e-8.

return_all_matricesbool, optional

Whether to return all matrices or just the policy function. Default True.

Returns:
G1np.ndarray

Policy function relating the current timestep to the next, transition matrix T in state space jargon.

Cnp.ndarray

Array of system means, intercept vector c in state space jargon.

impactnp.ndarray

Policy function component relating exogenous shocks observed at the t to variable values in t+1, selection matrix R in state space jargon.

fmatnp.ndarray

Matrix used in the transformation of the system to handle unstable roots.

fwtnp.ndarray

Weight matrix corresponding to fmat.

ywtnp.ndarray

Weight matrix corresponding to the stable part of the system.

gevnp.ndarray

Generalized left and right eigenvalues generated by qz(g0, g1), sorted such that stable roots are in the top-left corner.

eulist of int

Three-element list indicating existence and uniqueness of the solution, with the following meanings:

  • eu[0] = 1 for existence,

  • eu[1] = 1 for uniqueness.

  • eu[0] = -1 for existence only with not-s.c. z;

  • eu = [-2, -2] for coincident zeros.

loosenp.ndarray

Matrix characterising the sunspot-indeterminacy directions.

Notes

Adapted from http://sims.princeton.edu/yftp/gensys/mfiles/gensys.m. The core is numba-njit compiled and uses pytensor’s numba-compatible LAPACK wrappers.

References

[1]

Sims, Christopher A. “Solving linear rational expectations models.” Computational Economics 20.1-2 (2002): 1-20.