'run rolling regression

' set window size
!window = 3750
' set step size
!step = 1 

' get size of workfile
!length = @obsrange

' declare equation for estimation
equation eq01
 
'calculate number of rolls
!nrolls = @ceiling((!length-!window)/!step)

'matrix to store coefficient estimates
matrix(9,!nrolls) coefmat ' where 9 is the number of coefficients

'variable keeping track of how many rolls we've done
!j=0

' move sample !step obs at a time
for !i = 1  to  !length-!window+1-!step step !step 
!j=!j+1

   ' set sample to estimation period
smpl @first+!i-1  @first+!i-1+!window

	' estimate equation

smpl @all

' declare coef vectors to use in ARCH likelihood

coef(1) mu = 0.022616
coef(1) omega1 = 0.085462
coef(1) beta1 = 0.568876
coef(1) gamma1 = 2.475915
coef(1) xi = -0.008748
coef(1) phi = 0.153614
coef(2) tau  
coef(1) tau11 = -0.018957 
coef(1) tau12 = 0.022325
coef(1) sigma = 0.072021

'get starting values

smpl @first @first+1
series ht = omega1(1)
series res = 0.1
series nt = 0.1
!pi = @acos(-1)

'' set up ARCH likelihood

logl  logl11
logl11.append @logl logl
logl11.append @byeqn
logl11.append res = rt-mu(1)
logl11.append ht = omega1(1)+beta1(1)*ht(-1)+gamma1(1)*rkvar(-1)
logl11.append nt = res/@sqrt(ht)
logl11.append ut = rkvar-xi(1)-phi(1)*ht-tau11(1)*nt-tau12(1)*((nt^2)-1)
logl11.append logl = -0.5*log(2*!pi)-0.5*log(ht)-0.5*((res^2)/ht)-0.5*log(2*!pi)-0.5*log(sigma(1))-0.5*((ut^2)/sigma(1))

' estimate and display results
smpl @first+1 @last
logl11.ml(showopts, m=1000, c=1e-5, optmethod=legacy, cov=white)
show logl11.output

'store coefficients
colplace(coefmat,logl11.@coefs,!j)

next

show coefmat

