## Dynamic conditional correlation multivariate GARCH

For technical questions regarding estimation of single equations, systems, VARs, Factor analysis and State Space Models in EViews. General econometric questions and advice should go in the Econometric Discussions forum.

Moderators: EViews Gareth, EViews Moderator

malagesh
Posts: 1
Joined: Fri Jul 17, 2009 12:03 am

### Re: Dynamic conditional correlation multivariate GARCH

does anybody know how to incorporate asymmetry in DCC-GARCH model? i will be grateful to you if somebody can provide me asymmetric DCC-GARCH programme?
thanking you

Norling87
Posts: 1
Joined: Thu Apr 14, 2011 2:02 am

### Re: Dynamic conditional correlation multivariate GARCH

Hey!

The above given code works very well for estimating the DCC-GARCH, but as I understand it, the code uses the whole sample to estimate the correlation and uses that sample to estimate the correlation at each time t.

In my study, I want to use the DCC-GARCH in the bivariate case and roll a in-sample period of for say 500 observations to forecast an out-of-sample of, say 800 obervations. I want it to be a rolling-window forecast, shifting the in-sample 1-period ahead when forecasting the next days correlation. I tried to modify the code but wasn't even close to succeeding. Can anyone help me with this?

Regards

charlie295
Posts: 1
Joined: Tue Jul 19, 2011 5:48 am

### Re: Dynamic conditional correlation multivariate GARCH

Hi everybody,

I have managed to use the code provided kindly by hvtcapollo and produced reasonable rho values.

Probably an easy question but im not an expert in statistics, which of the series in the code gives the values of the conditional variances/st devs? (is it var_z1 and var_z2 or Z1/Z2 or something else)

thanks a lot

tg128
Posts: 18
Joined: Mon Sep 22, 2008 1:10 pm

### Re: Dynamic conditional correlation multivariate GARCH

Hvtcapollo wrote:You can consider this code. I used it last year for my research and you should be ok if using it for the bivariate. For trivariate u need to modify a litle bit especially for the log likelihood function.

Code: Select all

`'change path to program path%path=@runpathcd %path'load workfile containing the return seriesload nikkei_sp.WF1'set sample rangesample s1 1/06/1995 12/25/2007scalar pi=3.14159'defining the return series in terms of y1 and y2series y1=r_nikkeiseries y2=r_sp'fitting univariate GARCH(1,1) models to each of the two returns seriesequation eq_y1.arch(1,1,m=1000,h) y1 cequation eq_y2.arch(1,1,m=1000,h) y2 c'extract the standardized residual series from the GARCH fiteq_y1.makeresids(s) z1eq_y2.makeresids(s) z2'extract garch series from univariate fiteq_y1.makegarch() garch1eq_y2.makegarch() garch2'Caculate sample variance of series z1, z2 and covariance of z1and z2 and correlation between z1 and z2scalar var_z1=@var(z1)scalar var_z2=@var(z2)scalar cov_z1z2=@cov(z1,z2)scalar corr12=@cor(z1,z2)'defining the starting values for the var(z1) var(z2) and covariance (z1,z2)series var_z1t=var_z1series var_z2t=var_z2series cov_z1tz2t=cov_z1z2'declare the coefficient starting valuescoef(2) TT(1)=0.2T(2)=0.7' ...........................................................' LOG LIKELIHOOD for correlation part' set up the likelihood ' 1) open a new blank likelihood object and name it 'dcc'' 2) specify the log likelihood model by append' ...........................................................logl dccdcc.append @logl logl'specify var_z1t, var_z2t, cov_z1tz2tdcc.append var_z1t=@nan(1-T(1)-T(2)+T(1)*(z1(-1)^2)+T(2)*var_z1t(-1),1)dcc.append var_z2t=@nan(1-T(1)-T(2)+T(1)*(z2(-1)^2)+T(2)*var_z2t(-1),1)dcc.append cov_z1tz2t=@nan((1-T(1)-T(2))*corr12+T(1)*z1(-1)*z2(-1)+T(2)*cov_z1tz2t(-1),1)dcc.append pen=(var_z1t<0)+(var_z2t<0)'specify rho12dcc.append rho12=cov_z1tz2t/@sqrt(@abs(var_z1t*var_z2t))'defining the determinant of correlation matrix and determinant of Dtdcc.append detrRt=(1-(rho12^2))dcc.append detrDt=@sqrt(garch1*garch2)dcc.append pen=pen+(detrRt<0)dcc.append detrRt=@abs(detrRt)'define the log likelihood functiondcc.append logl=(-1/2)*(2*log(2*pi)+log(detrRt)+(z1^2+z2^2-2*rho12*z1*z2)/detrRt)-10*pen'estimate the modelsmpl s1dcc.ml(showopts, m=500, c=1e-5)'display output and graphsshow dcc.outputgraph corr.line rho12show corr`

