Page 1 of 1

DCC GARCH with t distribution and Maximize

Posted: Sun Feb 14, 2021 11:53 am
by Narci4269
Hi. I am trying to implement a DCC GARCH with a t-distribution. According to my hypothesis there is a MGARCH relationship between S&P500 (its daily return), Brent (in daily % change) and return of a oil & gas stock (called GPRK). This is my code:

Code: Select all

cal(irregular)
all 1736
open data I:\EAFIT\Tesis\GPRK\Accion_GPRK_diaria.xls
data(format=xls, org=obs)

**print(win = 'datos')

***** Data  *****

set us10y = US_10Y; set ca10y = CA_10Y;

dofor i = us10y ca10y Embi_Col smb hml Rf ERm
   set %s('r'+%l(i)) = i{0} / 252
end dofor

set rembi_col = (1 + rembi_col)

dofor i = GPRK ECP GTE PXT FEC SP500 TSX Brent VIX rembi_col
   set %s('l'+%l(i)) = log(i{0})
end dofor

dofor i = lGPRK lECP lGTE lPXT lFEC lSP500 lTSX lrembi_col lBrent lVIX
   set %s('d'+%l(i)) = i{0} - i{1}
end dofor

dofor i = dlGPRK dlECP dlGTE dlSP500
   set %s('r'+%l(i)) = 100 * (i{0} - Rf)
end dofor

dofor i = dlPXT dlFEC dlTSX
   set %s('r'+%l(i)) = 100 * (i{0} - Rf)
end dofor

dofor i = rsmb rhml rERm dlbrent dlrembi_col
   set %s(%l(i)) = 100 * i{0}
end dofor

***** MEan Eq *****

vcv(matrix=jj, noprint, centered)
# rdlsp500 dlBrent rdlgprk

dec symm[series] hgpk(3,3)
dec symm[series] hecp(3,3)
clear(zeros) hgpk hecp

equation eqsp5 dlsp500
# constant rdlsp500{1} rdlsp500{5} dlBrent{0}
equation eqbrt dlBrent
# constant dlBrent{1} dlBrent{5} rdlsp500{1}

linreg(noprint, robust, define = eqgpk) rdlgprk / rgpk
# constant rdlgprk{1 to 5} rERm dlBrent rsmb rhml dlvix

group modgrk eqsp5 eqbrt eqgpk

compute ini=%imax(%regstart(),2),fin=%regend()
***** Variance *****

com n = 3
dec vect[series] y(n) u(n)
dec vect[frml] resid(n)
dec series[symm] h uu
set y(1) = rERm
set y(2) = dlBrent
set y(3) = rdlgprk

clear u

linreg(noprint) y(1) ini fin u(1)
# constant y(1){1} y(1){5} y(2){0}
com mk0 = %beta(1), mk1 = %beta(2), mk5 = %beta(3), mkbr0 = %beta(4)

linreg(noprint) y(2) ini fin u(2)
# constant y(2){1} y(2){5} y(1){1}
com br0 = %beta(1), br1 = %beta(2), br5 = %beta(3), brmk1 = %beta(4)

linreg(noprint) y(3) ini fin u(3)
# constant y(3){1 to 5} rsmb rhml dlvix
com gk0 = %beta(1), gk1 = %beta(2), gk2 = %beta(3)
com gk3 = %beta(4), gk4 = %beta(5), gk5 = %beta(6)
com gk6 = %beta(7), gk7 = %beta(8), gk8 = %beta(9)
com gk9 = -0.5, gk10 = -0.5

nonlin(parmset=meanparms) mk0 mk1 mk5 mkbr0 br0 br1 br5 brmk1 gk0 gk1 $
gk2 gk3 gk4 gk5 gk6 gk7 gk8 gk9 gk10

frml resid(1) = (y(1)-mk0-mk1*y(1){1}-mk5*y(1){5}-mkbr0*y(2){0})
frml resid(2) = (y(2)-br0-br1*y(2){1}-br5*y(2){5}-brmk1*y(1){1})
frml resid(3) = (y(3)-gk0-gk1*y(3){1}-gk2*y(3){2}-gk3*y(3){3}-gk4*y(3){4}-gk5*y(3){5} $
                 -gk6*rsmb-gk7*hml-gk8*dlvix $
                 -gk9*(h(t)(3,1)/h(t)(1,1))*rERm-gk10*(h(t)(3,2)/h(t)(2,2))*dlBrent)

