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) 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. See Chapters 2 and 4 of Structural Macroeconometrics by DeJong and Dave for a deeper descriptions of log-linearization and Klein’s solution method.