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.
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:
- g0
np.ndarray Coefficient matrix of the dynamic system corresponding to the time-t variables.
- g1
np.ndarray Coefficient matrix of the dynamic system corresponding to the time t-1 variables.
- c
np.ndarray Vector of constant terms.
- psi
np.ndarray Coefficient matrix of the dynamic system corresponding to the exogenous shock terms.
- pi
np.ndarray Coefficient matrix of the dynamic system corresponding to the endogenously determined expectational errors.
- div
float Threshold value for determining stable and unstable roots.
- tol
float, default: 1e-8 Level of floating point precision.
- return_all_matrices: bool, default True
Whether to return all matrices or just the policy function.
- g0
- Returns:
- G1
np.ndarray Policy function relating the current timestep to the next, transition matrix T in state space jargon.
- C
np.ndarray Array of system means, intercept vector c in state space jargon.
- impact
np.ndarray Policy function component relating exogenous shocks observed at the t to variable values in t+1, selection matrix R in state space jargon.
- fmat
np.ndarray Matrix used in the transformation of the system to handle unstable roots.
- fwt
np.ndarray Weight matrix corresponding to fmat.
- ywt
np.ndarray Weight matrix corresponding to the stable part of the system.
- gev
np.ndarray Generalized left and right eigenvalues generated by qz(g0, g1), sorted such that stable roots are in the top-left corner.
- eu
tuple Tuple of two values 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.
- loose
int Number of loose endogenous variables.
- G1
Notes
Adapted from http://sims.princeton.edu/yftp/gensys/mfiles/gensys.m
References
[1]Sims, Christopher A. “Solving linear rational expectations models.” Computational Economics 20.1-2 (2002): 1.