thanks for the code!

i wonder how to compute q11,t and q22,t from the DCC model and save them seperately please?

ruhee.mittal
Posts: 2
Joined: Thu Nov 17, 2011 4:28 am

### Re: Dynamic conditional correlation multivariate GARCH

i am not able to get answers with this code.
is this code incomplete??

ruhee.mittal
Posts: 2
Joined: Thu Nov 17, 2011 4:28 am

### Re: Dynamic conditional correlation multivariate GARCH

hello,
i am not able to generate logl series with the above program. thus i am not able to reach the final results. kindly help me in solving this problem.
thnk you..

nikolastico
Posts: 1
Joined: Tue Mar 05, 2013 11:23 pm

### Re: Dynamic conditional correlation multivariate GARCH

Hello to all,

I'm currently trying to using this code I copied from another post and modified it to allow assymetries (ADCC). I'm trying to testing contagion on index returns series...

Code: Select all

`'ADCC Model by Cappiello et al (2006)'Load workfile and measure length of seriesseries obscount = 1scalar obslength = @sum(obscount)'Specify the return seriesseries y1 = bovespaseries y2 = igbvl'Specify the number of iterations in the MLE (Engle & Sheppard (2001) used just one iteration)!itermle = 1000'Specify the initial values of the parameterscoef(1) alphacoef(1) betacoef(1) gamma'Values may vary depending on which will result in the highest Likelihood valuealpha(1) = 0.04beta(1) = 0.94gamma(1) = 0.02'Setting the samplesample s0    @first+1 @lastsample s1    @first+2 @lastsample sf    @first+3 @lastsample sf_alt   @first+13 @last'Initialization at sample s0smpl s0'Each return series is modeled with their respective GARCH specifications:'Use Bollerslev-Wooldridge QML'Standard errorsequation eq1.arch(1,1,thrsh=1,m=1000,c=1e-5,h) y1 c y1(-1) 'res_s11_1000 @ res_s11_1000equation eq2.arch(1,1,thrsh=1,m=1000,c=1e-5,h) y2 c y2(-1) 'res_s22_1000 @ res_s22_1000'Make residual serieseq1.makeresids e1eq2.makeresids e2'Make a garch series from the univariate estimateseq1.makegarch h11eq2.makegarch h22'Normalizing the residuals from e to e* (named as "e1n" and "e2n")series e1n = e1/h11^0.5series e2n = e2/h22^0.5'Make residual series for asymmetries in DCC modelseries n1n = @recode(e1n<0,e1n*e1n,0)series n2n = @recode(e2n<0,e2n*e2n,0)'The Q_bar=E[en*en'] components and its sample equivalent series qbar11 = @mean(e1n*e1n)series qbar12 = @mean(e1n*e2n)series qbar21 = @mean(e2n*e1n)series qbar22 = @mean(e2n*e2n)'The N_barseries nbar11 = @mean(n1n*n1n)series nbar12 = @mean(n1n*n2n)series nbar21 = @mean(n2n*n1n)series nbar22 = @mean(n2n*n2n)'The (en*en') matrix componentsseries e11n = e1n*e1nseries e12n = e1n*e2nseries e21n = e2n*e1nseries e22n = e2n*e2n'The (nn*nn') matrix componentsseries n11n = n1n*n1nseries n12n = n1n*n2nseries n21n = n2n*n1nseries n22n = n2n*n2n'Initialize the elements of Qt for variance targetingseries q11 = @var(e1)series q12 = @cov(e1,e2)series q21 = @cov(e2,e1)series q22 = @var(e2)'***********************************************************************************************'Declare a Loglikelihood objectlogl dccdcc.append @logl logl'The elements of matrix Qtdcc.append  q11 = (qbar11 - (alpha(1))^2*qbar11 - (beta(1))^2*qbar11 + (gamma(1))^2*nbar11) + (alpha(1))^2*e11n(-1) + (gamma(1))^2*n11n(-1) + (beta(1))^2*q11(-1)dcc.append  q12 = (qbar12 - (alpha(1))^2*qbar12 - (beta(1))^2*qbar12 + (gamma(1))^2*nbar12) + (alpha(1))^2*e12n(-1) + (gamma(1))^2*n12n(-1) + (beta(1))^2*q12(-1)dcc.append  q21 = (qbar21 - (alpha(1))^2*qbar21 - (beta(1))^2*qbar21 + (gamma(1))^2*nbar21) + (alpha(1))^2*e21n(-1) + (gamma(1))^2*n21n(-1) + (beta(1))*2*q21(-1)dcc.append  q22 = (qbar22 - (alpha(1))^2*qbar22 - (beta(1))^2*qbar22 + (gamma(1))^2*nbar22) + (alpha(1))^2*e22n(-1) + (gamma(1))^2*n22n(-1) + (beta(1))^2*q22(-1)'As input to detQQQdcc.append  q12n = ((qbar11 - (alpha(1))^2*qbar11 - (beta(1))^2*qbar11 + (gamma(1))^2*nbar11) + (alpha(1))^2*e11n(-1) + (gamma(1))^2*n11n(-1) + (beta(1))^2*q11(-1))/((abs(q11)^0.5)*(abs(q22)^0.5))dcc.append  q21n = ((qbar21 - (alpha(1))^2*qbar21 - (beta(1))^2*qbar21 + (gamma(1))^2*nbar21) + (alpha(1))^2*e21n(-1) + (gamma(1))^2*n21n(-1) + (beta(1))*2*q21(-1))/((abs(q22)^0.5)*(abs(q11)^0.5))'Setting up the Loglikelihood function, assuming that resid ~ N(0,H)'The Loglikelihood function is L' = -0.5*{summation from t=1 to T of ([log of determinant of inverse(diag[Qt])*Qt*inverse(diag[Qt])] + [en'*inverse(diag[Qt])*Qt*inverse(diag[Qt])*en])'Taking the adjoint{inverse(diag[Qt])*Qt*inverse(diag[Qt])}dcc.append  detQQQ = 1 - q12n*q21n'Tomando el adjoint{inverse(diag[Qt])*Qt*inverse(diag[Qt])}dcc.append  cofact11 =   1*1dcc.append  cofact12 =(-1)*q21ndcc.append  cofact21 =(-1)*q12ndcc.append  cofact22 =   1*1'Taking the inverse{inverse(diag[Qt])*Qt*inverse(diag[Qt])}dcc.append  invQQQ11 = cofact11/detQQQdcc.append  invQQQ12 = cofact12/detQQQdcc.append  invQQQ21 = cofact21/detQQQdcc.append  invQQQ22 = cofact22/detQQQ'Taking the en'*inverse{inverse(diag[Qt])*Qt*inverse(diag[Qt])}*endcc.append  enQQQen11 = e1n*invQQQ11*e1ndcc.append  enQQQen12 = e1n*invQQQ12*e2ndcc.append  enQQQen21 = e2n*invQQQ21*e1ndcc.append  enQQQen22 = e2n*invQQQ22*e2n'Append the loglikelihood function'Instead of log(detQQQ) use log(abs(detQQQ))dcc.append logl = -0.5*(log(abs(detQQQ)) + (enQQQen11+enQQQen21+ enQQQen12+enQQQen22))'Specifies the sample data where the estimation will be madesmpl s1'Estimates the parameters now using BHHH algorithmdcc.ml(b, showopts, m=!itermle, c=1e-5) 'A detQQQnpd = 0 indicates detQQQ is positive definiteseries count = (detQQQ<=0)scalar detQQQnpd = @sum(count)'Display the estimated parametersshow dcc.output'Forecast the q's by initializing themseries  q11f = 0series  q12f = 0series  q21f = 0series  q22f = 0'Specify the sample period to be forecastedsmpl sfseries  q11f = (qbar11 - (alpha(1))^2*qbar11 - (beta(1))^2*qbar11 + (gamma(1))^2*nbar11) + (alpha(1))^2*e11n(-1) + (gamma(1))^2*n11n(-1) + (beta(1))^2*q11(-1)series  q12f = (qbar12 - (alpha(1))^2*qbar12 - (beta(1))^2*qbar12 + (gamma(1))^2*nbar12) + (alpha(1))^2*e12n(-1) + (gamma(1))^2*n12n(-1) + (beta(1))^2*q12(-1)series  q21f = (qbar21 - (alpha(1))^2*qbar21 - (beta(1))^2*qbar21 + (gamma(1))^2*nbar21) + (alpha(1))^2*e21n(-1) + (gamma(1))^2*n21n(-1) + (beta(1))*2*q21(-1)series  q22f = (qbar22 - (alpha(1))^2*qbar22 - (beta(1))^2*qbar22 + (gamma(1))^2*nbar22) + (alpha(1))^2*e22n(-1) + (gamma(1))^2*n22n(-1) + (beta(1))^2*q22(-1)'To plot the time-varying conditional correlationsmpl sf_altseries rt = q12f/(@sqr(q11f)*@sqr(q22f))graph rtgraph.line rtshow rtgraphdelete e1n e2ndelete q12n q21ndelete n1n n2ndelete n11n n12n n21n n22ndelete e11n e12n e21n e22ndelete qbar*delete xbar*delete cofact*delete enqqqen*delete invqqq*delete enqqqen*delete eigenvect*delete invqqq*show detqqqnpdseries eigminsscalar eigminfor !j = 4 to obslength   'Input the hijsim to the elements of a 2x2 Q matrix   sym(2) Q   Q(1,1) = q11f(!j)   Q(2,1) = q21f(!j)   Q(2,2) = q22f(!j)   'Take the eigenvalues of Q   vector(4) Qeigenval   Qeigenval = @eigenvalues(Q)   'Collect the min eigenvalues in each Qt   eigmins(!j) = @min(Qeigenval)nexteigmin = @min(eigmins)show eigmin`

