Moving sample method

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

Student15
Posts: 19
Joined: Fri Apr 17, 2015 2:23 pm

Moving sample method

Postby Student15 » Sat Jun 06, 2015 5:39 pm

Hi Guys

May you please help me with correctly declaring my sample objects in a rolling regression. I am trying to estimate a rolling regression with a moving window of 126 observations and a step size of 20.6. I am using daily data (irregular), so for example the observations from January 2004 to June 2004 are used to estimate the regression for June 2004, the observations from February to July 2004 will be used to estimate the regression for July 2004 and so forth till 2013.The errors I am getting are the division by zero errors but I am failing to correctly specify my sample objects. I have attached the work file. My code is as follows:

Code: Select all

'run rolling regression
' set window size
!window = 126
' set step size
!step = 20.6
' get size of workfile
!length = @obsrange
' declare equation for estimation
equation eq1
'calculate number of rolls
!nrolls = @round((!length-!window)/!step)

'matrix to store coefficient estimates
matrix(9,!nrolls) coefmat ' where 9 is the number of coefficients
matrix(9,!nrolls) tmat
'variable keeping track of how many rolls we've done
!j=0

' move sample !step obs at a time
for !i = 1  to  @round((!length-!window)/!step)
!j=!j+1

   ' set sample to estimation period
smpl @first+!i-1  @first+!i+!window-2

   ' estimate equation
sample s0 @first @first+!window-1
sample s1 @first+!step-1 @first+!window+!step-1
smpl @all
' declare coef vectors to use in ARCH likelihood
coef(4) beta = 0
coef(3) alpha = 0
coef(1) dof = 0
coef(1) mu = 0

' get starting values
equation eq1.arch(1,1,ged,archm=sd,backcast=1) y c y(-1)
eq1.makegarch garchm
equation eq1.arch(1,1,ged,archm=sd,backcast=1) y c garchm*y(-1) y(-1)
beta(1) = eq1.c(1)
beta(2) = eq1.c(2)
beta(3) = eq1.c(3)
beta(4) = eq1.c(4)
alpha(1) = eq1.c(5)
alpha(2) = eq1.c(6)
alpha(3) = eq1.c(7)
dof(1) = eq1.c(8)
mu(1) = eq1.@se^2

' set presample values of expressions in logl
series sig2 = mu(1)
series resid = resid

' set up GARCH likelihood
logl ll1
ll1.append @logl logl
ll1.append @byeqn
ll1.append resid = y - beta(2) - beta(1)*sig2 - beta(3)*sig2*y(-1)- beta(4)*y(-1)
ll1.append sig2 = alpha(1)+ alpha(2)*resid(-1)^2 + alpha(3)*sig2(-1)
ll1.append z = resid/@sqrt(sig2)
ll1.append logl = log(@dged(z,dof(1))) - log(sig2)/2

' declare coef vectors to use in ARCH likelihood
coef(4) beta = 0
coef(1) thresh = 0
coef(3) alpha = 0
coef(1) dof = 0
coef(1) mu = 0

' get starting values
eq1.arch(1,1,thrsh=1,archm=sd,ged,backcast=1) y c y(-1)
eq1.makegarch garchm
eq1.arch(1,1,thrsh=1,archm=sd,ged,backcast=1) y c garchm*y(-1) y(-1)
beta(1) = eq1.c(1)
beta(2) = eq1.c(2)
beta(3) = eq1.c(3)
beta(4) = eq1.c(4)
alpha(1) = eq1.c(5)
alpha(2) = eq1.c(6)
thresh(1) = eq1.c(7)
alpha(3) = eq1.c(8)
dof(1) = eq1.c(9)
mu(1) = eq1.@se^2

' set presample values of expressions in logl
series sig2 = mu(1)
series resid = resid

' set up GARCH likelihood
logl ll1
ll1.append @logl logl
ll1.append @byeqn
ll1.append resid = y - beta(2) - beta(1)*sig2 - beta(3)*sig2*y(-1)- beta(4)*y(-1)
ll1.append sig2 = alpha(1)+ alpha(2)*resid(-1)^2 + alpha(3)*sig2(-1) + thresh(1)*resid(-1)^2*(resid(-1)<0)
ll1.append z = resid/@sqrt(sig2)
ll1.append logl = log(@dged(z,dof(1))) - log(sig2)/2
' estimate and display results
smpl s1
ll1.ml(showopts, m=1000, c=1e-5)
show ll1.output
delete s0 s1

'store coefficients
   colplace(coefmat,ll1.@coefs,!j)
   colplace(tmat,ll1.@tstats,!j)

next
show coefmat
show tmat








Thank you
Attachments
daily returns.wf1
Company A
(69.86 KiB) Downloaded 200 times

Return to “Programming”

Who is online

Users browsing this forum: No registered users and 42 guests