0% found this document useful (0 votes)
5 views6 pages

Kalman Filtere Algorithm

The document discusses the Kalman filter algorithm, focusing on state-space models and their application in estimating unobservable state variables using observable data. It outlines the necessary equations for measurement and transition, the recursive steps of the Kalman filter, and the calculation of Kalman gain. Additionally, it explains the process of running the Kalman smoother to obtain smoothed estimates from filtered estimates, emphasizing its utility in estimating missing data.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Kalman Filtere Algorithm

The document discusses the Kalman filter algorithm, focusing on state-space models and their application in estimating unobservable state variables using observable data. It outlines the necessary equations for measurement and transition, the recursive steps of the Kalman filter, and the calculation of Kalman gain. Additionally, it explains the process of running the Kalman smoother to obtain smoothed estimates from filtered estimates, emphasizing its utility in estimating missing data.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SECTION 3 | KALMAN FILTER

ALGORITHM - OPTIONAL (MPAFx)

UNIT 3.1 | STATE-SPACE MODELS AND THE QPM

Define Υt – the vector of observable variables, for which we have actual data, and Xt – the vector of
unobservable, state, variables that we want to estimate using the Kalman filter.

To run the Kalman filter, one needs to have a model in the state-space form. A state-space model
consists of two types of equations: measurement and transition.

Measurement, or observation, equations describe the static relationship between the observable
and the unobservable variables:

Yt = CXt + vt , (1)

where C is a matrix of (known) parameters, vt is a vector of measurement errors (if any), which are
independent identically distributed with zero mean and covariance matrix R, i.e. vt ~iid(0,R).

Transition, or state, equations describe the dynamics of state variables:

Xt = AXt−1 + εt, (2)

where A is a matrix of (known) parameters, εt is a vector of errors, which are independent and
identically distributed with zero mean and covariance matrix Q, i.e. εt ~iid(0,Q). Further assume that
errors vt and εt are independent of each other, i.e. Cov(νt,εt)=0.

Note that in the transition equation current states depend on the past states. However, recall that
our QPM is forward-looking, i.e. variables depend on their leads (or expectations), so the equations
take the form:

FEt [Xt+1] + GXt + HXt−1 + Mηt = 0, (3)

where F, G, H, M are matrices of (known) structural parameters, Et is the expectations operator,


ηt is the vector of structural shocks.
SECTION 3 | KALMAN FILTER
ALGORITHM - OPTIONAL (MPAFx)

UNIT 3.1 | STATE-SPACE MODELS AND THE QPM (Continued)

To bring this model to the state-space form, one needs to solve for rational expectations.
In particular, if the model (3) is well-behaved, it has a unique stable solution of the form:

Xt = AXt−1 + Pηt, (4)

where A and P are matrices of the coefficients that are functions of the structural parameters
F, G, H, M. Substituting (4) into (3), and taking expectations, one can see that these matrices must
satisfy the identity:

F [A(AXt−1 + Pηt) + P(Sηt)] + G[AXt−1 + Pηt] + HXt−1 + Mηt = 0 (5)

for any values of Xt−1 and ηt (where ηt+1 = Sηt + γt+1, γt~iid(0,W)), i.e. A and P are the solutions of
equations

FA2 + GA + H = 0, FAP + FPS + GP + M = 0, (6)

In (4), define εt Ξ Pηt to get the transition equation (2).1

UNIT 3.2 | KALMAN FILTER RECURSION

Once we have our model in the state-space form (1)-(2), we can use the Kalman filter.

Define Yt/t−1 and Xt/t−1 as the predicted values of Yt and Xt respectively, conditional on information
(observations) up to period t−1. Additionally, define Xt/t as the estimation of Xt conditional on
information (observations) up to period t.

The Kalman filter uses a recursive algorithm for each time period 1, 2, …,T. Each recursion consists
of two steps. Suppose we have the data observations and the state estimates for the period t−1, i.e.
we have Yt−1 and Xt−1/t−1. Then for the period t:

• Step 1. Prediction of state and measurement variables at time t, given the information up to
t−1. Since no new information arrived, the mean prediction is based on the state-space model
(1)-(2):

Xt/t−1 = AXt−1/t−1, (7)

Yt/t−1 = CXt/t−1. (8)


SECTION 3 | KALMAN FILTER
ALGORITHM - OPTIONAL (MPAFx)

UNIT 3.2 | KALMAN FILTER RECURSION (Continued)

• Step 2. Update the state estimate, given the data at period t. Once new observations at period
t arrive, there will be a discrepancy between the actual data, Yt , and the model prediction, Yt/t−1.
The Kalman filter uses this discrepancy to update the estimate of the unobserved states using
the matrix Kt called “Kalman gain”:

Xt/t = Xt/t−1 + Kt (Yt − Yt/t−1). (9)

UNIT 3.3 | KALMAN GAIN

Suppose the errors follow Normal distributions, i.e. vt ~N(0,R), εt ~N(0,Q).

For the first (prediction) step of the Kalman recursion, Pt/t−1 denotes the prediction error
variance of state variables, Xt, given the information (observations) up to period t−1,
i.e. Pt/t−1 = Vart−1 [(Xt − Xt/t−1)]. Similarly, Ft/t−1 is the prediction error variance of observed
variables, Yt , given the information (observations) up to period t−1, i.e.

Ft/t−1 = Vart−1 [(Yt − Yt/t−1)].

For the second (updating) step of the Kalman recursion, Pt/t denotes the error variance of state
variables, Xt, given the information (observations) up to period t, i.e. Pt/t = Vart [(Xt − Xt/t)].

Then the multivariate distribution for the vector (Yt, Xt) takes the form:

