Kalman Gain

Hi, guy:

I am a novice in using Bayesian or MLE to estimate DSGE models. There is a very practical question: when using Kalman filter to compute the log likelihood, is it better to keep the Kalman gain fixed or keep updating with new observations when doing estimation. I wrote the code myself, but the computed likelihood is really small, i.e, a huge functional value when using csminwel to find the minimizer. I attached my code to use Kalman filter computing the log likelihood here. Any suggestion or comments is highly appreciated. The code is written following Ferandez-Villaverde et al (2007 AER, the ABCD paper). My Q,U, W,Z are corresponding to their A, B, C and D.
kalman_quwz.m (1.89 KB)

Given that the Kalman-Filter in its formulation with the gain matrix being updated each period is optimal for the class of problems considered (linear and normal error terms), there is no reason for not updating it. Not doing so would omit valuable information for the state prediction.

Dear jpfeifer:

Thank you for the clarification. My thought is the same, but I am not sure. In the version of code I attached, I have the check of semi-positive definiteness, i.e, I check if eiven eigenvalue of the forecast error variance matrix is a positive real number or not. If not, I reset the value of the matrix to be an identity matrix. If I remove this check, the Kalman filter code can give me log-likelihood function at a similar magnitude as Dynare gives after dozens of iteration. I don’t know if this move is legitimate, since a new problem pops out: the search algorithm occasionally give me complex parameter values or NaN etc. I don’t know how to control this issue.

Thanks for your help again.


Having a non-positive definite forecast error variance may be a numerical problem or might indicate a problem with your code. We sometimes encountered the same problem if the matrix is badly conditioned. However, in this case, we do not reset the matrix but discard the draw because the results will be wrong in any case. Hence, we added check

if det(sigma)<0 loglik=Inf; return end
to the Kalman-Filter before the matrix is inverted.