I don't understand the following error message that Eviews 6 shows:

Missing values in @LOGL series at current coefficients at observation 1/24/1993 in "DO_DCC.ML(B,SHOWOPTS,M=1000,C=1E-5)"

Could anyone help me with this?

tesis_dcc.wf1
Thesis Workfile

Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

### Re: Dynamic conditional correlation multivariate GARCH

Carefully place your sample periods. For instance, you should use "smpl sf" instead of "smpl s1" before calling the estimation algorithm...

nicktz
Posts: 18
Joined: Thu Mar 28, 2013 1:41 am

### Re: Dynamic conditional correlation multivariate GARCH

snowdeer
Posts: 1
Joined: Wed May 08, 2013 5:02 am

### Re: Dynamic conditional correlation multivariate GARCH

I used the codes you provided for DCC-GARCH for eviews 5.0 and got the warning message "unmatched parenthesis" after typing the code"dcc.ml(showopts, m=500, c=1e-5)". Would you please enlighten me how to solve the problem? Thank you very much

Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

### Re: Dynamic conditional correlation multivariate GARCH

The code is not mine.

I am not sure if anything specific to version 5 is going on, but the message is pretty clear: There is at least one missing bracket somewhere in the code that you are currently using.

nicktz
Posts: 18
Joined: Thu Mar 28, 2013 1:41 am

