Problem with the tv_garch.prg

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator

Posts: 4
Joined: Fri Dec 19, 2008 5:35 am

Problem with the tv_garch.prg

Postby fraN » Fri Dec 19, 2008 6:57 am


I am trying to apply the tv_garch.prg (which can be find in the example files of the Eview5 application) to three financial market indexes.
After launching the program I get the following messages: !MLOG2PI is not defined in "LOGL=
I checked several time all the previous commands and I am quite sure they are corrects. So I was wondering which could be the problem.

I would really appreciate if someone might give me some advices to solve this problem.

Many thanks,


Posts: 5
Joined: Mon Dec 15, 2008 5:50 pm

Re: Problem with the tv_garch.prg

Postby shhgc2 » Fri Dec 19, 2008 11:02 am

Could you upload your all code? it should be helpful to check your problem, I think.
actually, original code is below. and could you check that and comparare your code and original?

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

Code: Select all

' TV_GARCH.PRG (10/10/2000)
' example program for EViews LogL object
' revised for version 5.0 (3/26/2004)
' restricted version of
' tri-variate BEKK of Engle and Kroner (1995):
'  y = mu + 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
'     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 y2 (saved as cov_y1y3)
'         H(2,2) = variance of y2   (saved as var_y2)
'         H(2,3) = cov of y1 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 + "../data/"
cd %path

' load workfile
load intl_fin.wf1

' dependent variables of all series must be continues
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
equation eq1.arch(m=100,c=1e-5) y1 c
equation eq2.arch(m=100,c=1e-5) y2 c
equation eq3.arch(m=100,c=1e-5) y3 c

' declare coef vectors to use in GARCH model
coef(3) mu
 mu(1) = eq1.c(1)
 mu(2) = eq2.c(1)
 mu(3) = eq2.c(1)

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

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

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

' use sample var-cov as starting value of variance-covariance matrix

series cov_y1y2 = @cov(y1-mu(1), y2-mu(2))
series cov_y1y3 = @cov(y1-mu(1), y3-mu(3))
series cov_y2y3 = @cov(y2-mu(2), y3-mu(3))
series var_y1 = @var(y1)
series var_y2 = @var(y2)
series var_y3 = @var(y3)

series sqres1 = (y1-mu(1))^2
series sqres2 = (y2-mu(2))^2
series sqres3 = (y3-mu(3))^2

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

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

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

logl tvgarch

' squared errors and cross errors
tvgarch.append @logl logl
tvgarch.append sqres1 = (y1-mu(1))^2
tvgarch.append sqres2 = (y2-mu(2))^2
tvgarch.append sqres3 = (y3-mu(3))^2

tvgarch.append res1res2 = (y1-mu(1))*(y2-mu(2))
tvgarch.append res1res3 = (y1-mu(1))*(y3-mu(3))
tvgarch.append res2res3 = (y3-mu(3))*(y2-mu(2))

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

tvgarch.append cov_y1y2 = omega(1)*omega(2) + beta(2)*beta(1)*cov_y1y2(-1) + alpha(2)*alpha(1)*res1res2(-1)
tvgarch.append cov_y1y3 = omega(1)*omega(3) + beta(3)*beta(1)*cov_y1y3(-1) + alpha(3)*alpha(1)*res1res3(-1)
tvgarch.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
tvgarch.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))
tvgarch.append invh1 = (var_y2*var_y3-cov_y2y3^2)/deth
tvgarch.append invh2 = -(cov_y1y2*var_y3-cov_y1y3*cov_y2y3)/deth
tvgarch.append invh3 = (cov_y1y2*cov_y2y3-cov_y1y3*var_y2)/deth
tvgarch.append invh4 = (var_y1*var_y3-cov_y1y3^2)/deth
tvgarch.append invh5 = -(var_y1*cov_y2y3-cov_y1y2*cov_y1y3)/deth
tvgarch.append invh6 = (var_y1*var_y2-cov_y1y2^2)/deth

' log-likelihood series
tvgarch.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
'tvgarch.append @temp invh1 invh2 invh3 invh4 invh5 invh6 sqres1 sqres2 sqres3 res1res2 res1res3 res2res3 deth

' estimate the model
smpl s1, m=100, c=1e-5)

' change below to display different output
show tvgarch.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 - tvgarch.@logl)
scalar lr_pval = 1 - @cchisq(lr,3)

EViews Glenn
EViews Developer
Posts: 2555
Joined: Wed Oct 15, 2008 9:17 am

Re: Problem with the tv_garch.prg

Postby EViews Glenn » Fri Dec 19, 2008 12:18 pm

It might be worth trying to replace the !mlog2pi replacement variable with a scalar expression. It's possible that there has been a slight changing in the parsing...

You'd replace the line reading

!mlog2pi = 3*log(2*@acos(-1))

with the statement

scalar mlog2pi = 3*log(2*@acos(-1))

and then in the logl itself, just remove the "!" from the "!mlog2pi" in the append statement near the bottom. If you really wanted, you could simply remove the !mlog2pi term entirely since it's only a constant term and won't affect estimation, but then comparing likelihoods with other calculations which use inessential constants becomes problematic.

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

Re: Problem with the tv_garch.prg

Postby trubador » Sat Dec 27, 2008 6:30 am

Other than that, initial values of mu(3) and beta(3) should be taken from eq3 instead of eq2. Although it is not an important mistake and may not effect the outcome in most situations, still GARCH models are nonlinear in nature and some of them might display high sensitivity to starting values.

Return to “Programming”

Who is online

Users browsing this forum: Google [Bot] and 11 guests