Kalman filter
Haroon Mumtaz
y t Ht Bt Az t e t
Coefficients
or data
Transition eq
Exogenous
regressors
Unobserved
state
t F t1 v t
The shocks
Assumptions
e t ~iid. N0, R
v t ~iid. N0, Q
Ee t , v t 0
Examples of econometric
models in state space form
A time-varying parameter model linking
import price inflation and the nominal
exchange rate
p t t D t E t e t
Import price
Time
Varying
coefficients
exchange rate
p t t Dt E t e t
t
Dt
t1
Dt1
v 1,t
v 2,t
GDP t T t C t
We assume that the trend component
follows a random walk T t c T t1 v 1,t
The cyclical component is a stationary
process C C v
t
t1
2,t
Trend-Cycle model
In SS form
H Matrix
data
Unobserved
states
GDP t
Tt
Ct
Tt
1 1
Ct
c
0
1 0
Tt1
Ct1
v 1,t
v 2,t
Trend-Cycle model
SS form with AR(2) cycle
Tt
GDP t
1 1 0
Ct
C t1
Tt
Ct
C t1
0
0
0 0
T t1
1 2 0
C t1
1 0
C t2
v 1t
v 2t
0
Idiosyncratic factor
In GDP growth
gdp i,t Bi F t e it
GDP growth in country i, i=1..4
Common factor
In GDP growth
SS form
data
Unobserved states
gdp 1,t
B1 0
gdp 2,t
B2 0
Ft
B3 0
F t1
gdp 3,t
gdp 4,t
Ft
F t1
e 1t
B4 0
f matrix
e 3t
e 4t
1 2
F t1
F t2
e 2t
v 1t
v 2t
Estimation Aims
Aim 1: Estimate parameters of the State
Space
y t Ht Bt Azt e t
t F t1 v t
e t ~iid. N0, R
v t ~iid. N0, Q
Estimation Aims
Aim 2: Recover the unobserved state
y t Ht Bt Az t e t
t F t1 v t
e t ~iid. N0, R
v t ~iid. N0, Q
Estimation
We use the Kalman filter for this purpose
The Kalman filter is a recursive algorithm
that provides an optimal estimate of t
conditional on an information set and
knowledge of the parameters of the state
space Ht , A, , F, R, Q
Notation
Model
yt x tt et
t F t1 v t
e t ~iid. N0, R
v t ~iid. N0, Q
t/t1
Notation
Estimate of t
up to time t
conditional on information
t/t
Covariance of t conditional on
information up to t-1
P t/t1
Notation
Covariance of t conditional on
information up to t-1
P t/t
Forecast of y given information up to time
t-1
y t/t1
Notation
Prediction error
t/t1 y t y t/t1
Variance of the prediction error
f t/t1
Kalman filter
Assume parameters , F, R, Q are known
The Kalman filter recursion consists of three
steps
1. Start with guess of state a time 0 0/0
and P 0/0
2. Prediction: At time 1 form an optimal
prediction y 1/0
using an estimated
value for 1/0
Kalman Filter
3. Updating: Use the observed value of y at
time 1 to calculate the prediction error
1/0 y 1 y 1/0
Predicted values
t/t1 F t1/t1
P t/t1 FP t1/t1 F Q
t/t1 y t y t/t1 y t x t t/t1
f t/t1 x t P t/t1 x t R
Forecast for y and the prediction error
E(v)=0
P t/t1 FP t1/t1 F Q
Second equation
Variance of transition eq
=0
P t1/t1
=Q
t/t1
y t y t/t1 y t x t t/t1
Forecast
error
f t/t1 x t P t/t1 x t R
E x t t t/t1 e t
=0
=R
Weight
assigned to new information
In the prediction error
Kalman gain
Relationship
Between Y3 andY2
covariance
Updated
Forecast based on Y2
old
Forecast based on Y1
variance
Error in forecasting
Y2 using information
Y1
K t P t/t1
Y3 t , Y 2 y t , Y1 x t
t/t t/t1 cov t , y t vary t y t y t/t1
P t/t1 K t x t P t/t1
P t/t1 x t x t P t/t1 x t
Lower weight
If R is high
Calculate prediction
error
Update states
0/0 , P 0/0
t/t1 F t1/t1
P t/t1 FP t1/t1 F Q
K t P t/t1 x t f 1
t/t1
t/t t/t1 K t t/t1
P t/t P t/t1 K t x t P t/t1
Kalman Smoother
The Kalman filter provides inference for
the state vector using information up to
time t t/t
We can get estimate of the state vector
using information up to the end of the
sample t/T using the Kalman smoother
t/T
P t/T
P t/t FP 1
t1/t
Kalman Smoother
t/T t/t P t/t F P 1
t1/t t1/T F t/t
t ct tt1 t
ct
t
ct1
t1
10
v1t
v2t
t
v1t
v2t
0
~N
0
0
0.6
,
0 0.006
0
0
0.001
2
0
-2
1970
1975
1980
1985
1990
1995
2000
2005
0.8
1.2
0.6
0.8
0.4
0.4
0.2
0.0
70
75
80
85
90
95
00
05
70
75
80
85
90
95
00
05
.6
1.2
.5
1.0
.4
0.8
0.6
.3
0.4
.2
0.2
70
75
80
85
90
95
00
05
70
75
80
85
90
95
00
05
Maximum Likelihood
Recall our Time-varying parameter model
yt x tt et
t F t1 v t
e t ~iid. N0, R
v t ~iid. N0, Q
Maximum Likelihood
The Likelihood function is given by
lnL 12 Tt1 ln2 n detx t P t/t1 x t R
1
2
or
lnL 12 Tt1 ln2 n detf t/t1
1
2
T
t/t1 f 1
t1
t/t1 t/t1
0/0 , P 0/0 , Q 0 , 0 , F 0 , R0
t/t1 F t1/t1
P t/t1 FP t1/t1 F Q
K t P t/t1 x t f 1
t/t1
Calculate likelihood
function for each t
1
2
1
f 1
2 t/t1 t/t1 t/t1
Tt1 t/t1 f 1
t/t1 t/t1
State variable
Observation equation