Multi-step ahead forecast

For questions regarding programming in the EViews programming language.

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

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

Re: Multi-step ahead forecast

Postby EViews Gareth » 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.
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 10:24 am

Thank you so much Gareth, you are a lifesaver! I have been able to successfully run the program :)

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

Re: Multi-step ahead forecast

Postby Nicole » Wed Jul 30, 2014 5:40 am

Hi again,

I have further question regrding my forecasting using GARCH models.
I want to try to forecast over different time horizons (eg.1, 5, 21 and 252 days ahead). In order to do this I am using the program I specified in my previous post.
However, when using a rolling window of 1, I do not get the same results as I do when I am using the drop down menues. I am staring to wonder if I have completely misunderstood what I am doing :?

Do you mind explaining to me what eviews actualy does when I use the drop down menues (choosing static forecast), or how I should go about forecasting different time horizons?

I have attached the program I am using, when trying to forecast over 5 days.
As usally all help is much appreciated! :)

'set window size'
!window=4070
'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

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

Re: Multi-step ahead forecast

Postby EViews Gareth » Wed Jul 30, 2014 8:13 am

I'm not sure I understand what you're asking.
Follow us on Twitter @IHSEViews

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

Re: Multi-step ahead forecast

Postby Nicole » Wed Jul 30, 2014 8:29 am

Sorry for not being clear enough. Basically, I thought that when I was doing a static forecast from the drop down menu I was forecasting 1-step ahead, meaning that as I am using daily data I would be forecasting 1 day ahead..

However, when I tried to adjust the program I attached to my previous post for it to become a 1 day rolling window, my outcomes are completely different. Have I misunderstood what Eviews is doing in the drop down menu or is my program not doing what I want it to do (forecast over different horizons)?
Attachments
Untitled.jpg
The drop down menu
Untitled.jpg (160.52 KiB) Viewed 10976 times

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

Re: Multi-step ahead forecast

Postby EViews Gareth » Wed Jul 30, 2014 8:36 am

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


If I then open up eq01, hit the forecast button and select "static" as the forecast type, then open up the series returnsf and fcast, they're identical.
Follow us on Twitter @IHSEViews

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

Re: Multi-step ahead forecast

Postby Nicole » Wed Jul 30, 2014 9:09 am

I am sorry for being so slow, but I still don't get it right... :oops:
I still do not get the same results by trying the two methods and my RMSE and MAE end up being the exact same number when I am trying to use the commands.

create u 4966 (this number is the total number of observations)

series returns=nrnd
series x1=nrnd
equation eq01.arch returns c x1

'set window size'
!window=4070 (this is my in-sample period)
'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
%1pers=@otod(@dtoo(%start)+!i+!window-1) (%1pers because I am trying a 1-day ahead forecast)
%1pere=@otod(@dtoo(%start)+!i+!window+0)

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

' 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 4070 @last
Attachments
brent-b1_ice.wf1
Workfile
(450.65 KiB) Downloaded 287 times

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

Re: Multi-step ahead forecast

Postby EViews Gareth » Wed Jul 30, 2014 9:16 am

I get the same results.
Follow us on Twitter @IHSEViews

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

Re: Multi-step ahead forecast

Postby Nicole » Wed Jul 30, 2014 9:26 am

The same results by trying to use both methods (using my code)?
When doing it from the drop down menu I get RMSE=0.993259, MAE=0.797992
When I use the code RMSE=MAE=0.895579

Is there something wrng with my code? :?

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

Re: Multi-step ahead forecast

Postby Nicole » Thu Jul 31, 2014 1:47 am

Hi Gareth,

I am sorry to bother you, but I am really struggling to figure out what I am doing wrong.
For some reason my RMSE and MAE come out identical and both inconsistent with the results I get when using the drop down menu.
When I try the example you posted I seem to get it right, but when trying to apply it to my workfile it doesn't work :(

Could you please have a look at my code as I am unable to figure out what I am doing wrong?

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

Re: Multi-step ahead forecast

Postby EViews Gareth » Thu Jul 31, 2014 7:54 am

Let's ignore the RMSE and MAE for the moment. You said that the actual forecast series are different. Is that true?
Follow us on Twitter @IHSEViews

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

Re: Multi-step ahead forecast

Postby Nicole » Thu Jul 31, 2014 10:14 am

That is correct. Can this be caused by me using the rolling window?
I have attached a screen shot of my forecasts using the two approaches. ReturnsF is the one when I used the drop down menu, while Fcast is the one where I used the program.
Attachments
Screenshot (65).png
Screenshot (65).png (176.74 KiB) Viewed 10931 times

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

Re: Multi-step ahead forecast

Postby EViews Gareth » Thu Jul 31, 2014 10:27 am

Post the exact program you are using. Give precise details on exactly what you are doing when you generate the forecast.
Follow us on Twitter @IHSEViews

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

Re: Multi-step ahead forecast

Postby Nicole » Thu Jul 31, 2014 11:05 am

When using the dropdown menu I estimate the simple GARCH(1.1) model by including "returns c returns(-1)" in the mean equation and nothing in the variance equation. I estimate my in-sample for 2/1/1995 12/30/2009, which equals 4070 observations. Then I press forecast - static - forecast sample "12/31/2009-6/13/2014"-deselect the "insert actuals for out of sample".

When trying to conduct a 1-step ahead forecast (1 day as I am using daily data) I use the following program:

'set window size' (my in-sample window)
!window=4070
'get size of workfile'
!lenght=@obsrange
'declare equation for estimation' (this is a standard GARCH(1.1) with a constant and a lagged value in the mean equation, which i have named eq01)
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 (%1 because i want to forecast one day ahead)
%1pers=@otod(@dtoo(%start)+!i+!window-1)
%1pere=@otod(@dtoo(%start)+!i+!window+0)

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

' 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)

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

Re: Multi-step ahead forecast

Postby EViews Gareth » Thu Jul 31, 2014 11:15 am

You're missing some Next statements.
Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: Google [Bot] and 29 guests