3.8. ANÁLISIS E INTERPRETACIÓN DE RESULTADOS
3.8.3. Observación
In real-world scenarios where the usage of models is afflicted by noisy or irregular data, smoothing or fil- tering techniques often prove useful in attaining estimates of the unknown variables (state space models where the latent variable is unknown, thus termed hidden Markov models). Such a method was developed by Kalman (1960).
Suppose that the variable under consideration to be modelled, xk, depends on its previous state, xk−1,
perturbed by some noise factor,wk, and satisfies
xk=Akxk−1+Bkuk+wk. (A.69)
Ak is the state transition model from statek−1 to statek,Bk is the control input model,uk is the control
input vector andwk ∼N(0, Qk) is the noise of the process, with Qk =E[wkwkT]. Control inputs are often
not relevant in financial models and are mostly omitted in the pertaining literature, as will be done here as well. (A.69) represents the state transition equation.
The measurement equation, which relatesxk to the current observation, is given by
zk =Hkxk+vk, (A.70)
A.2 Statistical Models, Tests and Distributions 139
A.2.12.1 Derivation of the Kalman Filter Algorithm
This section is based on content taken from Mastro (2013).
The Kalman filter algorithm utilises (A.69) and (A.70) to find the optimal weighting, called the Kalman gain, between the model predicted estimate and the observed value by finding the minimum variance of the mean square error between the true state, xk, and the estimated state, ˆxk. The error at time kis given by
ek=xk−xˆk. (A.71)
The prediction estimate for the state at time stepk, denoted by ˆx−k, is obtained using the transition model
at (A.69) as follows:
ˆ
x−k =Akxˆk−1. (A.72)
Similarly, the observation model at (A.70) is used with the predicted estimate to determine the observed (measurement) estimate for the state at time stepk:
ˆ
z−k =Hkxˆ−k =HkAkxˆk−1. (A.73)
The innovation or measurement residual, ik, is the difference between the actual observation at timek,zk,
and the predicted observation at (A.73):
ik=zk−zˆk−=zk−Hkxˆ−k.
The corrected estimate for the state variable atk, ˆxk, is calculated by adding to the transition estimate the
innovation residual, weighted by the Kalman gain Kk:
ˆ
xk= ˆx−k +Kkik
= ˆx−k +Kk(zk−Hkxˆ−k)
⇒xˆk= ˆx−k(I−KkHk) +Kkzk. (A.74)
Substituting (A.70) into (A.74) yields ˆ
xk= ˆx−k(I−KkHk) +Kk(Hkxk+vk). (A.75)
Now the error covariance matrix is given by
Pk=E[ekeTk] =E[(xk−xˆk)(xk−xˆk)T]. (A.76)
Using the expression at (A.75) in (A.76) gives
Pk=E[(xk−xˆ−k(I −KkHk) +Kk(Hkxk+vk)])(xk−xˆ−k(I−KkHk) +Kk(Hkxk+vk))T]
=E[((I −KkHk)(xk−xˆ−k)−Kkvk)((I−KkHk)(xk−xˆ−k)−Kkvk)T].
(A.77) The error betweenxk and ˆx−k, written as
A.2 Statistical Models, Tests and Distributions 140
is uncorrelated with the measurement noisevk, thus (A.77) becomes
Pk= (I−KkHk)E[(xk−xˆ−k)(xk−xˆk−)T](I−KkHk)T +KkE[vkvTk]KkT
= (I−KkHk)Pk−(I−KkHk)T +KkRkKkT.
(A.79) The mean square errors are the diagonal elements of the error covariance matrix at (A.79), which are simply the variances (since the diagonal elements of a covariance matrix are the variances). The total mean square error is the sum of the diagonal mean square error terms. The sum of the diagonal elements of a square matrix is called the trace. Hence to find the minimum mean square error and obtain an expression for the optimal Kalman gain, the minimum of the trace needs to be determined.
First, expanding out the terms in (A.79) gives
Pk=Pk−−KkHkPk−−Pk−KkTHkT +Kk(HkPk−HKT +Rk)KkT. (A.80)
Now the trace ofPk, denoted by Tr(Pk), is given by
Tr(Pk) = Tr(Pk−)−Tr(KkHkPk−)−Tr(P − k K T kHkT) + Tr(Kk(HkPk−H T K+Rk)KkT) = Tr(Pk−)−2 Tr(KkHkPk−) + Tr(Kk(HkPk−HKT +Rk)KkT), (A.81) where the second line follows since
Tr(KkHkPk−) = Tr(P −
k K
T kHkT).
To find the optimalKk, (A.81) is differentiated with respect to Kk and set to zero:
dTr(Pk) dKk = −2(HkPk−) T + 2K k(HkPk−H T K+Rk) = 0.
Solving for Kk yields the optimal Kalman gain as
⇒Kk=Pk−H
T
k(HkPk−H T
K+Rk)−1. (A.82)
The measurement prediction covariance,Sk, is defined as
Sk :=HkPk−HkT +Rk. (A.83)
Thus the Kalman gain can be rewritten as
Kk=Pk−HkT(Sk)−1. (A.84)
Multiplying both sides of (A.84) by SkKkT yields
KkSkKkT =P −
k H
T
A.2 Statistical Models, Tests and Distributions 141
Using (A.83) and then (A.85) in (A.80) results in the correction expression for the error covariance:
Pk =Pk−−KkHkPk−−P − k KkTHkT +KkSkKkT =Pk−−KkHkPk−−P − k K T kHkT +P − k H T kKkT =Pk−−KkHkPk− ⇒Pk = (I−KkHk)Pk−. (A.86)
The correction step of the Kalman filter is fully defined by (A.82), (A.74) and (A.86). The expression for the prediction of the state variable for the next time step is (A.72), with the corresponding error estimate given by (A.78). The remaining component to determine is the prediction of the error covariance.
Substituting (A.69) and (A.72) into (A.78) gives
e−k = (Akxk−1+wk)−Akxˆk−1
=Akek−1+wk.
The prediction of the error covariance for the next time step is
Pk−=E[(e−k)(e −
k)T] =E[(Akek−1+wk)(Akek−1+wk)T]. (A.87)
wk and e−k−1 are uncorrelated, as wk only occurs between times k−1 and k, whilst e−k−1 accumulates up
until time k−1 only. Thus the expression for the prediction of the error covariance is
Pk− =AkE[(e−k)(e − k) T]AT k +E[wkWkT] ⇒Pk− =AkPk−1ATk +Qk. (A.88)