Estimation of VAR(1)-GARCH(1,1) model

Discussions of ARCH, GARCH, and related models
irfanawan
Posts: 40
Joined: Wed Apr 01, 2015 2:12 pm

Estimation of VAR(1)-GARCH(1,1) model

Unread post by irfanawan »

Hi Tom,
I estimate VAR(1)-GARCH(1,1) using FRML command and by RATS command.
The coding for FRML is given below

Code: Select all

open data d-spcscointc.txt
data(format=free,org=columns,top=2) 1 2275 sp500 cisco intel
set r1 = sp500 
set r2 = cisco
set h1 = 0.0
set h2 = 0.0
nonlin a10 a11 a12 a20 a21 a22 c10 c20 c11 c12 c21 c22 d11 d12 d21 d22 rho
frml a1t = r1(t)-(a10+a11*r1(t-1)+a12*r2(t-1))
frml a2t = r2(t)-(a20+a21*r1(t-1)+a22*r2(t-1))
frml gvar1 = c10+c11*a1t(t-1)**2+c12*a2t(t-1)**2+d11*h1(t-1)+d12*h2(t-1)
frml gvar2 = c20+c21*a1t(t-1)**2+c22*a2t(t-1)**2+d21*h1(t-1)+d22*h2(t-1)
frml gdet = -0.5*(log(h1(t)=gvar1(t))+log(h2(t)=gvar2(t)) $
+log(1.0-rho**2))
frml gln = gdet(t)-0.5/(1.0-rho**2)*((a1t(t)**2/h1(t)) $
+(a2t(t)**2/h2(t))-2*rho*a1t(t)*a2t(t)/sqrt(h1(t)*h2(t)))
smpl 3 2275
compute a10 = .22, a20 = 0.07, a11 = 0.01, rho = 0.5, a12 = .4, a21 = .5
compute c10 = .27, c11 = 0.2, d11 = .6, c12 = .2, d12 = .2
compute c20 = .17, c22 = 0.13, d22 = 0.8, c21 = .1, d21 = .3
maximize(method=bhhh,iterations=500,rob) gln
the results are given below

Code: Select all

MAXIMIZE - Estimation by BHHH
Convergence in    61 Iterations. Final criterion was  0.0000064 <=  0.0000100
With Heteroscedasticity/Misspecification Adjusted Standard Errors
Usable Observations                      2273
Function Value                     -3672.6624

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  A10                           0.075049586          0.015269671      4.91494  0.00000089
2.  A11                          -0.006323123          0.024237368     -0.26088  0.79418256
3.  A12                           0.015632354           0.006210138      2.51723  0.01182811
4.  A20                           0.358889885           0.054470997      6.58864  0.00000000
5.  A21                          -0.074112862  0.066593131     -1.11292  0.26574257
6.  A22                           0.053170195  0.025089897      2.11919  0.03407463
7.  C10                           0.025733328  0.003531222      7.28737  0.00000000
8.  C20                           0.526537916  0.082069890      6.41573  0.00000000
9.  C11                           0.073885727  0.007072894     10.44632  0.00000000
10. C12                           0.001686320  0.000505247      3.33762  0.00084501
11. C21                           0.010094643  0.069358449      0.14554  0.88428210
12. C22                           0.119394861  0.013753363      8.68114  0.00000000
13. D11                           0.903275438  0.009356433     96.54057  0.00000000
14. D12                          -0.002602313  0.000572443     -4.54598  0.00000547
15. D21                          -0.125506227  0.089361091     -1.40448  0.16017476
16. D22                           0.833019216  0.016392141     50.81821  0.00000000
17. RHO                           0.520893393  0.014860092     35.05317  0.00000000
using the same data I estimate the model by following command

Code: Select all

garch(p=1,q=1,mv=cc,var=varma, reg, met=bhhh,rob) / r1 r2
# constant r1{1} r2{1}
the results are given below

Code: Select all

MV-CC GARCH  with VARMA Variances - Estimation by BHHH
Convergence in    34 Iterations. Final criterion was  0.0000062 <=  0.0000100
With Heteroscedasticity/Misspecification Adjusted Standard Errors
Usable Observations                      2273
Log Likelihood                     -7835.7082

  Variable                               Coeff      		Std Error      		T-Stat      	Signif
