# How `linearsolve` Works

The equilibrium conditions for most DSGE models can be expressed as a vector function $F$:

\begin{align}
f(E_t X_{t+1}, X_t, \epsilon_{t+1}) = 0,
\end{align}

where 0 is an $n\times 1$ vector of zeros, $X_t$ is an $n\times 1$ vector of endogenous variables, and $\epsilon_{t+1}$ is an $m\times 1$ vector of exogenous structural shocks to the model. $E_tX_{t+1}$ denotes the expecation of the $t+1$ endogenous variables based on the information available to decision makers in the model as of time period $t$. 

The function $f$ is often nonlinear. Because the values of the endogenous variables in period $t$ depend on the expected future values of those variables, it is not in general possible to compute the equilibirum of the model by working directly with the function $f$. Instead it is often convenient to work with a log-linear approximation to the equilibrium conditions around a non-stochastic steady state. In many cases, the log-linear approximation can be written in the following form:

\begin{align}
A E_t\left[ x_{t+1} \right] & = B x_t + \left[ \begin{array}{c} \epsilon_{t+1} \\ 0 \end{array} \right],
\end{align}

where the vector $x_{t}$ denotes the log deviation of the variables in $X_t$ from their steady state values. Given the function $f$, `linearsolve` computes matrices $A$ and $B$ numerically as:

\begin{align}
A & = \left[ \frac{\partial \log f_1 }{\partial \log X_{t+1} } \left(\bar{X} \right) - \frac{\partial \log f_2 }{\partial \log X_{t+1} } \left(\bar{X} \right) \right]
\end{align}

and:

\begin{align}
B & = -\left[ \frac{\partial \log f_1 }{\partial \log X_{t+1} } \left(\bar{X} \right) - \frac{\partial \log f_2 }{\partial \log X_{t} } \left(\bar{X} \right) \right]
\end{align}

The variables in $x_t$ are grouped in a specific way: $x_t = [s_t; u_t]$ where $s_t$ is an $n_s \times 1$ vector of predetermined (state) variables and $u_t$ is an $n_u \times 1$ vector of nonpredetermined (forward-looking) variables. $\epsilon_{t+1}$ is an $n_s\times 1$ vector of i.i.d. shocks to the state variables $s_{t+1}$.  $\epsilon_{t+1}$ has mean 0 and diagonal covariance matrix $\Sigma$. The solution to the model is a pair of matrices $F$ and $P$ such that:

\begin{align}
u_t  &  = Fs_t\\
s_{t+1} & = Ps_t + \epsilon_{t+1}.
\end{align}

`linearsolve` computes the matrices $F$ and $P$ are using the [Klein (2000)](http://www.sciencedirect.com/science/article/pii/S0165188999000457) solution method which is based on the generalized Schur factorization of the marices $A$ and $B$. The solution routine incorporates many aspects of his Klein's Matlab program [solab.m](http://paulklein.ca/newsite/codes/codes.php). See Chapters 2 and 4 of [Structural Macroeconometrics](https://press.princeton.edu/titles/9622.html) by DeJong and Dave for a deeper descriptions of log-linearization and Klein's solution method.

00814234b86f261295ba305051eb590f6254a3bd
ipynb
Jupyter Notebook
docs/source/how_linear_solve_works.ipynb
letsgoexploring/linearsolve-original
e8cfdabab98976d413b43756fb363d04644fea4d
MIT
2020-01-11T01:07:32.000Z
2021-08-17T12:50:33.000Z
docs/source/how_linear_solve_works.ipynb
letsgoexploring/linearsolve-original
e8cfdabab98976d413b43756fb363d04644fea4d
MIT
2019-07-15T13:42:45.000Z
2019-07-15T16:37:21.000Z
docs/source/how_linear_solve_works.ipynb
letsgoexploring/linearsolve-original
e8cfdabab98976d413b43756fb363d04644fea4d
MIT
2019-09-28T21:04:49.000Z
2022-03-05T20:59:31.000Z
Qwen/Qwen-72B
1. YES
2. YES

