Variations on BEKK
Posted: Wed Dec 02, 2009 2:53 pm
The code below provides modernized calculations for standard, diagonal and triangular BEKK models. The standard BEKK, can, of course, be done with GARCH directly. The code using MAXIMIZE can be used as the base if you want some additional features that aren't currently included. This uses the same data set as the garchmv.prg example.
Note that MV=TBEKK (for triangular BEKK) and MV=DBEKK (for diagonal BEKK) were added to the GARCH instruction with RATS 8.3. Also, the SIGNS option was added to allow for different sign effects on asymmetry.
Note that MV=TBEKK (for triangular BEKK) and MV=DBEKK (for diagonal BEKK) were added to the GARCH instruction with RATS 8.3. Also, the SIGNS option was added to allow for different sign effects on asymmetry.
Code: Select all
*
* Variations on BEKK models
*
all 6237
open data g10xrate.xls
data(format=xls,org=columns) / usxjpn usxfra usxsui
*
set xjpn = 100.0*log(usxjpn/usxjpn{1})
set xfra = 100.0*log(usxfra/usxfra{1})
set xsui = 100.0*log(usxsui/usxsui{1})
*
* Standard BEKK with GARCH instruction
*
compute gstart=3,gend=6237
garch(p=1,q=1,mv=bekk,pmethod=simplex,piters=5) gstart gend xjpn xfra xsui
*
* General setup for GARCH with MAXIMIZE
*
compute n=3
*
dec series[vect] yv
dec frml[vect] residv
dec vect[series] u(n)
*
* The paths of the covariance matrices and uu' are saved in the
* SERIES[SYMM] named H and UU. UX and HX are used for the current values
* of the residual vector and H matrices
*
declare series[symm] h uu
*
* ux is used when extracting a u vector
*
declare symm hx(n,n)
declare vect ux(n)
declare frml[symm] hf
*
* Mean parameters
*
dec vect mu(n)
nonlin(parmset=meanparms) mu
*
* Define residuals
*
frml residv = yv-mu
*
* Define vector of dependent variables
*
gset yv = ||xjpn,xfra,xsui||
*
* Run preliminary regression to get estimates of residuals and means.
*
nlsystem(frmlvector=residv,parmset=meanparms,resids=u) gstart gend
compute rr=%sigma
*
* These are used to initialize pre-sample variances.
*
gset h * gend = rr
gset uu * gend = rr
*
frml logl = $
hx = h(t) = hf(t) , $
ux = residv , $
uu(t) = %outerxx(ux) , $
%pt(u,t,ux) , $
%logdensity(hx,ux)
******************************************************************
*
* Standard BEKK. Should be the same as above (just much slower)
*
dec rect var(n,n) vbr(n,n)
dec packed vct(n,n)
dec symm vcs
*
compute var=sqrt(.05)*%identity(n),vbr=sqrt(.45)*%identity(n)
compute vct=%decomp(rr)
nonlin(parmset=bekkparms) vct var vbr
FUNCTION %%BEKKInit
compute vcs=%ltouterxx(vct)
END
frml hf = vcs+%mqform(h{1},vbr)+%mqform(uu{1},var)
maximize(title="Standard BEKK Model",start=%%BEKKInit(),parmset=meanparms+bekkparms,$
method=bfgs,iters=400,pmethod=simplex,piters=5) logl gstart gend
******************************************************************
*
* Diagonal BEKK
*
dec vect vav(n) vbv(n)
dec packed vct(n,n)
dec symm vcs vbs vas
*
compute vav=%fill(n,1,sqrt(.05)),vbv=%fill(n,1,sqrt(.45))
compute vct=%decomp(rr)
nonlin(parmset=dbekkparms) vct vav vbv
FUNCTION %%DBEKKInit
compute vcs=%ltouterxx(vct)
compute vbs=%outerxx(vbv)
compute vas=%outerxx(vav)
END
*
frml hf = vcs+vbs.*h{1}+vas.*uu{1}
maximize(title="Diagonal BEKK Model",start=%%DBEKKInit(),parmset=meanparms+dbekkparms,$
method=bfgs,iters=400,pmethod=simplex,piters=5) logl gstart gend
******************************************************************
*
* Triangular BEKK. This is written assuming the "causality" flows from
* the first to the last series, which means that the A' matrix in A'HA
* needs to be lower triangular. Because of the convention used in
* defining "packed" matrices, the output will show A and B as lower
* triangular, so this is actually doing AHA' rather than A'HA.
*
dec packed vat(n,n) vbt(n,n)
dec packed vct(n,n)
dec rect var(n,n) vbr(n,n)
compute vat=sqrt(.05)*%identity(n),vbt=sqrt(.45)*%identity(n)
compute vct=%decomp(rr)
nonlin(parmset=tbekkparms) vct vat vbt
FUNCTION %%TBEKKInit
local integer i j
compute vcs=%ltouterxx(vct)
ewise vbr(i,j)=%if(j>=i,vbt(i,j),0.0)
ewise var(i,j)=%if(j>=i,vat(i,j),0.0)
END
frml hf = vcs+%mqform(h{1},vbr)+%mqform(uu{1},var)
maximize(title="Triangular BEKK",start=%%TBEKKInit(),parmset=meanparms+tbekkparms,$
method=bfgs,iters=400,pmethod=simplex,piters=5) logl gstart gend