Page 1 of 1

Multivariate ANST-GARCH

Posted: Mon Aug 29, 2011 3:21 am
by huanpipt
Hello, I want to run a bivariate ANST-GARCH-M.

I have some problem in following part,

Code: Select all

set rs = uu(t)(1,1)
set rf = uu(t)(2,2)

set fs = (1+%exp(-L*rs{1}))^(-1)
set ff = (1+%exp(-L*rf{1}))^(-1)
gset F = ||fs,ff||
There is a error message
"## SX22. Expected Type REAL, Got MATRIX(REAL) Instead
>>>>xp(-L*rs{1}))^(-1)<<<<"

But I don't know how to revise these part.

Following is whole code.

Code: Select all

compute n=2
compute gstart=1,gend=1555
*
dec series[vect] Y
dec frml[vect] R
dec vect[series] U(n)
dec series[vect] ECT

*
*
* 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] G uu
*
* ux is used when extracting a u vector
*
declare symm Gx(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 F(n)
dec vect EC(n) C1(n) C2(n)
dec rect T1(n,n) T2(n,n) F1(n,n) F2(n,n)

nonlin(parmset=meanparms) EC C1 C2 T1 T2 F1 F2 L
*
* Mean model = VAR(1) with sqrt(G) "M" term
*
frml R = Y-EC.*ECT{1}-C1-C2.*F-T1*Y{1}-T2.*F*Y{1}-F1*%sqrt(%xdiag(G))-F2.*F*%sqrt(%xdiag(G))
*
gset Y = ||dLSP,dLF1M||

linreg LSP / ECTEQ
# LF1M
gset ECT = ||ECTEQ,ECTEQ||



*
* Run preliminary VAR(4) to get estimates of residuals
*
*


linreg dLSP / u(1)
# constant dLSP{1} dLF1M{1} ecteq{1}

linreg dLF1M / u(2)
# constant dLSP{1} dLF1M{1} ecteq{1}

*
linreg dLSP
# constant dLSP{1} DLF1M{1} u(1) u(2) ecteq{1}
compute C1(1)=%beta(1),C2(1)=%beta(1),$
        T1(1,1)=%beta(2),T2(1,1)=%beta(2),$
        T1(1,2)=%beta(3),T2(1,2)=%beta(3),$
        F1(1,1)=%beta(4),F2(1,1)=%beta(4),$
        F1(1,2)=%beta(5),F2(1,2)=%beta(5),$
        EC(1)=%beta(6)

linreg dLF1M
# constant dLSP{1} dLF1M{1} u(1) u(2) ecteq{1}
compute C1(2)=%beta(1),C2(2)=%beta(1),$
        T1(2,1)=%beta(2),T2(2,1)=%beta(2),$
        T1(2,2)=%beta(3),T2(2,2)=%beta(3),$
        F1(2,1)=%beta(4),F2(2,1)=%beta(4),$
        F1(2,2)=%beta(5),F2(2,2)=%beta(5),$
        EC(2)=%beta(6)


vcv(matrix=WWW)
# u

*
* These are used to initialize pre-sample variances.
*
gset G  * gend = WWW
gset uu * gend = WWW
set u(1) = 0.0
set u(2) = 0.0
*
declare frml[symm] Gf
*
frml logl = $
    Gx    = Gf(t) , $
    G(t)  = Gx, $
    ux    = R , $
    uu(t) = %outerxx(ux), $
    %pt(u,t,ux),$
    %logdensity(Gx,ux)
*
set rs = uu(t)(1,1)
set rf = uu(t)(2,2)

set fs = (1+%exp(-L*rs{1}))^(-1)
set ff = (1+%exp(-L*rf{1}))^(-1)
gset F = ||fs,ff||



Re: Multivariate ANST-GARCH

Posted: Mon Aug 29, 2011 9:44 am
by TomDoan

Code: Select all

set rs = uu(t)(1,1)
set rf = uu(t)(2,2)

set fs = (1+%exp(-L*rs{1}))^(-1)
set ff = (1+%exp(-L*rf{1}))^(-1)
gset F = ||fs,ff||
You have two problems with this. First, you want to use just exp, not %exp in the third and fourth instructions. That's what's giving you the syntax error. However, you have a more fundamental problem. FS and FF depend upon L, which is one of your free parameters. A SET instruction will evaluate those only at the current value of L, so FS and FF won't change when L is updated as part of your estimation (and as a result, neither will F, which uses FS and FF). Instead, I think you want the following:

frml fs = (1+exp(-L*rs{1}))^(-1)
frml ff = (1+exp(-L*rf{1}))^(-1)
dec frml[vect] f
frml F = ||fs,ff||[/code]

Re: Multivariate ANST-GARCH

Posted: Mon Aug 29, 2011 12:27 pm
by huanpipt
Thanks your response.
But there is another problem.
I revised the code as following,

Code: Select all

set rs = uu(t)(1,1)
set rf = uu(t)(2,2)
frml fs = (1+exp(-L*rs{1}))^(-1)
frml ff = (1+exp(-L*rf{1}))^(-1)
dec frml[vect] F
frml F = ||fs,ff||
A error message comes
"## MAT15. Subscripts Too Large or Non-Positive
Error was evaluating entry 1"
I have found the error part,

Code: Select all

set rs = uu(t)(1,1)
set rf = uu(t)(2,2)
After I added following code, the problem has not been solved.

Code: Select all

dec series rs
dec series rf
This is my whole code, and I attach the data in this post.

Code: Select all

compute n=2
compute gstart=1,gend=1555
*
dec series[vect] Y
dec frml[vect] R
dec vect[series] U(n)
dec series[vect] ECT
dec series rs
dec series rf
*
*
* 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] G uu
*
* ux is used when extracting a u vector
*
declare symm Gx(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 EC(n) C1(n) C2(n)
dec rect T1(n,n) T2(n,n) F1(n,n) F2(n,n)
dec frml[vect] F


nonlin(parmset=meanparms) EC C1 C2 T1 T2 F1 F2 L
*
* Mean model = VAR(1) with sqrt(G) "M" term
*
frml R = Y-EC.*ECT{1}-C1-C2.*F-T1*Y{1}-T2.*F*Y{1}-F1*%sqrt(%xdiag(G))-F2.*F*%sqrt(%xdiag(G))
*
gset Y = ||dLSP,dLF1M||

set rs = uu(t)(1,1)
set rf = uu(t)(2,2)

frml fs = (1+exp(-L*rs{1}))^(-1)
frml ff = (1+exp(-L*rf{1}))^(-1)
frml F = ||fs,ff||


linreg LSP / ECTEQ
# LF1M
gset ECT = ||ECTEQ,ECTEQ||



*
* Run preliminary VAR(4) to get estimates of residuals
*
*


linreg dLSP / u(1)
# constant dLSP{1} dLF1M{1} ecteq{1}

linreg dLF1M / u(2)
# constant dLSP{1} dLF1M{1} ecteq{1}

*
linreg dLSP
# constant dLSP{1} DLF1M{1} u(1) u(2) ecteq{1}
compute C1(1)=%beta(1),C2(1)=%beta(1),$
        T1(1,1)=%beta(2),T2(1,1)=%beta(2),$
        T1(1,2)=%beta(3),T2(1,2)=%beta(3),$
        F1(1,1)=%beta(4),F2(1,1)=%beta(4),$
        F1(1,2)=%beta(5),F2(1,2)=%beta(5),$
        EC(1)=%beta(6)

linreg dLF1M
# constant dLSP{1} dLF1M{1} u(1) u(2) ecteq{1}
compute C1(2)=%beta(1),C2(2)=%beta(1),$
        T1(2,1)=%beta(2),T2(2,1)=%beta(2),$
        T1(2,2)=%beta(3),T2(2,2)=%beta(3),$
        F1(2,1)=%beta(4),F2(2,1)=%beta(4),$
        F1(2,2)=%beta(5),F2(2,2)=%beta(5),$
        EC(2)=%beta(6)

compute L = 30

vcv(matrix=WWW)
# u

*
* These are used to initialize pre-sample variances.
*
gset G  * gend = WWW
gset uu * gend = WWW
set u(1) = 0.0
set u(2) = 0.0
*
declare frml[symm] Gf
*
frml logl = $
    Gx    = Gf(t) , $
    G(t)  = Gx, $
    ux    = R , $
    uu(t) = %outerxx(ux), $
    %pt(u,t,ux),$
    %logdensity(Gx,ux)
*



*
* This does a simple GARCH(1,1) model for the variance.
*
dec symm A1(n,n) A2(n,n) A3(n,n) B1(n,n) B2(n,n) B3(n,n)

compute A1=WWW,B1=WWW,A2=%const(0.50),B2=%const(0.50),A3=%const(0.05),B3=%const(0.05)
nonlin(parmset=garchparms) A1 A2 A3 B1 B2 B3
frml Gf = A1+A2.*G{1}+A3.*uu{1}+(B1+B2.*G{1}+B3.*uu{1})*F

maximize(trace,parmset=meanparms+garchparms,pmethod=bfgs,piters=100,method=bfgs,iters=200) logl gstart+2 gend
*
* This does a BEKK model for the variance
*
dec rect AA2(n,n) AA3(n,n) BB2(n,n) BB3(n,n)
compute AA2=.05*%identity(n),AA3=.50*%identity(n),BB2=.05*%identity(n),BB3=.50*%identity(n)
compute A1=%decomp(WWW),B1=%decomp(WWW)
nonlin(parmset=garchparms) A1 AA2 AA3 B1 BB2 BB3
frml Gf = A1*tr(A1)+AA3*G{1}*tr(AA3)+AA2*uu{1}*tr(AA2)+(B1*tr(B1)+BB3*G{1}*tr(BB3)+BB2*uu{1}*tr(BB2))*F

maximize(trace,parmset=meanparms+garchparms,pmethod=bfgs,piters=100,method=bfgs,iters=200) logl gstart+2 gend

Re: Multivariate ANST-GARCH

Posted: Mon Aug 29, 2011 1:10 pm
by TomDoan
Do those SET instructions only over the range for which UU would be actually be defined.

Re: Multivariate ANST-GARCH

Posted: Fri Sep 02, 2011 1:36 am
by huanpipt
Dear Tom,

I've adjusted my code,

set rs gstart+2 gend = uu(t)(1,1)
set rf gstart+2 gend = uu(t)(2,2)

frml fs = 1/(1+exp(-L*rs{1}))
frml ff = 1/(1+exp(-L*rf{1}))
frml F = ||fs,ff||

, but it doesn't work with the same error message.

and I try to run the following code,

set rs = u(1)
set rf = u(2)

frml fs = 1/(1+exp(-L*rs{1}))
frml ff = 1/(1+exp(-L*rf{1}))
frml F = ||fs,ff||
, it work, but the usable sample is not as I expected.

The much sample is skipped, and every time I run the same code with different usable data which is shown from the result table.

I want to know if the code is wrong to deal with the multivariate smooth transformation function, and how to correct it right.

Thanks for your help.

Hoping hear from your, I am.

Re: Multivariate ANST-GARCH

Posted: Fri Sep 02, 2011 8:15 am
by TomDoan
Aren't your dimensions wrong on F? It should be a 2 x 2 matrix, not a 2 vector.

Re: Multivariate ANST-GARCH

Posted: Fri Sep 02, 2011 10:58 am
by huanpipt
Thanks for your help.
It really help me a lot.
I forget the F in the mean equation should not be the same as in the variance equation.

I have create a new 2*2 matrix, V, for the variance equation.
It work with correct sample, only the result is not perfect perhaps due to the wrong initial setting.
Following is my added code, would you mind to see if there is still problem.
And I appreciate your helping very much. :)

