' GARCH1.PRG (1.0 - 6/29/98)
' example program for EViews LogL object
' revised for version 4.0 (10/27/2000 h)
'
' GARCH(1,1) model with MA(1) errors and coef restrictions. 
'
' This is the specification described in Section 9.1 (pp. 3014-3017) 
' of Bollerslev, Tim, Robert F. Engle and Daniel B. Nelson (1994) 
' "ARCH Models", in Chapter 49 of the Handbook of Econometrics, 
' Volume 4, North-Holland, applied to different data. 

'change path to program path
'%path = @runpath
'cd "{%path}"

' load workfile
'load gerus

'series y = 100*dlog(ger)

if @isobject("s0")=1 then  delete s0 endif
if @isobject("s1")=1 then  delete s1 endif
if @isobject("ll1")=1 then  delete ll1 endif
if @isobject("logl")=1 then  delete logl endif

' set sample (1/2/82-7/9/92) as in Table 1, column 1
' 10/6/86 is obs 3945
sample s0 2750 2750
sample s1 2751 4538
smpl s1


' get starting values from Gaussian ARCH
equation eq1.arch y c 
' declare and initialize parameters
'coef(1) mu = eq1.c(1)
'coef(1) omega = eq1.c(2)
'coef(1) alpha = eq1.c(3)
'coef(1) beta = eq1.c(4)


' declare coef vectors to use in ARCH likelihood
coef(1) mu = 0.00307
'coef(1) theta = .1
coef(2) omega = 0.75415
coef(1) alpha =0.15
coef(1) beta =0.6


' get starting values from MA(1)
equation eq_temp.ls y c
'mu(1) = eq_temp.c(1)
'theta(1) = eq_temp.c(2)
'omega(1) = eq_temp.@se^2


' set presample values of expressions in logl
smpl s0
series sig2 =eq_temp.@se
series res = 0



' set up ARCH likelihood
logl ll1
ll1.append @logl logl
ll1.append res = y-mu(1)
'll1.append resma = res - theta(1)*resma(-1)        
ll1.append sig2 =omega(1)+alpha(1)*res(-1)^2+beta(1)*sig2(-1)
ll1.append z = res/@sqrt(sig2)
ll1.append logl =  log(@dnorm(z)) - log(sig2)/2


' estimate and display results         
smpl s1
ll1.ml(showopts, m=1000, c=1e-5)
show ll1.output

