## An Example Trivariate GARCH-in-Mean Program for EViews 6.0

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

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

### An Example Trivariate GARCH-in-Mean Program for EViews 6.0

Please find attached a programming code for trivariate garch-in-mean model written for EViews 6.0 sometime ago. I see that there is a growing need on multivariate garch estimation in EViews 6.0 recently and therefore decided to post it. Please keep in mind that you have to change the relevant parts (sample, series name, etc.) of the code to suit your own needs. Hope it will be useful...

Code: Select all

' TRIVARIATE GARCH-in-MEAN PROGRAM (01/05/2009)
' example program for EViews 6.0 LogL object
'
' restricted (diagonal) version of
' tri-variate BEKK of Engle and Kroner (1995):
'
' y = mu + lambda*H + res
'  res ~ N(0,H)
'
'  H = omega*omega' + beta*H(-1)*beta' + alpha*res(-1)*res(-1)'*alpha'
'
'  where,
'    y = 3 x 1
'    mu = 3 x 1
'    lambda = 3 x 1
'     H = 3 x 3 (symmetric)
'         H(1,1) = variance of y1   (saved as var_y1)
'         H(1,2) = cov of y1 and y2 (saved as cov_y1y2)
'         H(1,3) = cov of y1 and y3 (saved as cov_y1y3)
'         H(2,2) = variance of y2   (saved as var_y2)
'         H(2,3) = cov of y2 and y3 (saved as cov_y2y3)
'         H(3,3) = variance of y3   (saved as var_y3)
'   omega = 3 x 3 (low triangular)
'   beta = 3 x 3 (diagonal)
'   alpha = 3 x 3 (diagonal)
'

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

' dependent variables of all series must be continuous
series y1 = dlog(sp500)
series y2 = dlog(ftse)
series y3 = dlog(nikkei)

' set sample
' first observation of s1 need to be one or two periods after
' the first observation of s0
sample s0 3/3/94  8/1/2000
sample s1 3/7/94  8/1/2000

' initialization of parameters and starting values
' change below only to change the specification of model
smpl s0

'get starting values from univariate GARCH-in-mean
equation eq1.arch(archm=var,m=100,c=1e-5) y1 c
equation eq2.arch(archm=var,m=100,c=1e-5) y2 c
equation eq3.arch(archm=var,m=100,c=1e-5) y3 c

'save the conditional variances
eq1.makegarch garch1
eq2.makegarch garch2
eq3.makegarch garch3

' declare coef vectors to use in TVGARCHM model
coef(3) lambda
lambda(1) = eq1.c(1)
lambda(2) = eq2.c(1)
lambda(3) = eq3.c(1)

coef(3) mu
mu(1) = eq1.c(2)
mu(2) = eq2.c(2)
mu(3) = eq3.c(2)

coef(6) omega
omega(1) = (eq1.c(3))^.5
omega(2) = 0
omega(3) = 0
omega(4) = eq2.c(3)^.5
omega(5) = 0
omega(6) = eq3.c(3)^.5

coef(3) alpha
alpha(1) = (eq1.c(4))^.5
alpha(2) = (eq2.c(4))^.5
alpha(3) = (eq3.c(4))^.5

coef(3) beta
beta(1) = (eq1.c(5))^.5
beta(2) = (eq2.c(5))^.5
beta(3) = (eq3.c(5))^.5

' use sample var-cov as starting value of variance-covariance matrix
series cov_y1y2 = @cov(y1-mu(1)-lambda(1)*garch1, y2-mu(2)-lambda(2)*garch2)
series cov_y1y3 = @cov(y1-mu(1)-lambda(1)*garch1, y3-mu(3)-lambda(3)*garch3)
series cov_y2y3 = @cov(y2-mu(2)-lambda(2)*garch2, y3-mu(3)-lambda(3)*garch3)
series var_y1 = @var(y1-lambda(1)*garch1)
series var_y2 = @var(y2-lambda(2)*garch2)
series var_y3 = @var(y3-lambda(3)*garch3)

series sqres1 = (y1-mu(1)-lambda(1)*garch1)^2
series sqres2 = (y2-mu(2)-lambda(2)*garch2)^2
series sqres3 = (y3-mu(3)-lambda(3)*garch3)^2

