Page 1 of 1

Why Different Results? of Built-in and Frml commands

Posted: Sat Oct 03, 2015 3:34 am
by irfanawan
Hello Dear Tom,
I am working on writing a codes for different models of financial time series that was provided built-in in the RATS. I try to do this because I need some modification in the variance equation of these models (Univarite and Multivariate) so that I will be able to introduce dummies in the variance equation. If I includes these dummies in variance equation using Xreg option it will introduce these dummies in both equations of volatility. I need different dummies in different equation (for example Mensi at el (2015) in which they introduce dummies for structural variance break). I did the coding by myself and compare the result of my codes (without dummies) with built-in code for verification. I did coding of EGARCH model of Nelson, VARMA-GARCH of McAller and EGRACH model of Koutmos. When I estimate models with my codes and buil-in commands, the results are different even though the likelihood is almost identical. This discrepancy in results mainly in the constant of variance equation(s) and coefficients of spillover effect (multivariate models). I have used same data (d-spcscointc.txt file of Tasy Book) for the estimation of these models. The results and codes are given below for your expert opinion. Kindly guide me so that I will be able to get identical estimates of my models with my codes and built-in commands.

EGARCH Models codes and results

The codes

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 h = %variance

nonlin c0 c1 c a b d
frml e = R1(t)-c0-c1*R1(t-1)
frml var = c+a*(abs(e(t-1)/sqrt(h(t-1)))-sqrt(2/%pi))+b*log(h(t-1))+d*(e(t-1)/sqrt(h(t-1)))

frml gln = h=exp(var(t)), %logdensity(h, e)
smpl 3 2275
compute c0= .17, c1 = 0.13, c = 0.8, a = .1, b = .0003, d=-1
maximize(method=bfgh,iterations=500,rob) gln

Code: Select all

GARCH(P=1,Q=1,EXP,ASYMMETRIC,rob,reg) / R1
# constant r1{1}
The Results

Code: Select all

MAXIMIZE - Estimation by BFGS
Convergence in    24 Iterations. Final criterion was  0.0000032 <=  0.0000100
With Heteroscedasticity/Misspecification Adjusted Standard Errors
Usable Observations                      2273
Function Value                     -2650.6793

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  C0                            0.042971207  0.016451077      2.61206  0.00899983
2.  C1                            0.041454940  0.024626977      1.68331  0.09231429
3.  C                            -0.002161605  0.004352407     -0.49665  0.61943875
4.  A                             0.124309653  0.028409867      4.37558  0.00001211
5.  B                             0.983974980  0.007608731    129.32182  0.00000000
6.  D                            -0.074441790  0.022458964     -3.31457  0.00091784

Code: Select all

GARCH Model - Estimation by BFGS
Convergence in    25 Iterations. Final criterion was  0.0000099 <=  0.0000100
With Heteroscedasticity/Misspecification Adjusted Standard Errors
Dependent Variable R1
Usable Observations                      2273
Log Likelihood                     -2651.6327

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  Constant                      0.043045336  0.014425693      2.98394  0.00284567
2.  R1{1}                         0.041561338  0.023235316      1.78871  0.07366086

3.  C                            -0.102111331  0.029282510     -3.48711  0.00048827
4.  A                             0.125353695  0.034747261      3.60758  0.00030906
5.  B                             0.983915225  0.008372386    117.51909  0.00000000
6.  D                            -0.073425349  0.025383578     -2.89263  0.00382029
By looking at the results: likelihood value in both results are nearly same. coefficients of mean equation are identical. Come to the variance equation, coefficient # 4, 5, and 6 are nearly same in both codes but look at constant of variance equation in both they are significantly different from each other.

Now the codes and results of EGARCH model of Koutmos

The codes

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

stats(noprint) r1
set h1 = %variance
stats(noprint) r2
set h2 = %variance

nonlin  M10 M11 M12 M20 M21 M22 C1 C2 A11 A12 A21 A22  B1 B2 D1  D2 rho

