State Space forecasting with a rolling window

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

tmz
Posts: 6
Joined: Wed Aug 12, 2015 12:21 pm

State Space forecasting with a rolling window

Postby tmz » 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:
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 next
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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: State Space forecasting with a rolling window

Postby EViews Gareth » Wed Oct 19, 2016 1:54 pm

Each time through you're re-appending lines to the state space object, so you'll end up with a huge specification with lots of duplicates.

tmz
Posts: 6
Joined: Wed Aug 12, 2015 12:21 pm

Re: State Space forecasting with a rolling window

Postby tmz » Thu Oct 20, 2016 7:37 am

Hi,

Thank you for the quick answer.

The problem with the code seems to be in the forecast part. When I run the estimation part only, with a rolling window, it works. However, when I run the forecast part with the maximum likelyhood estimation(SSPACE.ml) and the forecast commande (SSPACE.forecast @signal y_forecast), I have the error message that I have a duplicate specification
Invalid or duplicate specification for state dependent variable in
equation "@STATE SV1 = SV1(-1) + [VAR = EXP(C(2))]" in "DO_
SSPACE.ML".
Do you know how to fix this problem? Is the code I am using appropriate for this kind of forecast model?

Thank you in advance.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13604
Joined: Tue Sep 16, 2008 5:38 pm

Re: State Space forecasting with a rolling window

Postby EViews Gareth » Thu Oct 20, 2016 7:57 am

Did you fix the issue I pointed out?

tmz
Posts: 6
Joined: Wed Aug 12, 2015 12:21 pm

Re: State Space forecasting with a rolling window

Postby tmz » Thu Oct 20, 2016 8:48 am

Hi Gareth,

Yes, I think I just fixed the issue you pointed out. I removed the append lines from the loop. After these modifications, my code looks like (again, this is for a 4-periods ahead forecast):

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 SSPACE.append @signal y=y(-1)+sv1+[var = exp(c(1))] SSPACE.append @state sv1=sv1(-1)+[var = exp(c(2))] '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 equation SSPACE.ml ' 4-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 forecast ' set sampl to obtain the 4th period observation smpl {%1pere} {%1pere} ' store forecasts fcast = forecast next
Please, let me know, if you find any mistakes in the code.

Thank you.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest