MATLAB MEX Function Reference
Kalman Filter (kalcvf.m)

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

Description

KALCVF computes the one-step prediction {z}_{t+1| t} and the filtered estimate {z}_{t| t}, 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:

The function returns the following output:

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 \eta_t and {\epsilon}_t, respectively, and Gt is a covariance of \eta_t and {\epsilon}_t. A- stands for the generalized inverse of A. The filtered value and its covariance matrix are denoted {z}_{t| t} and {P}_{t| t}, respectively. For k>0, {z}_{t+k| t} and {P}_{t+k| t} 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:
\hat{\epsilon}_t & = & {y}_t - {b}_t - {H}_t {z}_{t| t-1} \
{D}_t & = & {H}_t ...
 ...
{P}_{t+1| t} & = & {F}_t {P}_{t| t-1}{F}^'_t + {V}_t -
 {K}_t {D}_t {K}^'_t
And for k-step forecasting for k>1,
{z}_{t+k| t} & = & {a}_{t+k-1} + {F}_{t+k-1} {z}_{t+k-1| t} \
{P}_{t+k| t} & = & {F}_{t+k-1} {P}_{t+k-1| t}
 {F}^'_{t+k-1} + {V}_{t+k-1}
When you use the alternative transition equation
{z}_t = {a}_t + {F}_t{z}_{t-1} + \eta_t
the forward recursion algorithm is written
\hat{\epsilon}_t & = & {y}_t - {b}_t - {H}_t {z}_{t| t-1} \
{D}_t & = & {H}_t ... 
...  & = & {F}_{t+1} {P}_{t| t-1}{F}^'_{t+1} + {V}_{t+1} - {K}_t {D}_t {K}^'_t
And for k-step forecasting (k>1),
{z}_{t+k| t} & = & {a}_{t+k} + {F}_{t+k}{z}_{t+k-1| t} \
{P}_{t+k| t} & = & {F}_{t+k} {P}_{t+k-1| t} {F}^'_{t+k} +
 {V}_{t+k}

Remarks

The initial state vector and its covariance matrix of the time invariant Kalman filters are computed under the stationarity condition
{z}_{1|} & = & ({I}- {F})^- {a}\
{P}_{1|} & = & ({I}- {F}\otimes {F})^- {vec}({V})
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 {z}_{1|} is set to a1 and its covariance matrix {P}_{1|} 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.

Return to main page