series res1res2 = (y1-mu(1)-lambda(1)*garch1)*(y2-mu(2)-lambda(2)*garch2)
series res1res3 = (y1-mu(1)-lambda(1)*garch1)*(y3-mu(3)-lambda(3)*garch3)
series res2res3 = (y2-mu(2)-lambda(2)*garch2)*(y3-mu(3)-lambda(3)*garch3)

' constant adjustment for log likelihood
!mlog2pi = 3*log(2*@acos(-1))

' ...........................................................
' LOG LIKELIHOOD
' set up the likelihood
' 1) open a new blank likelihood object name tvgarch
' 2) specify the log likelihood model by append
' ...........................................................

logl tvgarchm

' squared errors and cross errors
tvgarchm.append @logl logl
tvgarchm.append sqres1 = (y1-mu(1)-lambda(1)*var_y1)^2
tvgarchm.append sqres2 = (y2-mu(2)-lambda(2)*var_y2)^2
tvgarchm.append sqres3 = (y3-mu(3)-lambda(3)*var_y3)^2

tvgarchm.append res1res2 = (y1-mu(1)-lambda(1)*var_y1)*(y2-mu(2)-lambda(2)*var_y2)
tvgarchm.append res1res3 = (y1-mu(1)-lambda(1)*var_y1)*(y3-mu(3)-lambda(3)*var_y3)
tvgarchm.append res2res3 = (y2-mu(2)-lambda(2)*var_y2)*(y3-mu(3)-lambda(3)*var_y3)

' variance and covariance series
tvgarchm.append var_y1  =  omega(1)^2 + beta(1)^2*var_y1(-1) + alpha(1)^2*sqres1(-1)
tvgarchm.append var_y2  = omega(2)^2+omega(4)^2 + beta(2)^2*var_y2(-1) + alpha(2)^2*sqres2(-1)
tvgarchm.append var_y3  = omega(3)^2+omega(5)^2+omega(6)^2 + beta(3)^2*var_y3(-1) + alpha(3)^2*sqres3(-1)

tvgarchm.append cov_y1y2 = omega(1)*omega(2) + beta(2)*beta(1)*cov_y1y2(-1) + alpha(2)*alpha(1)*res1res2(-1)
tvgarchm.append cov_y1y3 = omega(1)*omega(3) + beta(3)*beta(1)*cov_y1y3(-1) + alpha(3)*alpha(1)*res1res3(-1)
tvgarchm.append cov_y2y3 = omega(2)*omega(3) + omega(4)*omega(5) + beta(3)*beta(2)*cov_y2y3(-1) + alpha(3)*alpha(2)*res2res3(-1)

' determinant of the variance-covariance matrix
tvgarchm.append deth = var_y1*var_y2*var_y3 - var_y1*cov_y2y3^2-cov_y1y2^2*var_y3+2*cov_y1y2*cov_y2y3*cov_y1y3-cov_y1y3^2*var_y2

' calculate the elements of the inverse of var_cov (H) matrix
' numbered as vech(inv(H))
tvgarchm.append invh1 = (var_y2*var_y3-cov_y2y3^2)/deth
tvgarchm.append invh2 = -(cov_y1y2*var_y3-cov_y1y3*cov_y2y3)/deth
tvgarchm.append invh3 = (cov_y1y2*cov_y2y3-cov_y1y3*var_y2)/deth
tvgarchm.append invh4 = (var_y1*var_y3-cov_y1y3^2)/deth
tvgarchm.append invh5 = -(var_y1*cov_y2y3-cov_y1y2*cov_y1y3)/deth
tvgarchm.append invh6 = (var_y1*var_y2-cov_y1y2^2)/deth

' log-likelihood series
tvgarchm.append logl = -0.5*(!mlog2pi + (invh1*sqres1+invh4*sqres2+invh6*sqres3 +2*invh2*res1res2 +2*invh3*res1res3+2*invh5*res2res3 ) + log(deth))

' remove some of the intermediary series
tvgarchm.append @temp invh1 invh2 invh3 invh4 invh5 invh6 sqres1 sqres2 sqres3 res1res2 res1res3 res2res3 deth

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

' change below to display different output
show tvgarchm.output
graph var.line var_y1 var_y2 var_y3
graph cov.line cov_y1y2 cov_y1y3 cov_y2y3
show var
show cov

