Page 1 of 1

Recursive Forecast with loop

Posted: Sat Dec 14, 2013 11:50 am
by Jelena
Hello,

I have another issue. I tried to adjust the program for recursive window estimation that was (almost) like that provided somewhere in this forum. I wanted to create 12 X variables and than to regresses Y on a constant and each X in separate equations. For the simple IS analysis the procedure works. But when I try to adjust it for the OOS analyis I get an error message: "X13 is not defined in Freeze/ls_vol_x3013) eq_oos13.ls y z1 x13"
Of course its not defined, as I did not create it by purpose but also did not use it. And the only equation that is added to my workfile is ey_oos13 which is empty. I don't get where I made the mistake and would be very thankful if somebody could have a look!
Thank you!

smpl @all
'create a y series
series y=std_ann_vol_m

series z1=std_ann_vol_m(-1)

'create 15 X series
for !l=1 to 12
series x1=std_dividend_yield(-1)
series x2=std_exr
series x3=std_exr_gr
series x4=std_inf_gr
series x5=std_ms1_pp
series x6=std_ms1_sppy
series x7=std_ms3_pp
series x8=std_ms3_sppy
series x9=std_ppi_gr
series x10=std_term_spread
series x11=std_unempl
series x12=std_vol_inf

next

'run rolling regression

' set window size
!window = 180

' set step size
!step = 1

' get size of workfile
!length = @obsrange

' declare equation for estimation
equation eq_oos{!l}

'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)

'matrix to store coefficient estimates
matrix(4,!nrolls) coefmat ' where 2 is the number of coefficients

'series to store forecast estimates
series fcast2

'redundant series for 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 - recursive window
%first = @otod(@dtoo(%start))
%last = @otod(@dtoo(%start)+!i+!window-2)
smpl {%first} {%last}

' estimate equation - where the equation is y=c(1) + c(2)*x1

freeze(ls_vol_x30{!l}) eq_oos{!l}.ls y z1 x{!l}


' store coefficients
colplace(coefmat,eq_oos{!l}.@coef,!j)


' 1-period-ahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window-1) 'start point
%1pere = @otod(@dtoo(%start)+!i+!window) 'end point

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_oos{!l}.forecast(f=na) yf{!l}

' set sampl to obtain the 4th period observation
smpl {%1pere} {%1pere}

' store forecasts
fcast2{!l} = yf{!l}

next

'smpl @all
'show coefmat
'show fcast2.line

'd(noerr) yf

Re: Recursive Forecast with loop

Posted: Sat Dec 14, 2013 4:21 pm
by EViews Glenn
The error is in the line

Code: Select all

freeze(ls_vol_x30{!l}) eq_oos{!l}.ls y z1 x{!l}
which is below the !L loop (I'm using caps to be clear that this is "L" not "I"). Since you are past the loop, the value for !L is 13. The last term of the right-hand side is X13.