************************************************************************************
Mean Model(R1)
1.  Constant                   0.067452839         	 0.015238714         	4.42641              0.00000958
2.  R1{1}                          0.003889732          	0.023814160        	0.16334               0.87025315
3.  R2{1}                          0.014304492         	0.005903544         	2.42303              0.01539146
Mean Model(R2)
4.  Constant                   0.339449246  		0.055521257      	6.11386 	         0.00000000
5.  R1{1}                        -0.072030714  		0.066372692     		-1.08525  	       0.27781261
6.  R2{1}                         0.050964805  		0.025194395      	2.02286  	0.04308729
7.  C(1)                          0.011124304  		0.002561042      	4.34366  	0.00001401
8.  C(2)                          0.256512413  		0.059561465      	4.30668 	 0.00001657
9.  A(1,1)                        0.047385432  		0.006544956      	7.23999  	0.00000000
10. A(1,2)                      -0.000117081  		0.002152554     		-0.05439  	0.95662310
11. A(2,1)                       -0.081179705  		0.027107715     		-2.99471  	0.00274707
12. A(2,2)                        0.093852416  		0.013124545      	7.15091  	0.00000000
13. B(1,1)                        0.946030301  		0.008121174    		116.48935  	0.00000000
14. B(1,2)                       -0.005689723  		0.003706640    		 -1.53501  	0.12478183
15. B(2,1)                        0.051610857  		0.072453765      	0.71233  	0.47626159
16. B(2,2)                        0.883206748  		0.015656303     		56.41222  	0.00000000
17. R(2,1)                        0.521058810  		0.014914887     		34.93548  	0.00000000
I have the following questions
1 Why the log likelihood values are different for same models?
2. Why coefficients are different and their significance? The sign of coefficient are different and their values. some coefficient are significant in one estimation method and not in other.
Attachments
d-spcscointc.txt
(55.57 KiB) Downloaded 1043 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Estimation of VAR(1)-GARCH(1,1) model

Unread post by TomDoan »

The main reason for the huge gap in the log likelihoods is that your calculation doesn't include the integrating constants, and the RATS code does. If you use the following (in place of *your* gdet and gln), you'll get a log likelihood that's comparable:

frml gln = h1=gvar1(t),h2=gvar2(t),%logdensity(||h1|rho*sqrt(h1*h2),h2||,||a1t,a2t||)

Now, that only makes the likelihoods comparable in size, but doesn't change the results otherwise. The likelihood from your MAXIMIZE code is about 15 lower than what GARCH produces. That's because you're using a different initialization for the pre-sample variances. In fact, you're using 0's for the pre-sample variance which isn't a good idea. Correct that to use empirical estimates of the variance and you'll get pretty much the same results as GARCH. There's still a slight difference due to the handling of the pre-sample lagged squared residual, but that's minor---since there's no full-information likelihood function for a GARCH model, you'll get slightly different results from different estimators based upon their handling of pre-sample information.
irfanawan
Posts: 40
Joined: Wed Apr 01, 2015 2:12 pm

Re: Estimation of VAR(1)-GARCH(1,1) model

Unread post by irfanawan »

Dear Tom,
Thanks
Can you please modify my code, because I could not get what you wants to say. :?

Regards
Irfan
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Estimation of VAR(1)-GARCH(1,1) model

Unread post by TomDoan »

Code: Select all

open data d-spcscointc.txt
data(format=free,org=columns,top=2) 1 2275 sp500 cisco intel
set r1 = sp500
set r2 = cisco
*
* This replaces your initialization of variances to zero.
*
stats r1
set h1 = %variance
stats r2
set h2 = %variance
*
nonlin a10 a11 a12 a20 a21 a22 c10 c20 c11 c12 c21 c22 d11 d12 d21 d22 rho
frml a1t = r1(t)-(a10+a11*r1(t-1)+a12*r2(t-1))
frml a2t = r2(t)-(a20+a21*r1(t-1)+a22*r2(t-1))
frml gvar1 = c10+c11*a1t(t-1)**2+c12*a2t(t-1)**2+d11*h1(t-1)+d12*h2(t-1)
frml gvar2 = c20+c21*a1t(t-1)**2+c22*a2t(t-1)**2+d21*h1(t-1)+d22*h2(t-1)
*
* This uses %LOGDENSITY rather than expanding out the determinant and
* quadratic form calculations and includes the integrating constants.
*
frml gln = h1=gvar1(t),h2=gvar2(t),%logdensity(||h1|rho*sqrt(h1*h2),h2||,||a1t,a2t||)
smpl 3 2275
compute a10 = .22, a20 = 0.07, a11 = 0.01, rho = 0.5, a12 = .4, a21 = .5, a22 = 0.01
compute c10 = .27, c11 = 0.2, d11 = .6, c12 = .2, d12 = .2
compute c20 = .17, c22 = 0.13, d22 = 0.8, c21 = .1, d21 = .3
maximize(method=bhhh,iterations=500,rob,pmethod=simplex,piters=10) gln
*
garch(p=1,q=1,mv=cc,var=varma, reg, met=bhhh,rob) / r1 r2
# constant r1{1} r2{1}
irfanawan
Posts: 40
Joined: Wed Apr 01, 2015 2:12 pm