frml e_r1 = r1(t)-M10-M11*r1(t-1)-M12*r2(t-1)
frml e_r2 = r2(t)-M20-M21*r1(t-1)-M22*r2(t-1)

frml fr1 = (abs(e_r1/sqrt(h1))-sqrt(2/%pi))
frml fr2 = (abs(e_r2/sqrt(h2))-sqrt(2/%pi))

frml z1 = e_r1/sqrt(h1)
frml z2 = e_r2/sqrt(h2)

frml var_r1 = exp(c1+a11*(fr1(t-1)+d1*z1(t-1))+a12*(fr2(t-1)+d2*z2(t-1))+b1*log(h1(t-1)))
frml var_r2 = exp(c2+a21*(fr1(t-1)+d1*z1(t-1))+a22*(fr2(t-1)+d2*z2(t-1))+b2*log(h2(t-1)))


frml gln = h1 = var_r1(t), h2 = var_r2(t), %logdensity(||h1|rho*sqrt(h1*h2),h2||,||e_r1,e_r2||)
smpl 3 2275
compute m10 = 01, m20 = .2, m11 = .03, m12 = .04, m21 = .09, m22 = .08
compute c1 = .01, c2 = .04, a11= .04, a22 = .014, a12=.08, a21=.06
compute b1 = .01, b2 = .08, d1 = .04, d2 = .08
compute rho=.08

maximize(method=bfgh,ite=500,pit=20,pmet=sim,rob) gln

Code: Select all

GARCH(P=1,Q=1,MV=CC,VARIANCES=KOUTMOS,REGRESSORS,PMETHOD=SIMPLEX,PITERS=20,rob) / R1 R2
# Constant r1{1} R2{1}
The Results

Code: Select all

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

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  M10                           0.047121219  0.013493860      3.49205  0.00047933
2.  M11                           0.003150756  0.022161548      0.14217  0.88694398
3.  M12                           0.014972792  0.005958371      2.51290  0.01197431
4.  M20                           0.216337120  0.049657854      4.35655  0.00001321
5.  M21                          -0.037247364  0.081931155     -0.45462  0.64938420
6.  M22                           0.048598453  0.024417196      1.99034  0.04655380
7.  C1                           -0.004762401  0.004252895     -1.11980  0.26279807
8.  C2                            0.061290660  0.028398115      2.15827  0.03090723
9.  A11                           0.117066387  0.027882548      4.19855  0.00002686
10. A12                          -0.004946090  0.014637982     -0.33789  0.73544288
11. A21                          -0.020658764  0.018672091     -1.10640  0.26855429
12. A22                           0.105050725  0.026104390      4.02426  0.00005716
13. B1                            0.980705644  0.009125211    107.47211  0.00000000
14. B2                            0.969549832  0.014492062     66.90213  0.00000000
15. D1                           -0.541918842  0.088781796     -6.10394  0.00000000
16. D2                           -1.015702303  0.221988135     -4.57548  0.00000475
17. RHO                           0.519600274  0.017175700     30.25206  0.00000000

Code: Select all

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

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
Mean Model(R1)
1.  Constant                      0.046926041  0.010246796      4.57958  0.00000466
2.  R1{1}                         0.003722970  0.023917258      0.15566  0.87630072
3.  R2{1}                         0.015022906  0.005248749      2.86219  0.00420727
Mean Model(R2)
4.  Constant                      0.215835888  0.042987891      5.02085  0.00000051
5.  R1{1}                        -0.035827949  0.072481894     -0.49430  0.62109288
6.  R2{1}                         0.048756093  0.023112762      2.10949  0.03490248