### Re: Dynamic conditional correlation multivariate GARCH

I have trouble running the ADCC code on the attached data set.
It keeps saying missing values at 11/09/2007. This is a random date in the middle of my workfile.
I cannot understand what the problem might be! I have checked the starting values yet nothing seems to help.
Any ideas? Much appreciated!
Attachments
trial2.wf1

Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

### Re: Dynamic conditional correlation multivariate GARCH

There is a typo in your likelihood specification, which leads to explosive behavior:
dcc.append q21 = (qbar21 - (alpha(1))^2*qbar21 - (beta(1))^2*qbar21 + (gamma(1))^2*nbar21) + (alpha(1))^2*e21n(-1) + (gamma(1))^2*n21n(-1) + (beta(1))*2*q21(-1)
Just replace the red part with ^

nicktz
Posts: 18
Joined: Thu Mar 28, 2013 1:41 am

### Re: Dynamic conditional correlation multivariate GARCH

Thanks so much!!!! Rosen89
Posts: 2
Joined: Mon Aug 12, 2013 12:37 pm

### Re: Dynamic conditional correlation multivariate GARCH

I have seen that there are some other posts about this but none of the answers seem to make any difference for me: the problem is that when I run the LOGL I get up that I have missing values....
If anybody could help that would be brilliant as I have not much experience in this area (which is also why the code I am using is not mine but one I found in this forum)
For info purposes: I am running a spot price against a portfolio -- both weekly returns

