I need to do a rolling estimation of a C-GARCH, outputting 1-day ahead forecast for the conditional variance.
I have observations of 4 years and i need a rolling window of the first 2. I found a code in the forum and i adjusted it to my needs. The problem is that the forecast series are on the returns. I need to forecast volatility. The code I used is below. Any help would be useful, thank you for your time!!
Code: Select all
' set window size
!window = 521
' set step size
!step = 1
' get size of workfile
!length = @obsrange
' declare equation for estimation
equation eq
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'matrix to store coefficient estimates
matrix(6,!nrolls) coefmat ' where 3 is the number of coefficients
'series to store forecast estimates
series fcast
'*EDITED: catching start and end points
%start = "@first" '@otod(@ifirst(ser))
%end = "@last" '@otod(@ilast(ser))
'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 for estimation period
%first = @otod(@dtoo(%start)+!i-1)
%last = @otod(@dtoo(%start)+!i+!window-2)
smpl {%first} {%last}
' estimate equation - where the equation is P =c(1) + c(2)*P1(-1)
eq.ARCH(cgarch) rt c
' store coefficients
colplace(coefmat,eq.@coefs,!j)
' 1-period-ahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window-1)
%1pere = @otod(@dtoo(%start)+!i+!window)
if @dtoo(%end) < @dtoo(%1pere) then 'check whether the forecast end point is greater than the workfile end point
exitloop
endif
' set smpl for forecasting period
smpl {%1pers} {%1pere}
' forecast with command *forecast* (see also *fit*)
eq.forecast(f=na) yf
' set sampl to obtain the 1st period observation
smpl {%1pere} {%1pere}
' store forecasts
fcast = yf
next
smpl @all
'show coefmat
'show fcast.line
d(noerr) yf
eq.makegarch garch01