## Basic Rolling Regression

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

VictorV
Posts: 14
Joined: Thu May 24, 2012 6:16 am

### Re: Basic Rolling Regression

Here it is!

I found out that the coefficient matrix does give enough entries. With 372 obs and a window of 50 the coef matrix gives 322 entries.
So the only problems I have are with the fcast series.
Attachments
rollregr.wf1
(35.75 KiB) Downloaded 405 times

EViews Esther
EViews Developer
Posts: 149
Joined: Fri Sep 03, 2010 7:57 am

### Re: Basic Rolling Regression

I see that the spreadsheet for "fcast" presents its output from the 24th entry.
Attachments
rollregr.wf1
(35.71 KiB) Downloaded 361 times

VictorV
Posts: 14
Joined: Thu May 24, 2012 6:16 am

### Re: Basic Rolling Regression

So what do I do wrong? Here is a screenshot where you can clearly see the spreadsheet from the 13th entry
Attachments
PrintScreen.JPG (209.2 KiB) Viewed 17997 times

EViews Esther
EViews Developer
Posts: 149
Joined: Fri Sep 03, 2010 7:57 am

### Re: Basic Rolling Regression

Please delete the fcast series before running the program?

VictorV
Posts: 14
Joined: Thu May 24, 2012 6:16 am

### Re: Basic Rolling Regression

That should do it, I'm sorry for the inconvenience!

bebebe
Posts: 3
Joined: Fri Jun 22, 2012 6:41 pm

### Re: Basic Rolling Regression

Hi,

i am trying to do a GARCH (1,1) dynamic forecast, with a rolling window which overlaps. I have 1015 daily observations, and would like to use the past 500days data to forecast the variance for next 21 days. and this is then repeated by moving the window one day forward, such that the no. of days used in forecasting, and forecasted data have same length.

I am using eviews 5, have tried to replicate this using Esther's code for 4 step ahead rolling regression. However, i am getting zeros as my results.

Attached is the code which i have done so far and workfile.

Can someone pls shed some light on how to correct this pls?

Thank you very much.
Attachments
test 1.WF1
(42.28 KiB) Downloaded 305 times
thesis code 1.prg
(1.67 KiB) Downloaded 639 times

RouzbehR
Posts: 12
Joined: Fri Aug 03, 2012 12:12 pm

### Re: Basic Rolling Regression

Dear all,

I am doing a recursive regression modelling and I do not know how to fix the starting date so it does forecasting recursively and not rolling. And I need to know how I can put the first 10 years as the forecasting period. I have data from 1980(1) to 2011(12) and I need it to use 1980(1) to 1989(12) to forecast 1990(1) and so on.

I appreciate any help.

Best

doudou
Posts: 14
Joined: Thu Sep 06, 2012 9:22 am

### Re: Basic Rolling Regression

Hi Gareth,

I am new to eviews and forecasting thingy. My data ranges from 2001.01-2012.06 monthly data .
Since im using the usoil price at t to forecast exchange rate usdaud at t+1, equation I used is simple as usdaud c usoil, I have adjusted data accordingly, so it wud appear as usoil price at t to forecast exchange rate usdaud at t to avoid my confusion.
I want to use rolling window forecast use sample from 2001.01-2002.12 24 observations to forecast the 2003.01 and then include the 2003.01 in my sample as 2001.02-2003.01 to forecast 2003.02 until 2012.06.

Do I need to have the 2001.01-2012.06 monthly data x and y ready in the workfile to start with the forecasting?
What should I replace the " u 800" in your original code?

could you please help me check if the programme is correct?

I changed couple of things for my basic rolling forecast

Code: Select all

