
' Open workfile with the series y, which is an AR(1)ARCH(1) process:

' y 		= 0.8*y(-1) + e
' sig2 = 1 + 0.5*e(-1)

wfopen ".\ar1arch1.wf1"

' Estimate ar1arch1 model using the built-in command
' Derivatives: accurate numeric derivatives and always use numeric
' No backcasting of MA terms
' I use these two options in order to have a correct comparision with the manual ML estimation
smpl @first @last
equation eq1.arch(1,0,showopts,m=1000,c=1e-5,s=0,z,derivs="an") y c ar(1)


' Estimate an AR(1) model to obtain initial values for Maximum Likelihood estimation
equation eq0.ls y c ar(1)

' Setting the initial values for Maximum Likelihood estimation
' I use the same initial values as in the built in command in order to have a correct comparision with the built in command
coef(1) mu = 0.02682
coef(1) rho = 0.00500
coef(1) a0  = 1.88875
coef(1) a1  = 0.17143

' Initializing residual (res) and variance (var) series
smpl @first @first
series res  = 0
series var   = na

' Set up the likelihood
logl ar1arch1
ar1arch1.append @logl logl1
ar1arch1.append var = a0(1) + a1(1)*res(-1)^2
ar1arch1.append res = y - mu(1) - rho(1)*y(-1)
ar1arch1.append logl1 = -(1/2)*@log(2*@acos(-1))-(1/2)*@log(var)-(1/(2*(var)))*res^2

' Estimate using Maximum Likelihood
smpl @first+1 @last
ar1arch1.ml(showopts,m=1000,c=1e-5)

' Show relevant output
show eq1.output
show ar1arch1.output

' END of PROGRAM
