Financial Econometrics:
Latent Variables - The Kalman Filter
Subhajit Basu
November 2023
Subhajit Basu Latent Variables 1 / 22
Unobserved But Still There
Sometimes in macroeconomics, we come across variables that play important
roles in theoretical models but which we cannot observe.
Examples include the concept of potential output. For example, in many
Keynesian models, inflationary pressures are determined by how far actual
output is from this time-varying potential output series.
In reality, we do not observe potential output so is this concept even worth
bothering with? Well, just because a variable isn’t observable, that doesn’t
mean we can’t make a guess as to how it is behaving.
For example, if our data move in a way that would be consistent with a large
increase in potential output (perhaps GDP rises a lot but there are no signs of
inflationary pressures) then perhaps we should assume that is has indeed
increased.
In these notes, we will discuss methods for dealing with unobserved (or latent)
variables in time series, building towards a method known as the Kalman
filter. We will see the Kalman filter again when we discuss estimation of
DSGE models.
Latent Variables 2 / 22
Extracting a Signal
Going back to our earlier point, suppose we see a big increase in output in the
latest quarterly data that is not accompanied by a burst of inflation?
Does this mean we should assume there has been a big change in potential
output?
Probably not. Potential output probably doesn’t move around a lot from
quarter to quarter and it is likely that there is a lot of fairly random noise in
the quarterly fluctuations in inflation.
But there is also probably a useful signal in the data as well.
So we are dealing with a type of signal extraction problem: What’s the best
way to extract a useful signal from information that also contains useless
noise?
We discuss these ideas in the next few slides, developing the tools that are
used for the Kalman filter.
Latent Variables 3 / 22
Conditional Expectations
Suppose we are interested in getting an estimate of the value of a variable X .
We don’t observe X but instead we observe a variable Z that we know to be
correlated with X .
Specifically, let’s assume that X and Z are jointly normally distributed so that
X µX σ2X σ XZ
∼N ,
Z µZ σ XZ σ2Z
In this case, the expected value of X conditional on observing Z is
σ XZ
E (X |Z ) = µ X + 2 (Z −µ Z)
σZ
Alternatively, if ρ is the correlation between X and Z (ρ = σ XZ )
σX σZ
then we can
write σX
E (X |Z ) = µ X + ρ (Z −µ Z )
σZ
The amount of weight you put on the information in Z when formulating an
expectation for X depends on how correlated Z is with X and on their relative
standard deviation. If Z has a high standard deviation (so it’s a poor signal)
then you don’t place much weight on it.
Latent Variables 4 / 22
Multivariate Conditional Expectations
In the previous example, we considered only two variables. What about the
case in which X is a 1 × n vector of variables and Z is a 1 × m vector? There
is a straightforward generalisation of the formula just presented.
Denote the covariance matrix of the variables in X as Σ XX , the covariance
matrix of the variables in Z as Σ Z Z and the matrix of covariances between the
entries in X and Z as Σ X Z .
If all the variables are jointly normally distributed then this can be written as
X µX Σ XX Σ XZ
∼N ,
Z µZ Σ′XZ ΣZZ
In this case, the expected value of X conditional on observing Z is
E (X |Z ) = µ X + Σ XZ Σ −1
ZZ
(Z −µ Z)
This formula will play an important role in our explanation of the Kalman
filter.
Latent Variables 5 / 22
State-Space Models
State-space models are a general class of linear time series models that mix
together observable and unobservable variables. These models can be
described using two equations.
The first, known as the state or transition equation, describes how a set of
unobservable state variables, St , evolve over time as follows:
St = FSt −1 + ut
The term ut can include either normally-distributed errors or perhaps zeros if
the equation being described is an identity. We will write this as
ut ∼ N (0, Σ u ) though Σ u may not have a full matrix rank.
The second equation in a state-space model, which is known as the
measurement equation, relates a set of observable variables, Z t , to the
unobservable state variables
Zt = HSt + vt
Again, the term wt can include either normally-distributed errors or perhaps
zeros if the equation being described is an identity. We will write this as
vt ∼ N (0, Σ v ) though Σ v may not have a full matrix rank.
Latent Variables 6 / 22
Estimation of State-Space Models: Intuition
Before working through the details of the methods used to estimate
state-space models via maximum likelihood, let’s build-up some intuition first.
The observed data are described by
Zt = HSt + vt
where vt contains some normally-distributed errors.
We can’t observe St but suppose we could replace it by an observable
unbiased guess based on information available up to time t −1. Call this
guess St|t−1 and suppose its errors are normally distributed with a known
covariance matrix.
St −S t|t−1 ∼ N 0, Σ t|t−1
S
Then the observed variables could be written as
Zt = HSt |t − 1 + vt + H St −St |t −1
Because St|t−1 is observable and the unobservable elements (vt and
St −St|t−1) are normally distributed, this model can be estimated via
maximum-likelihood methods.
Latent Variables 7 / 22
Log Likelihood of Observables
The observable data can be written as
Zt = HSt |t − 1 + vt + H St −St |t −1
Then the variance of error term after conditioning on period t −1’s estimate
of the state variables is given by
vt + H St −St |t −1 ∼ N (0, Ωt )
where
Ωt = Σ v + HΣ tS|t −1 H′
Let θrepresent the parameters of the model, i.e. θ= (F , H, Σ v , Σ u ). We will
show later that Σ St|t−1 depends on these parameters.
The log-likelihood function for Z t given the observables at time t −1 is
1 ′
log f (Z t |Z t −1, θ) = −log 2π −log |Ω |−
t Zt −HS t |t − 1 Ωt−1 Zt −HS t |t −1
2
Latent Variables 8 / 22
Maximum Likelihood Estimation
Given the initial estimates of the first-period unobservable state S1|0, the
combined likelihood for all the observed data is the product of all the
period-by-period likelihoods
iY
=T
f Z1 , Z2 , ...., ZT |S , θ = f Z1|S1|0 , θ f (Zi |Zi −1 , θ)
1|0 i =2
So the combined log-likelihood function for the observed dataset is given by
ΣT
log f Z1 , Z2 , ...., ZT |S1|0 , θ = −T log 2π − log |Ω i |
i =1
1Σ
T
′
− Zi −HS i |i −1 Ω−1
i
Zi −HS i |i −1
2 i =1
The maximum-likelihood parameter estimates are the set of matrices
θ= (F , H, Σ v , Σ u ) that provide the largest value for this function.
Latent Variables 9 / 22
Estimating the State Variables
We have described how to estimate the model’s parameters via MLE provided
we have an unbiased guess based on information available up to time t −1,
which we called St|t−1, with normally distributed errors.
Here we describe a method for generating these unbiased guesses known as
the Kalman filter. It is an iterative method. Starting from one period’s
estimates of the state variables, it uses the observable data for the next period
to update these estimates.
Let’s start with formulating an estimate of the state variable at time t given
information at time t −1. This is easy enough
St = FSt −1 + ut ⇒ St |t −1 = FSt −1|t − 1
This means that in period t −1, the expected value for the observables in
period t are
Z t|t−1 = HSt|t−1 = HFSt−1|t−1
Then in period t, when we observe Z t the question is how do we update our
guesses for the state variable in light of the “news” in Z t −HFSt−1|t−1?
Latent Variables 10 / 22
Conditional Expectation: The Kalman Filter
The assumptions of the model imply that
′ ! !
St FSt−1|t−1 Σ St|t −1 HΣ St|t −1
∼N ,
Zt HFSt −1|t − 1 HΣ St |t −1 Σ v + HΣ St |t −1 H′
Now we can use our earlier result about conditional expectations to state that
the minimum variance unbiased estimate of St given the observed Z t is
E (St |Zt ) = St|t = FSt−1|t−1 + K t Z t −HFSt−1|t−1
where ′ −1
S v S H ′
Kt = H Σ Σ +
t |t −1 t |t −1
HΣ
The covariance matrices required to compute this K t matrix (known as the
Kalman gain matrix) are updated by the formulae:
'
Σ St|t −1 = FΣ tS−1|t − 1 F + Σ u
Σ St|t = (I −K t H) Σ St|t −1
Latent Variables 11 / 22
Initialising the Kalman Filter
We still need an initial estimate S1|0 as well as its covariance matrix to start
the filter process.
In many macroeconomic models, the state variable can be assumed to have a
zero mean without losing any generality, so that can work as a first guess for
the state.
We can estimate the unconditional variance by estimating what the variance
of an estimate of the state variable would be from a large sample of data.
Recall that
'
Σ St|t −1 = FΣ St −1|t − 1 F + Σ u
The values of the covariance matrix genrated by this equation will generally
converge, so for our unconditional covariance matrix we can use a value of Σ
that solves
'
Σ = FΣ F + Σ u
Latent Variables 12 / 22
The Kalman Smoother
The Kalman filter is what is known as a one-sided filter: The estimates of
states at time t are based solely on information available at time t. No data
after period t is used to calculate estimates of the unobserved state variables.
This is a reasonable model for how someone might behave if they were
learning about the state variables in real time. But researchers have access to
the full history of the data set, including all the observations after time t.
For this reason, economists generally estimate time-varying models using a
method known as the Kalman smoother. This is a two-sided filter that uses
data both before and after time t to compute expected values of the state
variables at time t.
I don’t want to overload the technique here so I won’t go into how this is
done: Basically, you do the Kalman filter first and then work backwards from
the final estimates further exploiting joint distribution properties.
Latent Variables 13 / 22
Example: The Hodrick-Prescott Filter
Previously, we discussed the HP filter as a way of choosing a trend for series
that had a time-varying trend Yt∗ picked to minimize
ΣN h i
(Yt −Y t∗) 2 + λ ∆ Y t∗−∆ Y t∗−1
t=1
This seems fairly ad hoc but it can be viewed as an example of the Kalman
filter. Consider the following state-space model
Yt = Yt∗ + Ct
∆ Yt∗ = ∗ + ϵg
∆ Yt−1 t
Ct = ϵtc
where Var (ϵg ) = σ 2 and Var (ϵc ) = σ 2
t g t c
It can be shown that for large samples the HP filter technique is the same as
σc2
Kalman filter estimation of this model when we set λ = σ2 . Hodrick and
g
Prescott assumed Ct had a standard deviation of 5 percentage points while ϵgt
had a standard deviation of one-eighth of a percentage point. Hence they
52
chose λ = 1 2 = (25)(64) = 1600.
( 8)
Latent Variables 14 / 22
Example: Laubach and Williams (2001)
This paper uses the Kalman filter to estimate a model featuring two
unobservable time-varying series: Potential output and the natural rate of
interest.
The model has seven equations
ỹt = yt −yt∗
∗
y˜t = Ay (L) ỹt−1 + Ar (L) r t−1 —rt−1 + ϵ1t
πt = Bπ (L) πt −1 + By (L) ỹt −1 + +Bx (L) xt + ϵ2t
rt∗ = cgt + zt
zt = Dz (L) zt −1 + ϵ3t
∗
yt∗ = yt−1 + gt−1 + ϵ4t
gt = gt −1 + ϵ5t
where yt is log of real GDP, yt∗ is the log of potential output, y˜tis the output
gap, r t is the real Federal funds rate, rt∗ is the “natural” real rate of interest,
π t is inflation, xt is a set of additional variables that determine inflation and
gt is the growth rate of potential output.
Latent Variables 15 / 22
Laubach and Williams Results
In addition to the results in the original paper, updated estimates are available
on the San Francisco Fed website.
The next page shows the original paper’s estimates of the natural real rate of
interest (i.e. the real interest rate that stabilises the economy) with the green
area showing standard errors,
The following page shows the updated estimates of the natural rate using the
two-sided Kalman smoother. While the original paper had shown the natural
rate as a stationary series, the latest estimates show a steady downward trend
so that the current “natural real rate” is negative.
The model also sees a steady decline in the growth rate of potential output. It
assigns much of the weak growth of recent years to structural factors (output
gap in recent recession is quite small).
Final pictures show differences between two-sided and one-sided estimates of
natural rate of interest and potential output growth. You can see why they
call it the Kalman smoother.
RATS code for estimating the Laubach-Williams model is linked to on the
website.
Latent Variables 16 / 22
Actual Versus Natural Real Interest Rates
Latent Variables 17 / 22
Laubach-Williams Estimates of Natural Rate of Interest
Latent Variables 18 / 22
Laubach-Williams Estimates of Potential Output Growth
Latent Variables 19 / 22
Laubach-Williams Estimates of Output Gap
Latent Variables 20 / 22
One-Sided and Two-Sided Estimates of Natural Rate of
Interest
Latent Variables 21 / 22
One-Sided and Two-Sided Estimates of Potential Output
Growth
Latent Variables 22 / 22