Starting the Kalman Filter Recursion

Let the state-space system take the form (Hamilton (1994) page 377, but with notation changes): \[S_{t+1} = F S_{t} + \nu_{t+1}\] \[y_{t} = A^{\prime} x_{t} + H^{\prime} S_{t} + w_{t}\] where \(S\) is the state vector, \(y\) is an observed variable, and \(x_{t}\) is a vector of exogenous and predetermined variables.

One of the things you can do with the state-space system above is evaluate the likelihood function of a normal linear DSGE model at a guess of the unknown parameters. There exist convenient formulas for various objects of interest in a normal linear state-space system, including the likelihood function. One of the things you need in order to implement the Kalman filter is the starting value for the state vector, \(S_{1|0}\), and the variance matrix, \(P_{1|0}\). Unfortunately, popular references such as Herbst and Schoerfeide (2015) will omit critical details of how to compute those two quantities, leaving the implementation a mystery.

This is where Hamilton (1994, page 378) comes to the rescue. You can substitute the unconditional mean for the initial value of the state vector, \(S_{1|0}\). This will often be a vector of zeroes.

The more difficult question is the variance matrix \(P_{1|0}\). Letting \(\Sigma\) denote the unconditional covariance matrix for \(S\), Hamilton shows that \[\Sigma = F \Sigma F^{\prime} + Q\] where \(Q\) is the covariance matrix of \(\nu\), equal to \(E\left[\nu_{t+1} \nu_{t+1}^{\prime}\right]\). If you’re estimating the parameters of \(Q\) as part of the model, you can use the current guess of those parameters to compute \(Q\).

Hamilton provides the solution as \[vec\left(\Sigma\right) = vec\left(P_{1|0}\right) = \left[I_{r^{2}} - \left( F \otimes F \right)\right]^{-1} vec\left(Q\right)\] where \(vec\) is the vectorization operator stacking the columns of the matrix.

Steps:

  1. Take a guess of all parameters.
  2. Use the parameters to calculate \(F\) and \(Q\).
  3. Plug into the above equation to solve for \(vec\left(P_{1|0}\right)\).
  4. Unpack \(vec\left(P_{1|0}\right)\) into \(P_{1|0}\).

If you dig into the Dynare source code, you’ll see that they solve this using an algorithm for something called a discrete Lyapunov equation (Git link). I’m going to assume that is faster and/or has better properties with respect to numerical stability compared to a straightforward implementation of Hamilton’s solution. I will admit that I first heard of a Lyapunov equation while looking at the Dynare source code to see how they start the recursion.