( )|
Yt
Xt
Yt,…,Yt−1~N (( ) (
Yt/t−1
Xt/t−1
,
Ft/t−1
Pt/t−1C ’
CPt/t−1
Pt/t−1 )) . (10)

From (10), the conditional distribution of Xt given Yt takes the form:

Xt|Yt,Y1,…,Yt−1~N (Xt/t−1 + Pt/t−1C’Ft/t−1−1[Yt − Yt/t−1], Pt/t−1 − Pt/t−1 C’Ft/t−1−1CPt/t−1). (11)

From (11), it directly follows:

Xt/t = Xt/t−1 + Pt/t−1 C’Ft/t−1−1 [Yt − Yt/t−1] = Xt/t−1 + Kt [Yt − Yt/t−1], (12)
SECTION 3 | KALMAN FILTER
ALGORITHM - OPTIONAL (MPAFx)

UNIT 3.3 | KALMAN GAIN (Continued)

Pt/t = Pt/t−1 − Pt/t−1 C’Ft/t−1−1CPt/t−1 = (I − KtC) Pt/t−1, (13)

where the Kalman gain is

Kt = Pt/t−1 C’Ft/t−1−1. (14)

Note that Ft/t−1 follows:

Ft/t−1 = Vart−1 [(Yt − Yt/t−1)] = Vart−1 [(CXt + vt − CXt/t−1)] = CPt/t−1 C’ + R

In turn, Pt/t−1 follows:

Pt/t−1 = Vart−1 [(Xt − Xt/t−1)] = Vart−1 [(AXt−1 + εt − AXt−1|t−1)] = APt−1|t−1 A’ + Q = A(I − Kt−1C)Pt−1|t−2 A’ + Q

Substituting Ft/t−1 and Pt/t−1 in (12)-(14), one gets the following equations for the Kalman filter
algorithm:

Kt = Pt/t−1C’(CPt/t−1 C’ + R)−1. (15)

Xt/t = Xt/t−1 + Kt [Yt − Yt/t−1], (16)

Pt+1|t = A(I − KtC)Pt/t−1 A’ + Q, (17)

Thus, Kalman gain in (15) depends positively on the state prediction error variance, Pt/t−1, and
negatively on the measurement equation variance R. This should be intuitively clear:

• if there are big mistakes in predicting states Xt/t−1 on the first step of the Kalman recursion
(Pt|t-1 is large), one puts more weight on the new data observations Yt, which means that Kalman
gain Kt is large;

0 in particular, that will be true for the transition equations that do not hold tightly,
i.e. Q is large;

• if the information is noisy (R is large), one puts less weight on the new information (Kt is small).
SECTION 3 | KALMAN FILTER
ALGORITHM - OPTIONAL (MPAFx)

UNIT 3.4 | KALMAN FILTER AND KALMAN SMOOTHER ALGORITHM

Having derived all the relevant expressions, we can combine them together to see how the Kalman
filter algorithm works.

Recall that the filter works as a recursion. Accordingly, in order to initialize it, we need to provide
starting values for all the states at the beginning of the sample, X0|0, as well as for the variance of
state prediction errors, P0|0. For small data samples, these starting values might significantly affect
the results of filtration. If one doesn’t have any other prior information, one option would be to
assume that the starting values for the states and for their prediction error variance are not far from
their steady states. In particular, for stationary models we can set the starting values equal to the
steady state values.

Once we have defined the starting values, Kalman filter runs the recursive algorithm for each time
period 1, 2, …, T. Each recursion consists of two steps.

• Step 1. Prediction using the state-space model:

Xt/t−1 = AXt−1/t−1, (7)

Yt/t−1 = CXt/t−1,. (8)

• Step 2. Update using the data:

Kt = Pt/t−1C’(CPt/t−1 C’ + R)−1, (15)

Xt/t = Xt/t−1 + Kt [Yt − Yt/t−1], (16)

Pt+1/t = A(I−Kt C)Pt/t−1 A’ + Q. (17)

The Kalman filter provides optimal linear mean squared error estimator of the states given
the information up to period t. If the errors are normally distributed, it is optimal across all the
estimators of Xt conditional on information up to that period.
SECTION 3 | KALMAN FILTER
ALGORITHM - OPTIONAL (MPAFx)

UNIT 3.4 | KALMAN FILTER AND KALMAN SMOOTHER ALGORITHM


(Continued)

For each period t, the Kalman filter uses only information up to that period to estimate Xt. These
estimates can be found in Xt/t−1 (from the prediction step) and in Xt/t (from the update step).
However, in order to estimate Xt, it is often desirable to use all the available data – up to the last
period T. That is, it might be desirable to obtain estimates Xt/T, which are called smoothed estimates
of the states. That’s what the Kalman smoother does.

To run the Kalman smoother, one needs first to run the Kalman filter and obtain all estimates of the
states: X1/1, X2/2, …, XT/T.

Then the Kalman smoother algorithm works recursively backwards, from T-1, T-2, …, 1. For each
period t+1 we observe the difference between the smoothed and the filtered estimates of the
states: Xt+1/T −Xt+1/t. The Kalman smoother uses this difference to update the filtered estimates of the
states at period t, in order to obtain the estimates for the smoothed states:

Xt/T = Xt/t + Jt [Xt+1/T − Xt+1/t]. (18)

In practice, apart from decomposing variables into trend and gap components – which is the focus
of this course – the Kalman filter is also used to estimate missing data. For example, in the dataset
used in this module, GDP growth is not available for the last quarter, 2014Q1. However, we can
run filtration on the sample including 2014Q1, and the model will estimate a value for GDP (level,
trend, and gap) for 2014Q1, that is it will produce a forecast, given the structure of the model and
its parameterization.

Footnotes:
1. If εt is autocorrelated, add it as another state variable, while the iid shocks hitting εt
will be the new shocks in the transition equation.

You might also like