Friday, June 20, 2008

Overview Kalman Filter Functions

MATLAB MEX Function Reference
Kalman Filter (kalcvf.dll)

The Kalman filter provides a tool for dealing with state space models to analyse economic and financial time series of not only correlated its past values but also contemporaneously correlated each other and each other's past values. You can develop a model of the univariate or multivariate time series and the relationships between the vector time series.

Syntax


logl = kalcvf(data, lead, a, F, b, H, var)
logl = kalcvf(data, lead, a, F, b, H, var, z0, vz0)
[logl, pred, vpred] = kalcvf(data, lead, a, F, b, H, var)
[logl, pred, vpred] = kalcvf(data, lead, a, F, b, H, var, z0, vz0)
[logl, pred, vpred, filt, vfilt] = kalcvf(data, lead, a, F, b, H, var)
[logl, pred, vpred, filt, vfilt] = kalcvf(data, lead, a, F, b, H, var, z0, vz0)

Description


KALCVF computes the one-step prediction and the filtered estimate , as well as their covariance matrices.
The function uses forward recursions, and you can also use it to obtain k-step estimates.

The inputs to the KALCVF function are as follows:

data
is a Ny×T matrix containing data ( y1, ... , yT)'.
lead
is the number of steps to forecast after the end of the data.
a
is an Nz×1 vector for a time-invariant input vector in the transition equation,
or an Nz×(T+lead) vector containing input vectors in the transition equation.
F
is an Nz×Nz matrix for a time-invariant transition matrix in the transition equation,
or an Nz×Nz×(T+lead) matrix containing transition matrices in the transition equation.
b
is an Ny×1 vector for a time-invariant input vector in the measurement equation,
or an Ny×(T+lead) vector containing input vectors in the measurement equation.
H
is an Ny×Nz matrix for a time-invariant measurement matrix in the measurement equation,
or an Ny×Nz×(T+lead) matrix containing measurement matrices in the measurement equation.
var
is an (Ny+Nz)×(Ny+Nz) matrix for a time-invariant variance matrix for
the error in the transition equation and the error in the measurement equation,
or an (Ny+Nz)×(Ny+Nz)×(T+lead) matrix containing variance matrices for
the error in the transition equation and the error in the measurement equation, that is, .
z0
is an optional Nz×1 initial state vector .
vz0
is an optional Nz×Nz covariance matrix of an initial state vector .
The function returns the following output:

logl
is a value of the average log likelihood function of the SSM when the observation noise is normally distributed:

where Ct is the mean square error matrix of the prediction error , such that .
pred
is an optional Nz×(T+lead) matrix containing one-step predicted state vectors .
vpred
is an optional Nz×Nz×(T+lead) matrix containing mean square errors of predicted state vectors .
filt
is an optional Nz×T matrix containing filtered state vectors .
vfilt
is an optional Nz×Nz×T matrix containing mean square errors of filtered state vectors .
Algorithm

The KALCVF function computes the conditional expectation of the state vector zt given the observations, assuming that the mean and the variance of the initial state vector are known. The filtered value is the conditional expectation of the state vector zt given the observations up to time t. For k-step forecasting where k>0, the conditional expectation at time t+k is computed given observations up to t. For notation, Vt and Rt are variances of and , respectively, and Gt is a covariance of and . A- stands for the generalized inverse of A. The filtered value and its covariance matrix are denoted and , respectively. For k>0, and stand for the k-step forecast of zt+k and its mean square error. The Kalman filtering algorithm for one-step prediction and filtering is given as follows:

And for k-step forecasting for k>1,

When you use the alternative transition equation

the forward recursion algorithm is written

And for k-step forecasting (k>1),

Remarks

The initial state vector and its covariance matrix of the time invariant Kalman filters are computed under the stationarity condition

where F and V are the time invariant transition matrix and the covariance matrix of transition equation noise, and vec( V) is an Nz2 ×1 column vector that is constructed by the stacking Nz columns of matrix V. Note that all eigenvalues of the matrix F are inside the unit circle when the SSM is stationary. When the preceding formula cannot be applied, the initial state vector estimate is set to a1 and its covariance matrix is given by 106I. Optionally, you can specify initial values.
See also

KALCVS performs fixed-interval smoothing

Getting Started with State Space Models

Kalman Filtering Example 1: Likelihood Function Evaluation

Kalman Filtering Example 2: Estimating an SSM Using the EM Algorithm

References

[1] Harvey, A.C., Forecasting, Structural Time Series Models and the Kalman Filter, Cambridge: Cambridge University Press, 1991.

[2] Anderson, B.D.O., and J.B. Moore, Optimal Filtering, Englewood Cliffs, NJ: Prentice-Hall, 1979.

[3] Hamilton, J.D., Time Series Analysis, Princeton, 1994.