Re: Estimation of VAR(1)-GARCH(1,1) model

Unread post by irfanawan »

Hello Tom,
Can you please explain this function. I just wants to write my own, that's why I am asking you for explaining. I wants to improve my skills in RATS.


frml gln = h1=gvar1(t),h2=gvar2(t),%logdensity(||h1|rho*sqrt(h1*h2),h2||,||a1t,a2t||)

Thanks
Irfan
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Estimation of VAR(1)-GARCH(1,1) model

Unread post by TomDoan »

%LOGDENSITY(V,U) returns the log multivariate Normal density for covariance matrix V and residuals U including all the integrating constants.

The

h1=gvar1(t),h2=gvar2(t)

computes the two variance formulas (GVAR1 and GVAR2) and saves the results into H1(t) and H2(t).

||h1|rho*sqrt(h1*h2),h2||

is in-line matrix notation for the SYMMETRIC covariance matrix with h1 and h2 as the diagonals (variances) and rho as the correlation. You don't need the top right value in that because a covariance matrix is symmetric.

||a1t,a2t||

is in-line matrix notation for the pair of residuals using your formulas. This is doing the same calculation as you had, except you were writing out the inverse and determinant algebraically and you didn't have the integrating constants.
irfanawan
Posts: 40
Joined: Wed Apr 01, 2015 2:12 pm

Re: Estimation of VAR(1)-GARCH(1,1) model

Unread post by irfanawan »

Dear Tom,
I wants to execute this loop,
* Tsay, Analysis of Financial Time Series, 3rd edition
* Example 10.5 from pp 524-530
*
open data m-ibmspln.dat
calendar(m) 1926
data(format=prn,org=columns) 1926:1 1936:12 ibm sp
set sp500 = sp
*

*
* Compute the moving window correlations, creating the series
* "movingcorr"
*
do time=1935:12,1936:1
cmom(corr) time-199 time
# ibm sp500
set movingcorr time time = %cmom(1,2)
end do time
print / movingcorr

My Question is why we use time-199 time in this loop. What is the logic of using 199. Is it is a window?

Please guide me,
The data is attached
Attachments
m-ibmspln.dat
(18.23 KiB) Downloaded 981 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Estimation of VAR(1)-GARCH(1,1) model

Unread post by TomDoan »

irfanawan wrote: do time=1935:12,1936:1
cmom(corr) time-199 time
# ibm sp500
set movingcorr time time = %cmom(1,2)
end do time
print / movingcorr

My Question is why we use time-199 time in this loop. What is the logic of using 199. Is it is a window?

Please guide me,
Yes. It's a window of width 200 (time-199 to time) ending with time period <<time>>.
irfanawan
Posts: 40
Joined: Wed Apr 01, 2015 2:12 pm

Re: Estimation of VAR(1)-GARCH(1,1) model

Unread post by irfanawan »

Dear Tom, Thanks for your kind reply and guidance.

In the estimation of Multivariate GARCH models, when we change the pre-iteration the results of model change, what is the ideal no of pre-iterations for estimation? I did an estimation of VARMA-GARCH model with different pre-iterations. The spillover results change but the other remain same all the time.

My quires are
1. What is the ideal no of Pre-Iteration in estimation? Because it help in convergence.
2. Is it necessary to set pre-iteration in models?

looking for your reply

Irfan Malik
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Estimation of VAR(1)-GARCH(1,1) model

Unread post by TomDoan »

If you are getting converged results which are clearly different (not just third and fourth decimal place differences), then you presumably have a model with multiple modes. The one with the highest log likelihood is the one that you want.

The idea behind the preliminary iterations is to use an optimization method which is less sensitive to bad guess values than BFGS or BHHH. They aren't always needed, but when used, something in the 5-20 range is typically enough. More than that usually doesn't help and can make things worse. There's an extensive discussion of how simplex and BFGS work in the RATS Programming Manual.
irfanawan
Posts: 40
Joined: Wed Apr 01, 2015 2:12 pm

Re: Estimation of VAR(1)-GARCH(1,1) model

Unread post by irfanawan »

Dear Tom,
Hello.
I wants to estimate VAR(1,1)-EGARCH(1,1) model of Koutmos (1996).The results of model form my codes and window based estimates are different. the results from both estimation are given below.

