## Stochastic volatility with exogenous variables via Kalman filter

June 3, 2014 by zulfahmed

The general form for a univariate state space model is:

and

Now according to Sandmann/Koopman, one extends this for explanatory variables as follows. We make have components . We append an identity matrix to so . Now does not change but we append zeros to . Next

. Here , and and .

Let us set up this problem so we can use the Kalman filter for quasi-ML estimation of parameters using the R package ‘FKF’. One has to translate to their notation:

fkf( a0, P0, dt, ct, Tt, Zt, HHt, GGt, yt)

Suppose that we have 3 exogenous variables, then we want to specify Zt with these. We want dt to be also specified. With we can set and .

One has to be a bit careful with the formatting of the input data: the ‘fkf’ package allows time-varying or stationary inputs for several parameters such as Tt, Zt and some others. These do not expect normal 2d matrices but 3d multidimensional array. In our case for example we want Zt to be a 3 x 1 x N array. Perhaps it is worthwhile spending some time on producing a wrapping that takes care of these preprocessing …

AN R FUNCTION FOR SANE LOG-LIKELIHOOD

So we are interested in a 1-dimensional observable and a -dimensional latent process where of the components handle exogenous variables. The code to do this with stochastic volatility parameters is the following. In order to obtain sane log-likelihoods it is best to check and handle ‘NA’ values from st (these are signs of the returns), yt (these are log-return-squared), X (exogenous variables, such as junk bond premium (DBAA-DAAA in Fred parlance), 3-month treasury rate (DTB3), etc. The function is just a wrapper around the ‘FKF’ filtering function. The output includes prediction, filtering, and smoothing.

function (yt,st,X,rho,phi,sigma.eta)
{
N=dim(yt)[2]
k<-dim(X)[2]
m<-k+1
d<-1
a0<-rep(0,m)
C0<-diag(1.0,m,m)*1e7
Tt<-diag(1.0,m,m)
Tt[1,1]<-phi
A<-0.7979*rho*sigma.eta
B<- 1.1061*rho*sigma.eta
Gt<-diag(0.,m,m)
Gt[1,1]<-sigma.eta^2-A^2
Ht<-pi^2/2
HHt<-Ht %*% t(Ht)
GGt<-Gt %*% t(Gt)
Zt<-array(0., dim=c(d,m,N))
for (k in 2:m){ Zt[d,k,]<-t(X[,k-1]) }
dt<-matrix(0.,m,N)
dt[1,]<-A*st
m1<-fkf( a0, C0, dt, matrix(0), Tt, Zt, GGt,HHt,yt)
m1
}

### Like this:

Like Loading...

*Related*

## Leave a Reply