`'create some data where usdaud as y usoil as x and I am not sure what I shall replace for the below sentence u 800 as the name of my workfile questioningcreate u 800usdaud =nrndusoil =nrnd'-------------------------------------------------------------------------------------'run rolling regression' set window size 200101 to 200212 24 data to forecast 200301!window = 24' set step size as 200301 to 201206 9 years plus 6month gives 114!step = 114' get size of workfile!length = @obsrange' declare equation for estimationequation eq1'calculate number of rolls!nrolls = @round((!length-!window)/!step)'matrix to store coefficient estimatesmatrix(2,!nrolls) coefmat ' where 2 is the number of coefficients'variable keeping track of how many rolls we've done!j=0' move sample !step obs at a timefor !i = 1 to !length-!window+1-!step step !step!j=!j+1' set sample to estimation periodsmpl @first+!i-1 @first+!i+!window-2' estimate equation - where the equation is usdaud=c(1) + c(2)*usoil eq1.ls usdaud c usoil 'store coefficientscolplace(coefmat,eq1.@coefs,!j)nextshow coefmat`

Many thanks!!!!!!!!!!!!!!!!!!!
Attachments
forecast data.wf1
the original page indicates all orginal data ( log diff) , the f1 page is the data adjusted by me and ready to go...
(107.7 KiB) Downloaded 306 times
01 forecast.wf1
thats what my manually forecasted file look like.
(453.48 KiB) Downloaded 301 times

EViews Esther
EViews Developer
Posts: 149
Joined: Fri Sep 03, 2010 7:57 am

### Re: Basic Rolling Regression

Do I need to have the 2001.01-2012.06 monthly data x and y ready in the workfile to start with the forecasting?
What should I replace the " u 800" in your original code?
The following three lines will create an undated workfile (named UNTITLED) and generate random series usdaud and usoil.

Code: Select all

`create u 800 'will create undated workfile with 800 observationsusdaud = nrndusoil = nrnd`
Since you have your workfile (i.e. 01 FORECAST) with the monthly data, these lines can be ignored.

I want to use rolling window forecast use sample from 2001.01-2002.12 24 observations to forecast the 2003.01 and then include the 2003.01 in my sample as 2001.02-2003.01 to forecast 2003.02 until 2012.06.
Since you are trying to do 1-period ahead forecast, the following lines should be included in your code.

Code: Select all

`' 1-period-ahead forecast   %1pers = @otod(@dtoo(%start)+!i+!window-1)   'start point   %1pere = @otod(@dtoo(%start)+!i+!window)      'end point`
*Please note that the previous discussion has the 4-period-ahead-forecast example.

In your example, each roll would be specified as
2001/01 - 2002/12
2001/02 - 2003/01
....
The window size is 24 because each roll has 24 observations, and therefore

Code: Select all

`' set window size 200101 to 200212 24 data to forecast 200301!window = 24`
The step size should tell how many observations to step over between each iteration of the roll.
Since the difference between 2001/01 and 2001/02 is "1", the step size should be fixed to be 1.

Code: Select all

`' set step size as 1!step = 1`

doudou
Posts: 14
Joined: Thu Sep 06, 2012 9:22 am

### Re: Basic Rolling Regression

Hi Esther,

Many thanks for your correction.

Please see below as I tidy up the whole code:

Code: Select all

`'run rolling regression' 1-period-ahead forecast%1pers = @otod(@dtoo(%start)+!i+!window-1) 'start point%1pere = @otod(@dtoo(%start)+!i+!window) 'end point' set window size 200101 to 200212 24 data to forecast 200301!window = 24' set step size as 1!step = 1' get size of workfile!length = @obsrange' declare equation for estimationequation eq1'calculate number of rolls!nrolls = @round((!length-!window)/!step)'matrix to store coefficient estimatesmatrix(2,!nrolls) coefmat ' where 2 is the number of coefficients'variable keeping track of how many rolls we've done!j=0' move sample !step obs at a timefor !i = 1 to !length-!window+1-!step step !step!j=!j+1' set sample to estimation periodsmpl @first+!i-1 @first+!i+!window-2' estimate equation - where the equation is usdaud=c(1) + c(2)*usoil eq1.ls usdaud c usoil 'store coefficientscolplace(coefmat,eq1.@coefs,!j)nextshow coefmat`

