Page 1 of 1
Multivariate GARCH-M, with restrictions across equations
Posted: Tue Jan 16, 2018 1:24 pm
by unfallenfelix
Dear Tom,
Here's Felix. I'm trying to estimate a pricing model using multivariate GARCH-in-Mean, and I want to restrict the coefficients to be the same across the three mean equations. How can I adjust the below code to achieve this? Thanks.
Code: Select all
dec symm[series] hhs(3,3)
clear(zeros) hhs
*******Define Three mean equations*********
equation rwf rw
# constant hhs(1,1) hhs(1,2) hhs(1,3)
equation rmf rm
# constant hhs(2,1) hhs(2,2) hhs(2,3)
equation rsf rs
# constant hhs(3,1) hhs(3,2) hhs(3,3)
*******Group the three equations***********
group garchm rwf rmf rsf
*******Estimate using GARCH(1,1)*********
garch(model=garchm,p=1,q=1,pmethod=simplex,piters=10,mvhseries=hhs)
Re: Multivariate GARCH-M, with restrictions across equations
Posted: Tue Jan 16, 2018 2:53 pm
by TomDoan
You can't use GARCH to do that---you would have to set up the GARCH model for estimation using MAXIMIZE. This is an older example of a GARCH model with M terms done using MAXIMIZE. This wouldn't be necessary to do this particular analysis now, as the HADJUST option could be used instead to handle the sqrt(variance), but shows how to estimate a model with a general set of mean model equations. You can impose the restrictions through the PARMSET.
Code: Select all
*
* Example of a multivariate GARCH-M model using square roots of the
* variances in the mean equation. The mean model is a VAR(1)+square
* roots of variances.
*
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})
*
compute n=3
compute gstart=3,gend=6237
*
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)
*
* These will be the parameters for the mean equations. These are
* adjusted to add variance or covariance terms as needed.
*
dec vect b(n)
dec rect ar(n,n) gm(n,n)
nonlin(parmset=meanparms) b ar
*
* Mean model = VAR(1) with sqrt(h) "M" term
*
frml residv = yv-b-ar*yv{1}-gm*%sqrt(%xdiag(h))
*
gset h = %zeros(n,n)
gset yv = ||xjpn,xfra,xsui||
*
* Get guess values for the mean parameters ignoring the "M" term by
* running an NLSYSTEM. (The system is actually linear, so this converges
* right away).
*
compute gm=%const(0.0)
nlsystem(parmset=meanparms,frml=residv) gstart gend
compute rr=%sigma
*
* Reset the parameter set for the means to include gm
*
nonlin(parmset=meanparms) b ar gm
*************************************************************************
*************************************************************************
*
* From this point, everything is the same as it would be for any GARCH
* model done using MAXIMIZE.
*
* These are used to initialize pre-sample variances.
*
gset h * gend = rr
gset uu * gend = rr
*
declare frml[symm] hf
*
* Common formula for the log likelihood
*
frml logl = $
hx = hf(t) , $
h(t) = hx, $
ux = residv , $
uu(t) = %outerxx(ux), $
%pt(u,t,ux),$
%logdensity(hx,ux)
*************************************************************
*
* Simple DVEC GARCH(1,1) model for the variance.
*
dec symm vcs(n,n) vas(n,n) vbs(n,n)
compute vcs=rr,vbs=%const(0.50),vas=%const(0.05)
nonlin(parmset=garchparms) vcs vas vbs
frml hf = vcs+vbs.*h{1}+vas.*uu{1}
maximize(parmset=meanparms+garchparms,$
pmethod=simplex,piters=5,method=bfgs,iters=400) logl gstart gend
Re: Multivariate GARCH-M, with restrictions across equations
Posted: Tue Jan 16, 2018 3:07 pm
by unfallenfelix
Thank you Tom! This is very helpful. I'm a new user of RATS and I find this Forum is amazing.
Felix
TomDoan wrote:You can't use GARCH to do that---you would have to set up the GARCH model for estimation using MAXIMIZE. This is an older example of a GARCH model with M terms done using MAXIMIZE. This wouldn't be necessary to do this particular analysis now, as the HADJUST option could be used instead to handle the sqrt(variance), but shows how to estimate a model with a general set of mean model equations. You can impose the restrictions through the PARMSET.
Code: Select all
*
* Example of a multivariate GARCH-M model using square roots of the
* variances in the mean equation. The mean model is a VAR(1)+square
* roots of variances.
*
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})
*
compute n=3
compute gstart=3,gend=6237
*
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)
*
* These will be the parameters for the mean equations. These are
* adjusted to add variance or covariance terms as needed.
*
dec vect b(n)
dec rect ar(n,n) gm(n,n)
nonlin(parmset=meanparms) b ar
*
* Mean model = VAR(1) with sqrt(h) "M" term
*
frml residv = yv-b-ar*yv{1}-gm*%sqrt(%xdiag(h))
*
gset h = %zeros(n,n)
gset yv = ||xjpn,xfra,xsui||
*
* Get guess values for the mean parameters ignoring the "M" term by
* running an NLSYSTEM. (The system is actually linear, so this converges
* right away).
*
compute gm=%const(0.0)
nlsystem(parmset=meanparms,frml=residv) gstart gend
compute rr=%sigma
*
* Reset the parameter set for the means to include gm
*
nonlin(parmset=meanparms) b ar gm
*************************************************************************
*************************************************************************
*
* From this point, everything is the same as it would be for any GARCH
* model done using MAXIMIZE.
*
* These are used to initialize pre-sample variances.
*
gset h * gend = rr
gset uu * gend = rr
*
declare frml[symm] hf
*
* Common formula for the log likelihood
*
frml logl = $
hx = hf(t) , $
h(t) = hx, $
ux = residv , $
uu(t) = %outerxx(ux), $
%pt(u,t,ux),$
%logdensity(hx,ux)
*************************************************************
*
* Simple DVEC GARCH(1,1) model for the variance.
*
dec symm vcs(n,n) vas(n,n) vbs(n,n)
compute vcs=rr,vbs=%const(0.50),vas=%const(0.05)
nonlin(parmset=garchparms) vcs vas vbs
frml hf = vcs+vbs.*h{1}+vas.*uu{1}
maximize(parmset=meanparms+garchparms,$
pmethod=simplex,piters=5,method=bfgs,iters=400) logl gstart gend
Re: Multivariate GARCH-M, with restrictions across equations
Posted: Wed Jan 17, 2018 12:38 pm
by unfallenfelix
Hi Tom,
The last section of the code use Simple DVEC GARCH(1,1) model for the variance, do you have the code for DCC GARCH(1,1) using MAXIMIZE ? Thanks.
Felix
TomDoan wrote:You can't use GARCH to do that---you would have to set up the GARCH model for estimation using MAXIMIZE. This is an older example of a GARCH model with M terms done using MAXIMIZE. This wouldn't be necessary to do this particular analysis now, as the HADJUST option could be used instead to handle the sqrt(variance), but shows how to estimate a model with a general set of mean model equations. You can impose the restrictions through the PARMSET.
Code: Select all
*
* Example of a multivariate GARCH-M model using square roots of the
* variances in the mean equation. The mean model is a VAR(1)+square
* roots of variances.
*
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})
*
compute n=3
compute gstart=3,gend=6237
*
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)
*
* These will be the parameters for the mean equations. These are
* adjusted to add variance or covariance terms as needed.
*
dec vect b(n)
dec rect ar(n,n) gm(n,n)
nonlin(parmset=meanparms) b ar
*
* Mean model = VAR(1) with sqrt(h) "M" term
*
frml residv = yv-b-ar*yv{1}-gm*%sqrt(%xdiag(h))
*
gset h = %zeros(n,n)
gset yv = ||xjpn,xfra,xsui||
*
* Get guess values for the mean parameters ignoring the "M" term by
* running an NLSYSTEM. (The system is actually linear, so this converges
* right away).
*
compute gm=%const(0.0)
nlsystem(parmset=meanparms,frml=residv) gstart gend
compute rr=%sigma
*
* Reset the parameter set for the means to include gm
*
nonlin(parmset=meanparms) b ar gm
*************************************************************************
*************************************************************************
*
* From this point, everything is the same as it would be for any GARCH
* model done using MAXIMIZE.
*
* These are used to initialize pre-sample variances.
*
gset h * gend = rr
gset uu * gend = rr
*
declare frml[symm] hf
*
* Common formula for the log likelihood
*
frml logl = $
hx = hf(t) , $
h(t) = hx, $
ux = residv , $
uu(t) = %outerxx(ux), $
%pt(u,t,ux),$
%logdensity(hx,ux)
*************************************************************
*
* Simple DVEC GARCH(1,1) model for the variance.
*
dec symm vcs(n,n) vas(n,n) vbs(n,n)
compute vcs=rr,vbs=%const(0.50),vas=%const(0.05)
nonlin(parmset=garchparms) vcs vas vbs
frml hf = vcs+vbs.*h{1}+vas.*uu{1}
maximize(parmset=meanparms+garchparms,$
pmethod=simplex,piters=5,method=bfgs,iters=400) logl gstart gend
Re: Multivariate GARCH-M, with restrictions across equations
Posted: Wed Jan 17, 2018 2:07 pm
by unfallenfelix
Hi Tom,
I've found the code under "Cappiello, Engle, Sheppard(2006) DCC GARCH models".
https://estima.com/forum/viewtopic.php? ... c+maximize
Thanks.
Felix
Re: Multivariate GARCH-M, with restrictions across equations
Posted: Thu Jan 18, 2018 6:32 am
by unfallenfelix
Hi Tom,
I use "display h" after MAXIMIZE instruction to print the covariance matrix, and I get a series of lower triangle matrix. Are these series of matrices the estimated covariances?
Since I've declared h to be symm, why the displayed matrices are lower triangular? I've used "%xcol(h,4)" in the mean equation, if h is in fact lower triangular, there'll be many zero elements in the dependent variables.
The code I used is based on the one you shared earlier.
Felix
Code: Select all
OPEN DATA "C:\Users\User\Desktop\SAS DATA\SAS output data.xlsx"
DATA(FORMAT=XLSX,ORG=COLUMNS) 1 847 rw rw usd jpy fwd rff US3MM period cut it ex r1 r2 r3 r4 r5 r6 r7 r8 $
r9 r10 r11 r12 r13 r14 r15 r16 r17 r18 r19 r20 us3m us5y us10y erd aaa dif dyld fwp i1 i2 rmm rm rs $
spr lgrw lgrm lgrs lgspr usterm lgusterm lgerd lgdyld lgaaa lgdif lgfwd lgfwp i3
*
compute n=24
compute gstart=3,gend=200
*
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)
*
* These will be the parameters for the mean equations. These are
* adjusted to add variance or covariance terms as needed.
*
nonlin(parmset=meanparms) a b c d
*
* Mean model = VAR(1) with sqrt(h) "M" term
*
frml residv = yv-a*%xcol(h,1)-b*%xcol(h,2)-c*%xcol(h,3)-d*%xcol(h,4)
*
gset h = %zeros(n,n)
gset yv = ||rw,rm,rs,spr,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16,r17,r18,r19,r20||
*
nlsystem(parmset=meanparms,frml=residv) gstart gend
*
compute rr=%sigma
*
*
*************************************************************************
*************************************************************************
*
* From this point, everything is the same as it would be for any GARCH
* model done using MAXIMIZE.
*
* These are used to initialize pre-sample variances.
*
gset h * gend = rr
gset uu * gend = rr
*
declare frml[symm] hf
*
* Common formula for the log likelihood
*
frml logl = $
hx = hf(t) , $
h(t) = hx, $
ux = residv , $
uu(t) = %outerxx(ux), $
%pt(u,t,ux),$
%logdensity(hx,ux)
*************************************************************
*
* Simple DVEC GARCH(1,1) model for the variance.
*
dec symm vcs(n,n) vas(n,n) vbs(n,n)
compute vcs=rr,vbs=%const(0.50),vas=%const(0.05)
nonlin(parmset=garchparms) vcs vas vbs
frml hf = vcs+vbs.*h{1}+vas.*uu{1}
maximize(parmset=meanparms+garchparms,$
pmethod=simplex,piters=5,method=bfgs,iters=400) logl gstart gend
display h
Re: Multivariate GARCH-M, with restrictions across equations
Posted: Thu Jan 18, 2018 7:20 am
by TomDoan
SYMMETRIC matrices are stored and displayed by their lower triangle, since there is no independent information in the upper triangle.
Re: Multivariate GARCH-M, with restrictions across equations
Posted: Sun Feb 04, 2018 12:45 am
by unfallenfelix
Hi Tom,
I've updated the code you provided to replicate De Santis and Gerald (1998). For the variance model, they've used a parsimonious setting as below,
Ht=H0*(ll'-aa'-bb')+aa'*et-1*e't-1+bb'*Ht-1, the code is,
Code: Select all
frml hf = cc.*(l*tr(l)-a*tr(a)-b*tr(b))+(a*tr(a)).*uu{1}+(b*tr(b)).*h{1}
where h is the covariance matrix, H0 (cc) is the unconditional covariance matrix, l is s*1 vector of ones, a and b are s*1 vectors of unknown parameters, e (u) is the residual, * (.*) is the Hadamard (element by element) matrix product. In this setting, there're 2s parmaters to estimate.
De Santis and Gerald (1998) set H0 (the unconditional matrix) equal to the sample covariance matrix of the returns in the first iteration. Thereafter it is updated using the covariance matrix of the stimated residuals at the end of each iteration. In my code below, I've used the sample covariance matrix as H0 (cc=rr=%sigma), but I don't know how to update it in the way De Santis and Gerald (1998) used. Please kindly help.
Code: Select all
********************declare***********************************************************
dec series[vect] yv
dec frml[vect] residv
dec vect[series] u(n)
declare series[symm] h uu
declare symm hx(n,n)
declare vect ux(n)
*************************mean model***************************************************
nonlin(parmset=meanparms) rff wa wb wc wd we ma mb mc md me $
sa sb sc sd se pa pb pc pd pe
frml residv = yv- rff- $
(wa+wb*i1+wc*i2+wd*i3+we*i4)*%xcol(h,1)- $
(ma+mb*i1+mc*i2+md*i3+me*i4)*%xcol(h,2)- $
(sa+sb*i1+sc*i2+sd*i3+se*i4)*%xcol(h,3)- $
(pa+pb*i1+pc*i2+pd*i3+pe*i4)*%xcol(h,4)
gset h = %zeros(n,n)
gset yv = ||rw,rm,rs,spr,r1,r2,r3,r4,r5||
nlsystem(parmset=meanparms,frml=residv) gstart gend
compute rr=%sigma
dispaly rr
************************GARCH MODEL *************************************************
gset h * gend = rr
gset uu * gend = rr
declare frml[symm] hf
frml logl = $
hx = hf(t) , $
h(t) = hx, $
ux = residv , $
uu(t) = %outerxx(ux), $
%pt(u,t,ux),$
%logdensity(hx,ux)
*******************************************************************************************
dec symm cc(n,n)
dec vect l(n)
dec vect a(n) b(n)
compute cc=rr
*
compute l=%const(1)
nonlin(parmset=garchparms) a b
frml hf = cc.*(l*tr(l)-a*tr(a)-b*tr(b))+(a*tr(a)).*uu{1}+(b*tr(b)).*h{1}
maximize(parmset=meanparms+garchparms,$
pmethod=simplex,piters=10,method=bfgs,iters=500,subiterations=100) $
logl gstart gend
**************************************************************************************
Re: Multivariate GARCH-M, with restrictions across equations
Posted: Mon Feb 05, 2018 11:03 am
by TomDoan
I don't find their GARCH model to be particularly convincing---that seems overly restricted. If you actually think the dynamics are that closely related, I would recommend going the whole distance and using the Cermeno and Grier panel GARCH restrictions.
There's nothing all that special about their handling of the covariance matrix. You have a parameter (the unconditional covariance matrix) which isn't being estimated freely, but is being calculated empirically, and you're looking for a fixed point in the estimation process. That's similar to the treatment of the weight matrix in overidentified GMM models, and you should note that in that case, continuous updating sometimes fails to converge. My recommendation is to do a two-step estimator instead---just do the MAXIMIZE to convergence, recompute the covariance matrix and redo the MAXIMIZE. That should give very similar results without running into problems chasing a fixed point. Again, however, you might want to think about what form of GARCH model to use, as it has nothing to do with how the "M" model works.