Code: Select all

dec frml[vect] F
dec frml[symm] V

frml rs = uu(t)(1,1)**(1/2)
frml rf = uu(t)(2,2)**(1/2)
frml rsf = uu(t)(1,2)**(1/2)

frml fs = 1/(1+exp(-L*rs{1}))
frml ff = 1/(1+exp(-L*rf{1}))
frml fsf = 1/(1+exp(-L*rsf{1}))
frml F = ||fs,ff||
frml V = ||fs|fsf,ff||

Re: Multivariate ANST-GARCH

Posted: Tue Sep 06, 2011 5:56 pm
by TomDoan
At this point, it would probably make the most sense for you to e-mail the set of equations that you're trying to estimate to us at support@estima.com.

Re: Multivariate ANST-GARCH

Posted: Sun May 06, 2018 9:54 pm
by wendystanner
Hi there. The multivatiate code is awesome,however, it does not work well for my data due to convergence problem. Is there a univariate version of ANST-GARCH available? I want to run two uni- model and then calculate hedge ratio. Thanks a lot.

Re: Multivariate ANST-GARCH

Posted: Mon May 07, 2018 4:25 pm
by TomDoan
See https://estima.com/forum/viewtopic.php? ... 123#p15750. However, how would you compute the hedge ratio from two separate univariate models? That wouldn't estimate the covariance, just the two variances.