'change path to program path
%path=@runpath
cd %path

'load workfile containing the return series

'set sample range
sample s1 1/07/2000 6/09/2006
scalar pi=3.14159

'defining the return series in terms of y1 and y2
series y1=spot
series y2=pf_h

'fitting univariate GARCH(1,1) models to each of the two returns series
equation eq_y1.arch(1,1,m=1000,h) y1 c
equation eq_y2.arch(1,1,m=1000,h) y2 c

'extract the standardized residual series from the GARCH fit
eq_y1.makeresids(s) z1
eq_y2.makeresids(s) z2

'extract garch series from univariate fit
eq_y1.makegarch() garch1
eq_y2.makegarch() garch2

'Caculate sample variance of series z1, z2 and covariance of z1and z2 and correlation between z1 and z2
scalar var_z1=@var(z1)
scalar var_z2=@var(z2)
scalar cov_z1z2=@cov(z1,z2)
scalar corr12=@cor(z1,z2)

'defining the starting values for the var(z1) var(z2) and covariance (z1,z2)
series var_z1t=var_z1
series var_z2t=var_z2
series cov_z1tz2t=cov_z1z2

'declare the coefficient starting values
coef(2) T
T(1)=0.2
T(2)=0.7

logl dcc
dcc.append @logl logl

'specify var_z1t, var_z2t, cov_z1tz2t
dcc.append var_z1t=@nan(1-T(1)-T(2)+T(1)*(z1(-1)^2)+T(2)*var_z1t(-1),1)
dcc.append var_z2t=@nan(1-T(1)-T(2)+T(1)*(z2(-1)^2)+T(2)*var_z2t(-1),1)
dcc.append cov_z1tz2t=@nan((1-T(1)-T(2))*corr12+T(1)*z1(-1)*z2(-1)+T(2)*cov_z1tz2t(-1),1)

dcc.append pen=(var_z1t<0)+(var_z2t<0)

'specify rho12
dcc.append rho12=cov_z1tz2t/@sqrt(@abs(var_z1t*var_z2t))

'defining the determinant of correlation matrix and determinant of Dt
dcc.append detrRt=(1-(rho12^2))
dcc.append detrDt=@sqrt(garch1*garch2)
dcc.append pen=pen+(detrRt<0)
dcc.append detrRt=@abs(detrRt)

'define the log likelihood function
dcc.append logl=(-1/2)*(2*log(2*pi)+log(detrRt)+(z1^2+z2^2-2*rho12*z1*z2)/detrRt)-10*pen

'estimate the model
smpl s1
dcc.ml(showopts, m=500, c=1e-5)

This is when I get up that I have missing values -- again, if anybody has time to help I would very much appreciate it 