Re: Multi-step ahead forecast
Posted: Fri Jul 18, 2014 7:59 am
The code you gave is for an EViews program. You'll need to run it in a program. Click on File->New->Program, then type it in there, and hit the run button.
Code: Select all
create u 10000
series returns=nrnd
series x1=nrnd
equation eq01.arch returns c x1
'set window size'
!window=400
'get size of workfile'
!lenght=@obsrange
'declare equation for estimation'
equation eq01
'set step size'
!step=1
'calculate number of rolls'
!nrolls=@floor((!lenght-!window)/!step)
'matrix to store coefficient estimates'
Matrix(5,!nrolls)coefmat 'where 5 is the number of coefficients
'series to store forecast estimates
series fcast
series fcastse
series fcastvar
'catching start and end points
%start= "@first"
%end= "@last"
'variable keeping track of how many rolls we've done
!j=0
'move sample !step obs at a time
for !i=1 to !lenght-!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}
'store coefficients
colplace(coefmat,eq01.@coefs,!j)
'1-period-ahead forecast
%5pers=@otod(@dtoo(%start)+!i+!window-1)
%5pere=@otod(@dtoo(%start)+!i+!window+4)
'set smpl for forecasting period
smpl {%5pers} {%5pere}
' forecast with command *fit*
eq01.fit(f=na) g_f1 g_se g_var
' store forecasts
fcast=g_f1
fcastse=g_se
fcastvar=g_var
'calculate RMSE
scalar rmse=@rmse(returns, fcast)
‘calculate MAE
Scalar mae=@mae(returns, fcast)
next
smpl 400 @last