' LR statistic for univariate vs trivariate
scalar lr = -2*(eq1.@logl + eq2.@logl + eq3.@logl - tvgarchm.@logl)
scalar lr_pval = 1 - @cchisq(lr,3)

maryamjannesari
Posts: 5
Joined: Wed Nov 16, 2011 9:13 am

### Re: An Example Trivariate GARCH-in-Mean Program for EViews 6

hi
i entered all the code in logl window,but i got error message that no equation in system or model,can u help me ?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 12578
Joined: Tue Sep 16, 2008 5:38 pm

### Re: An Example Trivariate GARCH-in-Mean Program for EViews 6

The code Trubador posted is an EViews program. You should copy it into a Program (File->New->Program)

maryamjannesari
Posts: 5
Joined: Wed Nov 16, 2011 9:13 am

### Re: An Example Trivariate GARCH-in-Mean Program for EViews 6

ok,thanks ,but when i copy them in the program window ,i got the error message about my path that not found on disk ,can u plz help me

maryamjannesari
Posts: 5
Joined: Wed Nov 16, 2011 9:13 am

### Re: An Example Trivariate GARCH-in-Mean Program for EViews 6

thank u ,thank u thank u ,i solve it

JackCrow
Posts: 2
Joined: Thu Nov 24, 2011 10:51 pm

### Re: An Example Trivariate GARCH-in-Mean Program for EViews 6

Just to be clear, this model contains only a mean and own-variance effect in the mean equation, right?

In other words, y1=c+lambda1*garch1+res1. Can this code be altered to estimate less parsimonious models?

I need to estimate y1=c+lambda1*garch1+psi1*garch2+rho1*garch3+res1, y2 and y3 similar. Can you simply create conditional variance estimates, add necessary coefficients (with starting values for psi and rho gained from rerunning the univariate garch-m model with the conditional variance from the other equations) and then just change the residual and variance/covariance equations and estimate that model with this code?

Help is greatly appreciated.

wuyunting
Posts: 2
Joined: Fri Jul 25, 2014 5:33 am

### Re: An Example Trivariate GARCH-in-Mean Program for EViews 6

Hello, does anyone else know how to change the code about the matrix determinant and inverse matrices into a 7 by 7 matrix instead of 3 by 3? I try to calculate the determinant by eviews and create a series for that number(of the determinant), and I use the same method for inverse matrices.

matrix (7,7) m2
m2.fill var_y1, cov_y1y2, cov_y1y3, cov_y1y4, cov_y1y5 ,cov_y1y6 ,cov_y1y7, cov_y1y2, var_y2, cov_y2y3 ,cov_y2y4, cov_y2y5 ,cov_y2y6, cov_y2y7 ,cov_y1y3, cov_y2y3, var_y3 ,cov_y3y4 ,cov_y3y5, cov_y3y6, cov_y3y7, cov_y1y4 ,cov_y2y4, cov_y3y4, var_y4, cov_y4y5, cov_y4y6, cov_y4y7, cov_y1y5 ,cov_y2y5, cov_y3y5, cov_y4y5, var_y5, cov_y5y6, cov_y5y7, cov_y1y6 ,cov_y2y6, cov_y3y6, cov_y4y6, cov_y5y6, var_y6, cov_y6y7 ,cov_y1y7, cov_y2y7, cov_y3y7, cov_y4y7, cov_y5y7, cov_y6y7 ,var_y7

scalar dm2=@det(m2)
series sdm2=dm2
tvgarchm.append deth=sdm2

however, the outcome for the model with code 'tvgarchm.ml(showopts, m=100, c=1e-5) show tvgarchm.output graph cov.line cov_y1y2 cov_y1y3 cov_y1y4 cov_y1y5 cov_y1y6 cov_y1y7' is several outlier points and a straight line. I cannot do manually since it involves huge calculation. Thank you!

thaotc4ueh
Posts: 1
Joined: Sat Mar 07, 2015 4:43 am

### Re: An Example Trivariate GARCH-in-Mean Program for EViews 6

maryamjannesari wrote:ok,thanks ,but when i copy them in the program window ,i got the error message about my path that not found on disk ,can u plz help me

I also have a question like you, what did you do?