7.  C(1)                         -0.094511925  0.022082230     -4.28000  0.00001869
8.  C(2)                         -0.006249044  0.022346638     -0.27964  0.77975267
9.  A(1,1)                        0.117611736  0.024107562      4.87862  0.00000107
10. A(1,2)                       -0.020517148  0.016283699     -1.25998  0.20767628
11. A(2,1)                       -0.005125008  0.013020480     -0.39361  0.69386801
12. A(2,2)                        0.105522682  0.025060981      4.21064  0.00002547
13. B(1)                          0.980614154  0.006154526    159.33220  0.00000000
14. B(2)                          0.969426894  0.013691089     70.80714  0.00000000
15. D(1)                         -0.537684424  0.118375654     -4.54219  0.00000557
16. D(2)                         -1.007991695  0.223240584     -4.51527  0.00000632
17. R(2,1)                        0.519245244  0.014370774     36.13203  0.00000000
Look at the results likelihood value and mean equations results are same in both results. The only difference in results at constant of variance equations and spillover effect. constants of variance equation not only different in values but in sign as well. The spillover effects are in reverse order in both codes. for example coefficient 10 of my codes is equal to coefficient 11 of built-in codes and also coefficient 11 of my codes is equal to coefficient 10 of built-in codes.

I am facing the same issue with VARMA GARCH model. Now what I should do to over come this issue?
Regards, Irfan Awan

Re: Why Different Results? of Built-in and Frml commands

Posted: Tue Oct 06, 2015 2:28 pm
by TomDoan
The difference in the variance intercept is that you're subtracting off sqrt(2/pi) from the terms while RATS doesn't. sqrt(2/pi) is a centering constant which is only the correct centering constant for conditionally Normal residuals---the mean is (a) different and (b) dependent upon the other parameters if the residuals are conditional t or conditionally GED. Since the centering constant just washed into the overall variance intercept anyway, we left it out.

If appears that the labeling is backwards on the off-diagonal elements in VARIANCE=KOUTMOS in version 9.0.

Re: Why Different Results? of Built-in and Frml commands

Posted: Wed Oct 07, 2015 5:10 am
by irfanawan
Dear Tom,
What should I do to get constant identical constant? Please guide me.

Regards, Irfan Awan

Re: Why Different Results? of Built-in and Frml commands

Posted: Wed Oct 07, 2015 8:15 am
by TomDoan
Don't subtract the sqrt(2/%pi) in the FRML.

Re: Why Different Results? of Built-in and Frml commands

