I am using the returns of a stock market index by examining the returns on given days of the week (monday to friday), and I would like to complete a 1 step rolling forecast (egarch with GED dist) to forecast the volatility for the last year in my sample (2011). I found a code on the eviews forum, and made some adjustments to it and it works, but I was wondering if anyone could check the code's accuracy, as the results shown in fcastvar are almost identical to the actual variances for the last year.
Here is the code:
Code: Select all
' set window size
!window = 6262
' get size of workfile
!length = @obsrange
' declare equation for estimation
equation eq01
_this.ARCH(egarch, ged=1.5) return 'EDIT: get the equation specification
' set step size
!step = 1
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'matrix to store coefficient estimates
matrix(1,!nrolls) coefmat 'where the number of coefficients is 6.
series fcast 'series to store forecast estimates
series fcastse
series fcastvar
%start = "@first"
%end = "@last"
!j = 0
' move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j = !j +1
%first = @otod(@dtoo(%start)+!i-1)
%last = @otod(@dtoo(%start)+!i+!window-2)
smpl {%first} {%last}
'estimate equation - note I'm error catching here, any errors mean we'll keep going.
!maxerr = @maxerrcount
setmaxerrs !maxerr+1
_this.ARCH(egarch, ged=1.5) return monday tuesday wednesday thursday friday @ monday wednesday thursday friday 'estimate equation
if @lasterrnum>0 then
clearerrs
else
' 1-period-ahead forecast
%pers = @otod(@dtoo(%start)+!i+!window-1) 'start point
%pere = @otod(@dtoo(%start)+!i+!window-1) 'end point
if @dtoo(%end) < @dtoo(%pere) then 'check whether the forecast end point is greater than the workfile end point
exitloop
endif
' set smpl for forecasting period
smpl {%pers} {%pere}
eq01.forecast(f=na) audf1 aud_se aud_var
' store forecasts vars
fcast = audf1
fcastse = aud_se
fcastvar = aud_var
endif
next
smpl @all
Note that I am using Eviews 7 at University, and also note that I have zero knowledge of programming.