gset h  = %zeros(n,n)
vcv(matrix=rr,noprint, centered)
# u
*
* h will have the sequence of variance estimates
* uu will have the sequence of uu' matrices
*

*
* hx and uux are used when extracting elements from h and uu.
* ux is used when extracting a u vector
*
declare symm hx(n,n) uux(n,n)
declare vect ux(n)
*
* This is used to initialize pre-sample variances.
*
gset h = rr
gset uu = rr
*
* This is a standard log likelihood formula for any bivariate
* ARCH, GARCH, ARCH-M,... The difference among these will be in
* the definitions of HF and RESID.
*
declare frml[symm] hf
*

nonlin(parmset=distrib) nu
frml logl = $
%do(i,1,n,u(i)=resid(i)),$
hx = hf(t) , $
ux = %xt(u,t) , uux = %outerxx(ux),$
h(t) = hx , uu(t) = uux,$
%logtdensity(hx,ux,nu)
com nu = 3

***** DCC *****

dec vect vcv(n) vav(n) vbv(n)
com alpha=0.05, beta=0.90
*

function hfcccgarch time
type symm hfcccgarch
type integer time
do i=1,n
   compute hx(i,i)=vcv(i)+$
        vbv(i)*h(time-1)(i,i)+vav(i)*uu(time-1)(i,i)
   do j=1,i-1
     compute hx(i,j)=(1-alpha-beta)*jj(i,j)+alpha*uu(time-1)(i,j)+beta*h(time-1)(i,j)
   end do j
end do i
compute hfcccgarch=hx
end
*
frml hf = hfcccgarch(t)
nonlin(parmset=garchparms) vcv vav vbv alpha beta
compute vcv=%xdiag(rr),vav=%const(0.05),$
   vbv=%const(0.80) 
maximize(parmset=meanparms+garchparms+distrib,$
   pmethod=simplex,piters=100,method=bfgs,iters=500) logl ini fin
Let me know if my program is Ok, or need adjustments

Re: DCC GARCH with t distribution and Maximize

Posted: Sun Feb 14, 2021 12:28 pm
by TomDoan
I'd be a bit concerned about the timing issue on:

linreg(noprint) y(1) ini fin u(1)
# constant y(1){1} y(1){5} y(2){0}

Do you really want current y(2) as an explanatory variable? GARCH models really aren't designed for that type of arrangement.

That's an old way to do things. Given that the model is linear in (possibly generated) explanatory variables, you can do that much more easily as I noted in the other thread.

Re: DCC GARCH with t distribution and Maximize

Posted: Tue Feb 16, 2021 9:03 am
by Narci4269
Tom thanks a lot for your support. Very useful.
Regards,

Re: DCC GARCH with t distribution and Maximize

Posted: Fri Feb 19, 2021 3:05 pm
by Narci4269
HI Tom. I am including a Dummy variables as xregressor for GARCH (Dummy = 1 if t>=1525; 0 otherwise). The code for GARCH estimation runs properly, however for this calculation:

set rhomk = %cvtocorr(hho(t))(3,1)

This error arises:

## MAT15. Subscripts Too Large or Non-Positive
Error was evaluating entry 548

What could be wrong?
Regards,

Re: DCC GARCH with t distribution and Maximize

Posted: Fri Feb 19, 2021 3:29 pm
by Narci4269
I saw this thread: https://estima.com/forum/viewtopic.php?t=144
However I don't know with 1734 observations, it cuts in this way:

With Heteroscedasticity/Misspecification Adjusted Standard Errors
Usable Observations 541

Data as I see is not missing but let me know what could be wrong.
Regards,

Re: DCC GARCH with t distribution and Maximize

Posted: Tue Feb 23, 2021 1:27 pm
by TomDoan
Same data set? Does this work without the dummy? If it does, it sounds like a problem defining the dummy. Could you attach the full program? (Don't paste it into the message---do it as an attachment).

Re: DCC GARCH with t distribution and Maximize

Posted: Thu Mar 04, 2021 1:31 pm
by Narci4269
Tom I realized that in my Excel file I had calculations in a column, affecting all data set. Data was depured once this fail was detected.
Regards and thanks for your support.