Multi-step ahead forecast

For questions regarding programming in the EViews programming language.

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

Nas1
Posts: 46
Joined: Thu Sep 06, 2012 5:20 am

Re: Multi-step ahead forecast

Postby Nas1 » Wed Jan 29, 2014 2:48 pm

EViews Gareth wrote:You have 7.


I just tried 7, and I got the same results of zero coefmat.

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

Re: Multi-step ahead forecast

Postby EViews Gareth » Wed Jan 29, 2014 3:05 pm

Works for me.
Follow us on Twitter @IHSEViews

Nas1
Posts: 46
Joined: Thu Sep 06, 2012 5:20 am

Re: Multi-step ahead forecast

Postby Nas1 » Wed Jan 29, 2014 3:18 pm

Thank you Gareth, May you please suggest why I am getting this coefmat for the same file that I uploaded??
Last edited by Nas1 on Wed Jun 25, 2014 7:12 am, edited 1 time in total.

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

Re: Multi-step ahead forecast

Postby EViews Gareth » Wed Jan 29, 2014 3:20 pm

Hard to say what you're doing wrong.
Follow us on Twitter @IHSEViews

Nas1
Posts: 46
Joined: Thu Sep 06, 2012 5:20 am

Re: Multi-step ahead forecast

Postby Nas1 » Wed Jan 29, 2014 3:27 pm

EViews Gareth wrote:Hard to say what you're doing wrong.


I tried the codes on my original working file and I got the same zero coefmat. Do you think there is something wrong in the codes?? do you think that this an indication for a bad quality for the results?

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

Re: Multi-step ahead forecast

Postby EViews Gareth » Wed Jan 29, 2014 3:28 pm

The code I have (which is the code you last posted, but changing the number of coefficients to 7) doesn't give zeros, and appears to work fine.

Code: Select all


' set window size
!window = 142

' set step size

' declare equation for estimation
equation eq01

' get size of workfile
!length = @obsrange

%cmnd = _this.@command 'EDIT: get the equation specification stored in eviews

!step = 4

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

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

'series to store forecast estimates
series fcast

'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-1)
smpl {%first} {%last}

' estimate equation -

!maxerr = @maxerrcount
setmaxerrs !maxerr+1
_this.{%cmnd} 'estimated equation


colplace(coefmat,eq01.@coefs,!j) 'store coefficients

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

if @dtoo(%end) < @dtoo(%4pere) then 'check whether the forecast end point is greater than the workfile end point
exitloop
endif

' set smpl for forecasting period
smpl {%4pers} {%4pere}

' forecast with command *forecast* (see also *fit*)
eq01.forecast(f=na) yf

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

' store forecasts
fcast = yf
next


smpl @all
show coefmat
show fcast.line

d(noerr) yf

'calculate RMSE
scalar rmse=@rmse(y, fcast)

' plot actual and recursive forecasts
graph graph1.line y fcast

graph1.addtext(t) forecast

show graph1
Follow us on Twitter @IHSEViews

Nas1
Posts: 46
Joined: Thu Sep 06, 2012 5:20 am

Re: Multi-step ahead forecast

Postby Nas1 » Wed Jan 29, 2014 3:50 pm

thank you Gareth for your support, i will re-examine everything again, at least the codes are correct :)

Nas1
Posts: 46
Joined: Thu Sep 06, 2012 5:20 am

Re: Multi-step ahead forecast

Postby Nas1 » Mon Feb 03, 2014 3:20 pm

Dear Gareth,
while I am running the same code discussed above, when I identify an AR(p) process, similar to Hamilton Markov switching model, the AR(p) process change automatically from the list of non-switching regressors to switching regressor. why this is happening?


best regards,




'run rolling regression

' set window size
!window = 60

' set step size

' declare equation for estimation
equation eq01

' get size of workfile
!length = @obsrange

%cmnd = _this.@command 'EDIT: get the equation specification stored in eviews

!step = 1

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

'matrix to store coefficient estimates
matrix(19,!nrolls) coefmat ' where 9 is the number of coefficients ( for each (variable+ constant)* number of regimes + probability regressor)

'series to store forecast estimates
series fcast

'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-1)
smpl {%first} {%last}

' estimate equation -

!maxerr = @maxerrcount
setmaxerrs !maxerr+1
_this.{%cmnd} 'estimated equation


