MATLAB MEX Function Reference |

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
*N*×_{y}*T*matrix containing data (*y*_{1}, ... ,*y*_{T})'. `lead`

- is the number of steps to forecast after the end of the data.
`a`

- is an
*N*×1 vector for a time-invariant input vector in the transition equation,_{z}

or an*N*×(_{z}*T*+lead) vector containing input vectors in the transition equation. `F`

- is an
*N*×_{z}*N*matrix for a time-invariant transition matrix in the transition equation,_{z}

or an*N*×_{z}*N*×(_{z}*T*+lead) matrix containing transition matrices in the transition equation. `b`

- is an
*N*×1 vector for a time-invariant input vector in the measurement equation,_{y}

or an*N*×(_{y}*T*+lead) vector containing input vectors in the measurement equation. `H`

- is an
*N*×_{y}*N*matrix for a time-invariant measurement matrix in the measurement equation,_{z}

or an*N*×_{y}*N*×(_{z}*T*+lead) matrix containing measurement matrices in the measurement equation. `var`

- is an (
*N*+_{y}*N*)×(_{z}*N*+_{y}*N*) matrix for a time-invariant variance matrix for_{z}

the error in the transition equation and the error in the measurement equation,

or an (*N*+_{y}*N*)×(_{z}*N*+_{y}*N*)×(_{z}*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
*N*×1 initial state vector ._{z} `vz0`

- is an optional
*N*×_{z}*N*covariance matrix of an initial state vector ._{z}

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:
is the mean square error matrix of the prediction error , such that .**C**_{t} `pred`

- is an optional
*N*×(_{z}*T*+lead) matrix containing one-step predicted state vectors . `vpred`

- is an optional
*N*×_{z}*N*×(_{z}*T*+lead) matrix containing mean square errors of predicted state vectors . `filt`

- is an optional
*N*×_{z}*T*matrix containing filtered state vectors . `vfilt`

- is an optional
*N*×_{z}*N*×_{z}*T*matrix containing mean square errors of filtered state vectors .

**Algorithm**

**Remarks**

**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.