Please let me know if there is anything else I need to correct? felt i ask so low level questions

EViews Esther
EViews Developer
Posts: 149
Joined: Fri Sep 03, 2010 7:57 am

### Re: Basic Rolling Regression

Code: Select all

`'run rolling regression' set window size!window = 24' set step size!step = 1' get size of workfile!length = @obsrange' declare equation for estimationequation eq1'calculate number of rolls!nrolls = @floor((!length-!window)/!step)'matrix to store coefficient estimatesmatrix(2,!nrolls) coefmat ' where 2 is the number of coefficients'series to store forecast estimatesseries fcast'*EDITED: 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 timefor !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 - where the equation is P =c(1) + c(2)*P1(-1)   eq1.ls usdaud c usoil      ' store coefficients   colplace(coefmat,eq1.@coefs,!j)      ' 1-period-ahead forecast   %1pers = @otod(@dtoo(%start)+!i+!window-1)        %1pere = @otod(@dtoo(%start)+!i+!window)        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 {%1pers} {%1pere}         ' forecast with command *forecast* (see also *fit*)   eq1.forecast(f=na) yf            ' set sampl to obtain the 4th period observation   smpl {%1pere} {%1pere}        ' store forecasts   fcast = yfnextsmpl @allshow coefmatshow fcast.lined(noerr) yf`

doudou
Posts: 14
Joined: Thu Sep 06, 2012 9:22 am

### Re: Basic Rolling Regression

EViews Esther wrote:

Code: Select all

`'run rolling regression' set window size!window = 24' set step size!step = 1' get size of workfile!length = @obsrange' declare equation for estimationequation eq1'calculate number of rolls!nrolls = @floor((!length-!window)/!step)'matrix to store coefficient estimatesmatrix(2,!nrolls) coefmat ' where 2 is the number of coefficients'series to store forecast estimatesseries fcast'*EDITED: 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 timefor !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 - where the equation is P =c(1) + c(2)*P1(-1)   eq1.ls usdaud c usoil      ' store coefficients   colplace(coefmat,eq1.@coefs,!j)      ' 1-period-ahead forecast   %1pers = @otod(@dtoo(%start)+!i+!window-1)        %1pere = @otod(@dtoo(%start)+!i+!window)        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 {%1pers} {%1pere}         ' forecast with command *forecast* (see also *fit*)   eq1.forecast(f=na) yf            ' set sampl to obtain the 4th period observation   smpl {%1pere} {%1pere}        ' store forecasts   fcast = yfnextsmpl @allshow coefmatshow fcast.lined(noerr) yf`

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

Before you said it cos mine is 1 period 1 period forecasting... i dnt understand why there is a 4th period ?
Please could you explain? thanks

doudou
Posts: 14
Joined: Thu Sep 06, 2012 9:22 am

### Re: Basic Rolling Regression

Hi Esther,

I ran this programe but says error
Please see screen shot.
Attachments
Untitled.png (3.44 KiB) Viewed 17737 times

EViews Esther
EViews Developer
Posts: 149
Joined: Fri Sep 03, 2010 7:57 am

### Re: Basic Rolling Regression

Please change the line

Code: Select all

`if @dtoo(%end) < @dtoo(%4pere) then`
to

Code: Select all

`if @dtoo(%end) < @dtoo(%1pere) then`

doudou
Posts: 14
Joined: Thu Sep 06, 2012 9:22 am

### Re: Basic Rolling Regression

Hi Esther,

Many thanks for the help with the code, it works!!!!

You know if you manually forecast 1 period, the fcast graph showed on eviews have information contains " RMSE" and

What should I change if I want to store the RMSE information?

Thanks!

Return to “Program Repository”

### Who is online

Users browsing this forum: No registered users and 1 guest