The codes of above model by me

Code: Select all

open data d-spcscointc.txt
data(format=free,org=columns,top=2) 1 2275 sp500 cisco intel
set r1 = sp500
set r2 = cisco
*
* This replaces your initialization of variances to zero.
*
stats(noprint) r1
set h1 = %variance
stats(noprint) r2
set h2 = %variance
*
nonlin a10 a20 a11 a12 a21 a22 c10 c20 c11 c12 c21 c22  d1 d2 d11  d22 rho
frml e_r1 = r1(t)-a10-a11*r1(t-1)-a12*r2(t-1)
frml e_r2 = r2(t)-a20-a21*r1(t-1)-a22*r2(t-1)

frml ez_r1 = e_r1/sqrt(h1)

frml ez_r2 = e_r2/sqrt(h2)
smpl 3 2275
set abs_ez_r1 = abs(ez_r1)
stat(noprint) abs_ez_r1
set e_ez_r1 = %mean


set abs_ez_r2 = abs(ez_r2)
stat(noprint) abs_ez_r1
set e_ez_r2 = %mean

frml var_r1 = exp(c10+c11*(abs(ez_r1(t-1))-e_ez_r1+d11*ez_r1(t-1))+c12*(abs(ez_r2(t-1))-e_ez_r2+d22*ez_r2(t-1))+d1*log(h1(t-1)))
frml var_r2 = exp(c20+c21*(abs(ez_r1(t-1))-e_ez_r1+d11*ez_r1(t-1))+c22*(abs(ez_r2(t-1))-e_ez_r2+d22*ez_r2(t-1))+d2*log(h2(t-1)))
frml gln1 = h1=var_r1, h2=var_r2,%logdensity(||h1|rho*sqrt(h1*h2),h2||,||e_r1,e_r2||)
smpl 3 2275
compute a10 = 01, a20 = .2, a11 = .3, a12 = .4, a21 = .9, a22 = .08
compute c10 = .1, c20 = .04, c11= .04, c22 = .014, c12=.8, c21=.6, rho=.05
compute d1 = .1, d2 = .8, d11 = .04, d12 = .08, d21 = .088, d22 = .3
maximize(method=bhhh,ite=500,rob,pmethod=sim,pit=10) gln1
The result

Code: Select all

MAXIMIZE - Estimation by BHHH
Convergence in    31 Iterations. Final criterion was  0.0000086 <=  0.0000100
With Heteroscedasticity/Misspecification Adjusted Standard Errors
Usable Observations                      2273
Function Value                     -7778.3881

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  A10                           0.047119856  0.014772557      3.18969  0.00142426
2.  A20                           0.216337419  0.055991818      3.86373  0.00011167
3.  A11                           0.003155075  0.022867560      0.13797  0.89026282
4.  A12                           0.014971347  0.005682906      2.63445  0.00842730
5.  A21                          -0.037227001  0.066665622     -0.55841  0.57656187
6.  A22                           0.048595728  0.022898204      2.12225  0.03381669
7.  C10                          -0.094221448  0.010426593     -9.03665  0.00000000
8.  C20                          -0.006026707  0.015863555     -0.37991  0.70401299
9.  C11                           0.117070203  0.013037442      8.97954  0.00000000
10. C12                          -0.004949746  0.008745004     -0.56601  0.57138809
11. C21                          -0.020653342  0.012368147     -1.66988  0.09494277
12. C22                           0.105055509  0.016999095      6.18006  0.00000000
13. D1                            0.980705072  0.003157587    310.58686  0.00000000
14. D2                            0.969536178  0.004848293    199.97476  0.00000000
15. D11                          -0.541947327  0.096619951     -5.60906  0.00000002
16. D22                          -1.015678101  0.170005628     -5.97438  0.00000000
17. RHO                           0.519608947  0.015000116     34.64033  0.00000000
model specification from window based is

Code: Select all

GARCH(P=1,Q=1,MV=CC,VARIANCES=KOUTMOS,REGRESSORS,rob,METHOD=BHHH,ITERS=500,PMETHOD=SIMPLEX,PITERS=10) / R1 R2
# Constant R1{1} R2{1} 
The results

Code: Select all

MV-CC GARCH  with Koutmos EGARCH Variances - Estimation by BHHH
Convergence in    44 Iterations. Final criterion was  0.0000047 <=  0.0000100
With Heteroscedasticity/Misspecification Adjusted Standard Errors
Usable Observations                      2273
Log Likelihood                     -8006.4136

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
Mean Model(R1)
1.  Constant                      0.065315369  0.017927002      3.64341  0.00026905
2.  R1{1}                        -0.019311364  0.021231860     -0.90955  0.36306171
3.  R2{1}                         0.011508760  0.007463356      1.54204  0.12306500
Mean Model(R2)
4.  Constant                      0.231658728  0.055497911      4.17419  0.00002991
5.  R1{1}                        -0.037330125  0.061168551     -0.61028  0.54167437
6.  R2{1}                         0.037915391  0.023881130      1.58767  0.11236063

7.  C(1)                         -0.599195321  0.032625992    -18.36558  0.00000000
8.  C(2)                         -0.004548661  0.013666598     -0.33283  0.73926220
9.  A(1,1)                        0.069517016  0.011079403      6.27444  0.00000000
10. A(1,2)                       -0.048928892  0.009709326     -5.03937  0.00000047
11. A(2,1)                       -0.023186018  0.005244522     -4.42100  0.00000982
12. A(2,2)                        0.121192688  0.017993011      6.73554  0.00000000
13. B(1)                         -0.932773505  0.010994667    -84.83872  0.00000000
14. B(2)                          0.972529738  0.004839015    200.97678  0.00000000
15. D(1)                         -0.170281018  0.074500245     -2.28564  0.02227511
16. D(2)                         -0.773667220  0.124442847     -6.21705  0.00000000
17. R(2,1)                        0.544713226  0.014302165     38.08607  0.00000000
please check my coding and explain why the results are different from each other. The data is given in my VAR-GARCH post. Remember the results of VAR-GARCH model with written codes and window based estimation are nearly same


Regards, Irfan
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Estimation of VAR(1)-GARCH(1,1) model

Unread post by TomDoan »

Don't use BHHH. From the User's Guide:

The GARCH instruction provides four estimation methods, which you select with
the METHOD option. The choices are BFGS, BHHH, SIMPLEX and GENETIC, which are
described in Chapter 4. The default is BFGS. BHHH is a common choice, since the model
is in the form that can be estimated using that; however, it isn’t necessarily a good
choice as the main estimation method, as the curvature far from the maximum can
be quite different from that calculated by BHHH.

If you want the BHHH covariance matrix, it’s better to use BFGS as a preliminary
method, then switch to BHHH for a final iteration once it’s converged. The derivativefree
methods (SIMPLEX and GENETIC) are very useful in multivariate garch models,
but aren’t quite as important with the univariate ones. However, if you’re having
convergence problems with BFGS or BHHH, you can use the PMETHOD option with
SIMPLEX or GENETIC and combined with PITERS to refine the initial guesses.
irfanawan
Posts: 40
Joined: Wed Apr 01, 2015 2:12 pm

Re: Estimation of VAR(1)-GARCH(1,1) model

Unread post by irfanawan »

irfanawan wrote:Dear Tom,
My question is that the coding which I done is identical to the command window coding. Because I wants to include breaks in variance equations of the model. If the coding is fine it means that I have improve my skill a little with your help and guidance...

How can I extract series of residuals of this model? using my coding:?

Regards, Irfan

How Can I Get the Series of Residuals of EGARCH model Using my Codes............. :?:
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Estimation of VAR(1)-GARCH(1,1) model

Unread post by TomDoan »

Isn't that what e_r1 and e_r2 FRML's are computing?
irfanawan
Posts: 40
Joined: Wed Apr 01, 2015 2:12 pm

Re: Estimation of VAR(1)-GARCH(1,1) model

Unread post by irfanawan »

Dear Tom,
Hello.
I estimate the model using following likelihood function

Code: Select all

frml gln1 = h1=var_r1, h2=var_r2,%logdensity(||h1|rho*sqrt(h1*h2),h2||,||e_r1,e_r2||
Then I use the Print command
"print / e_r1"
the following error message
>>>>print / e_r2<<<<
Is it possible you meant
R2
If the name isn't mistyped, it's possible that you have a poorly formatted instruction
Common errors are
* a space before the ( in an option field
* a missing space before = in a SET or FRML
* a missing $ at the end of a long line which continues to the next

Then I write my likelihood function as
frml gln1 = ee_r1=e_r1, ee_r2=e_r2,h1=var_r1, h2=var_r2,%logdensity(||h1|rho*sqrt(h1*h2),h2||,||ee_r1,ee_r2||)

then I use the following command to get residuals
"print / e_r1"

the error message is as
## SX22. Expected Type SERIES[REAL], Got REAL Instead
>>>>print / ee_r2<<<<


What should I do next to get residuals

Regards, IRfan
Post Reply