Posted: Thu Oct 08, 2015 12:03 am
by irfanawan
Then what should I subtract instead of abs(2/%pi)? Either I subtract average value of abs(e(t-1)/sqrt(h(t-1)).

Regards, Irfan Malik

Re: Why Different Results? of Built-in and Frml commands

Posted: Thu Oct 08, 2015 7:36 am
by TomDoan
Nothing. There is no practical reason for it. It just gets absorbed into the variance constant.

Re: Why Different Results? of Built-in and Frml commands

Posted: Fri Oct 09, 2015 5:50 am
by irfanawan
Dear Tom,
I am very please for your guidance and learn a lot from you. My results are identical when I exclude the term sqrt(2/%pi) from variance equation.

I am facing the same issue with VAR-GARCH model of McAleer (2009). The resutls are different with my codes and built-in codes. Please take a look at codes and results as well. Then suggest me the solution for this problem. My codes and both results are given below for same data file that I have already uploaded in previous post under this topic. I try different initial values of estimates of parameters.

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
com rho = %corr(r1,r2)
nonlin  M10 M11 M12 M20 M21 M22 C1 C2 A11 A12 A21 A22  B11 B12 B21  B22 rho

frml e1 = r1(t)-M10-M11*r1(t-1)-M12*r2(t-1)
frml e2 = r2(t)-M20-M21*r1(t-1)-M22*r2(t-1)

frml var_r1 = c1+a11*e1(t-1)^2+a12*e2(t-1)^2+b11*h1(t-1)+b12*h2(t-1)
frml var_r2 = c2+a21*e1(t-1)^2+a22*e2(t-1)^2+b21*h1(t-1)+b22*h2(t-1)
frml co_var = rho*sqrt(h1*h2)

frml gln = h1 = var_r1(t), h2 = var_r2(t), %logdensity(||h1|co_var,h2||,||e1,e2||)
smpl 3 2275
compute m10 = 01, m20 = .2, m11 = .03, m12 = .04, m21 = .09, m22 = .08
compute c1 = .01, c2 = .04, a11= .04, a22 = .014, a12=.08, a21=.06
compute b11 = .01, b12 = .08, b21 = .04, b22 = .8

maximize(method=bhhh,ite=500,rob,pit=10,pmet=sim) gln


The Results

Code: Select all

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

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  M10                           0.069870978  0.015237169      4.58556  0.00000453
2.  M11                          -0.001028523  0.023838114     -0.04315  0.96558503
3.  M12                           0.015008108  0.005925930      2.53262  0.01132147
4.  M20                           0.338570832  0.055565446      6.09319  0.00000000
5.  M21                          -0.059275533  0.068359681     -0.86711  0.38588038
6.  M22                           0.050013859  0.024810854      2.01581  0.04382030
7.  C1                            0.012941789  0.002597112      4.98315  0.00000063
8.  C2                            0.276668429  0.055460155      4.98860  0.00000061
9.  A11                           0.051072544  0.005976769      8.54518  0.00000000
10. A12                           0.000441689  0.000389851      1.13297  0.25722807
11. A21                          -0.016030770  0.046705688     -0.34323  0.73142582
12. A22                           0.082782684  0.012039832      6.87573  0.00000000
13. B11                           0.935604204  0.007556951    123.80710  0.00000000
14. B12                          -0.000886322  0.000492151     -1.80091  0.07171654
15. B21                          -0.042450211  0.064814096     -0.65495  0.51249778
16. B22                           0.891335967  0.014409960     61.85555  0.00000000
17. RHO                           0.519534260  0.014930625     34.79655  0.00000000
Built-in command

Code: Select all

GARCH(P=1,Q=1,MV=CC,VARIANCES=varma,REGRESSORS,rob,met=bhhh,pit=10,pmet=sim) / R1 R2
# Constant r1{1} R2{1}
The Results

Code: Select all

MV-CC GARCH  with VARMA Variances - Estimation by BHHH
Convergence in    32 Iterations. Final criterion was  0.0000073 <=  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.067452808  0.015238718      4.42641  0.00000958
2.  R1{1}                         0.003889737  0.023814166      0.16334  0.87025302
3.  R2{1}                         0.014304465  0.005903543      2.42303  0.01539164
Mean Model(R2)
4.  Constant                      0.339449219  0.055521250      6.11386  0.00000000
5.  R1{1}                        -0.072030708  0.066372688     -1.08525  0.27781262
6.  R2{1}                         0.050964755  0.025194395      2.02286  0.04308750

7.  C(1)                          0.011124375  0.002561059      4.34366  0.00001401
8.  C(2)                          0.256515791  0.059562083      4.30670  0.00001657
9.  A(1,1)                        0.047385606  0.006544980      7.23999  0.00000000
10. A(1,2)                       -0.000117071  0.002152559     -0.05439  0.95662700
11. A(2,1)                       -0.081179784  0.027107887     -2.99469  0.00274722
12. A(2,2)                        0.093852804  0.013124600      7.15091  0.00000000
13. B(1,1)                        0.946030189  0.008121202    116.48894  0.00000000
14. B(1,2)                       -0.005689813  0.003706667     -1.53502  0.12477862
15. B(2,1)                        0.051611295  0.072454116      0.71233  0.47625999
16. B(2,2)                        0.883205862  0.015656424     56.41172  0.00000000
17. R(2,1)                        0.521059011  0.014914875     34.93553  0.00000000
There is slight difference in the log likelihood values of both results. Conditional correlation coefficient are identical as well as own past volatility effects. There is difference in own past shock effects and shock and volatility spillover effects. The mean equations estimates are identical with each other.

Please guide me

Regards, Irfan Malik

Re: Why Different Results? of Built-in and Frml commands

Posted: Wed Dec 16, 2015 1:44 pm
by TomDoan
We uploaded a new build of version 9 which corrects a minor bug in the calculation of VARIANCES=VARMA. You probably have to uninstall then redo the installation procedure.

Re: Why Different Results? of Built-in and Frml commands

Posted: Sat Jan 02, 2016 3:48 am
by irfanawan
Dear Tom,
I have re-install the RATS copy in my machine and re-estimate the models again. When I estimate the models with my code and built-in codes I have the same results. Please let me know what I should to overcome this issue... :D

Regards, Irfan

Re: Why Different Results? of Built-in and Frml commands

Posted: Wed Jan 06, 2016 5:29 am
by irfanawan
dear Tom,
I am still facing the same issue regarding results. Please help me in this regards,
Irfan Malik

Re: Why Different Results? of Built-in and Frml commands

Posted: Fri Jan 08, 2016 1:53 pm
by TomDoan
That looks pretty close to me!

Code: Select all

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

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  M10                           0.069874715  0.015237096      4.58583  0.00000452
2.  M11                          -0.001031958  0.023838682     -0.04329  0.96547100
3.  M12                           0.015009538  0.005926033      2.53281  0.01131511
4.  M20                           0.338590599  0.055563953      6.09371  0.00000000
5.  M21                          -0.059295334  0.068356007     -0.86745  0.38569617
6.  M22                           0.050022446  0.024811315      2.01611  0.04378803
7.  C1                            0.012951854  0.002598521      4.98432  0.00000062
8.  C2                            0.276893658  0.055494527      4.98957  0.00000061
9.  A11                           0.051094164  0.005978922      8.54571  0.00000000
10. A12                           0.000442422  0.000390014      1.13437  0.25663790
11. A21                          -0.016060627  0.046729268     -0.34370  0.73107550
12. A22                           0.082824920  0.012045064      6.87625  0.00000000
13. B11                           0.935574266  0.007560094    123.75167  0.00000000
14. B12                          -0.000887490  0.000492369     -1.80249  0.07146828
15. B21                          -0.042453034  0.064841667     -0.65472  0.51264906
16. B22                           0.891271683  0.014416121     61.82465  0.00000000
17. RHO                           0.519534203  0.014930324     34.79725  0.00000000


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

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
Mean Model(R1)
1.  Constant                      0.069585330  0.015242099      4.56534  0.00000499
2.  R1{1}                        -0.000426821  0.023814509     -0.01792  0.98570049
3.  R2{1}                         0.015041113  0.005924890      2.53863  0.01112870
Mean Model(R2)
4.  Constant                      0.337941958  0.055582672      6.07999  0.00000000
5.  R1{1}                        -0.058302214  0.068355822     -0.85292  0.39370232
6.  R2{1}                         0.050149842  0.024794099      2.02265  0.04310901

7.  C(1)                          0.012923447  0.002594654      4.98080  0.00000063
8.  C(2)                          0.277165926  0.055528933      4.99138  0.00000060
9.  A(1,1)                        0.050824190  0.005951409      8.53986  0.00000000
10. A(1,2)                        0.000442681  0.000389077      1.13777  0.25521543
11. A(2,1)                       -0.015404225  0.046679902     -0.33000  0.74140228
12. A(2,2)                        0.082640510  0.012013158      6.87917  0.00000000
13. B(1,1)                        0.935888803  0.007526249    124.34996  0.00000000
14. B(1,2)                       -0.000889264  0.000491253     -1.81020  0.07026553
15. B(2,1)                       -0.043222033  0.064807302     -0.66693  0.50481587
16. B(2,2)                        0.891410729  0.014403686     61.88768  0.00000000
17. R(2,1)                        0.519253774  0.014928617     34.78244  0.00000000