State Space forecasting with a rolling window
Posted: Wed Oct 19, 2016 1:46 pm
Hi, I have defined a given State Space Model and I am trying to forecast 1 to 8-period ahead with a fixed rolling window. However, it seems that Eviews can not estimate the SSpace's state in a rolling window. When I run my code, I have the error message:
My code for the 4-period ahead forecast is (Based on Gareth's code at: http://forums.eviews.com/viewtopic.php?t=878):
My question: is it possible to forecast the @signal in a rolling window situation and if so, what's wrong with my code? Any idea on how to accomplish the forecast?
Thank you
.Invalid or duplicate specification for state dependent variable in equation "@STATE SV1 = SV1(-1) + [VAR = EXP(C(2))]" in "DO_TEST.ML".
My code for the 4-period ahead forecast is (Based on Gareth's code at: http://forums.eviews.com/viewtopic.php?t=878):
Code: Select all
'run rolling regression
' set window size
!window = 156 '13 years
' set step size
!step = 1
' get size of workfile
!length = @obsrange
' declare equation for estimation
sspace SSPACE
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'series to store forecast estimates
series fcast
'redundant series for catching start and end points
series ser = 1
%start = @otod(@ifirst(ser))
%end = @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 state space
SSPACE.append @signal y = y(-1) + sv1 + [var = exp(c(1))]
SSPACE.append @state sv1 = sv1(-1) + [var = exp(c(2))]
SSPACE.ml
' 1-period-ahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window-1) 'start point
%1pere = @otod(@dtoo(%start)+!i+!window+2) 'end point
if (%end) < (%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
SSPACE.forecast @signal y_forecast
' set sampl to obtain the 4th period observation
smpl {%1pere} {%1pere}
' store forecasts
fcast = y_forecast
nextThank you