colplace(coefmat,eq01.@coefs,!j) 'store coefficients

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

if @dtoo(%end) < @dtoo(%4pere) then 'check whether the forecast end point is greater than the workfile end point
exitloop
endif

' set smpl for forecasting period
smpl {%4pers} {%4pere}

' forecast with command *forecast* (see also *fit*)
eq01.forecast(f=na) yf

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

' store forecasts
fcast = yf
next


smpl @all
show coefmat
show fcast.line

d(noerr) yf


'calculate RMSE
scalar rmse=@rmse(y, fcast)


' plot actual and recursive forecasts
graph graph1.line y fcast

graph1.addtext(t) forecast

show graph1
Last edited by Nas1 on Wed Jun 25, 2014 7:11 am, edited 1 time in total.

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

Re: Multi-step ahead forecast

Postby EViews Gareth » Mon Feb 03, 2014 3:43 pm

That's a bug in EViews. Stay tuned for the next patch.
Follow us on Twitter @IHSEViews

Nas1
Posts: 46
Joined: Thu Sep 06, 2012 5:20 am

Re: Multi-step ahead forecast

Postby Nas1 » Mon Feb 10, 2014 3:14 pm

Dear Gareth,in the previous code I used the following command for calculating the RMSE,

scalar rmse=@rmse(y, fcast)

is this command correctly used ?? I am getting a very low RMSE that prompt me to ask this question.

best regards

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

Re: Multi-step ahead forecast

Postby EViews Gareth » Mon Feb 10, 2014 3:21 pm

Yep.
Follow us on Twitter @IHSEViews

Nas1
Posts: 46
Joined: Thu Sep 06, 2012 5:20 am

Re: Multi-step ahead forecast

Postby Nas1 » Mon Feb 10, 2014 3:32 pm

thank you for your quick answer.

Nicole
Posts: 22
Joined: Thu Jul 17, 2014 12:34 pm

Re: Multi-step ahead forecast

Postby Nicole » Thu Jul 17, 2014 12:52 pm

Hi,

I am trying to do a GARCH forecast with a 21-day rolling window, but I am new to eviews and I am constantly getting errors, like "!step not defined" or "!nrolls not defined".
I am immitating the codes posted on this forum, but I seem to be doing something wrong. My codes are given below:


' set window size
!window = 1777

' get size of workfile
!length = @obsrange

' declare equation for estimation
equation eq1

' set step size
!step = 1

'calculate number of rolls
!nrolls = @floor((!length-!window)/!step) (Here I get my errors so I do not proceed any further)


What might I be doing wrong? I have uploaded my workefile as an attachement.

I am also wondering how one can impose restrictions as aplha=0 and beta=0 when estimating GARCH(1.1) in the drop down windows (not using commands)

Appreciate all the help I can get! :)
Attachments
WTI data with IV (eviews).xlsx
(195.15 KiB) Downloaded 306 times

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

Re: Multi-step ahead forecast

Postby EViews Gareth » Thu Jul 17, 2014 1:14 pm

How did you try to run the program?

There is no way to impose those restrictions.
Follow us on Twitter @IHSEViews

Nicole
Posts: 22
Joined: Thu Jul 17, 2014 12:34 pm

Re: Multi-step ahead forecast

Postby Nicole » Fri Jul 18, 2014 5:42 am

Hi Gareth,

Thank you for the quick reply.

I am relally new to eviews, and do not understand what you mean.. Yesterday I tried simply typing the code (did not load any add-in, just typed in the command field) but got the error "!step not defined". What do you mean when you say "how did you run the progam?" :oops:

Today I tried downloading the "roll add-in" and make the rolling window that way. However, when I look at the stored coefficients in "rollcoef_" I it contains only one number while the rest are N/A. What I don't understand when I use this add-in is where i estimate the size of my window. I want to forecast a one-step-ahead 21-day rolling window, but where do I spesify the window size? I have set:

Start date/obs = @first
Last date/obs =@last
Window size=1162 (roughly 2/3 of my data)
Step size=1 (one-step-ahead)

So how do I spesify that I want 21-days rolling?

I also keep getting the following error when using the add-in method; "invalid (or out of range) coefficient or matrix index 3). What does this mean?

Thank you for taking the time to help me! :)


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 38 guests