Page **3** of **9**

### Re: Basic Rolling Regression

Posted: **Fri Jun 01, 2012 12:40 am**

by **VictorV**

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.

### Re: Basic Rolling Regression

Posted: **Fri Jun 01, 2012 9:32 am**

by **EViews Esther**

I see that the spreadsheet for "fcast" presents its output from the 24th entry.

### Re: Basic Rolling Regression

Posted: **Sun Jun 03, 2012 10:08 am**

by **VictorV**

So what do I do wrong? Here is a screenshot where you can clearly see the spreadsheet from the 13th entry

### Re: Basic Rolling Regression

Posted: **Mon Jun 04, 2012 8:43 am**

by **EViews Esther**

Please delete the fcast series before running the program?

### Re: Basic Rolling Regression

Posted: **Tue Jun 05, 2012 12:31 am**

by **VictorV**

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

### Re: Basic Rolling Regression

Posted: **Fri Jun 22, 2012 7:29 pm**

by **bebebe**

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.

### Re: Basic Rolling Regression

Posted: **Thu Aug 09, 2012 10:39 am**

by **RouzbehR**

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

### Re: Basic Rolling Regression

Posted: **Fri Sep 07, 2012 5:57 am**

by **doudou**

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 questioning`

create u 800

usdaud =nrnd

usoil =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 estimation

equation eq1

'calculate number of rolls

!nrolls = @round((!length-!window)/!step)

'matrix to store coefficient estimates

matrix(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 time

for !i = 1 to !length-!window+1-!step step !step

!j=!j+1

' set sample to estimation period

smpl @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 coefficients

colplace(coefmat,eq1.@coefs,!j)

next

show coefmat

Many thanks!!!!!!!!!!!!!!!!!!!

### Re: Basic Rolling Regression

Posted: **Fri Sep 07, 2012 9:13 am**

by **EViews Esther**

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 observations`

usdaud = nrnd

usoil = 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.

### Re: Basic Rolling Regression

Posted: **Fri Sep 07, 2012 11:54 am**

by **doudou**

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 estimation

equation eq1

'calculate number of rolls

!nrolls = @round((!length-!window)/!step)

'matrix to store coefficient estimates

matrix(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 time

for !i = 1 to !length-!window+1-!step step !step

!j=!j+1

' set sample to estimation period

smpl @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 coefficients

colplace(coefmat,eq1.@coefs,!j)

next

show coefmat

Please let me know if there is anything else I need to correct? felt

i ask so low level questions

### Re: Basic Rolling Regression

Posted: **Fri Sep 07, 2012 12:17 pm**

by **EViews Esther**

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 estimation

equation eq1

'calculate number of rolls

!nrolls = @floor((!length-!window)/!step)

'matrix to store coefficient estimates

matrix(2,!nrolls) coefmat ' where 2 is the number of coefficients

'series to store forecast estimates

series 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 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 - 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 = yf

next

smpl @all

show coefmat

show fcast.line

d(noerr) yf

### Re: Basic Rolling Regression

Posted: **Sat Sep 08, 2012 4:05 am**

by **doudou**

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 estimation

equation eq1

'calculate number of rolls

!nrolls = @floor((!length-!window)/!step)

'matrix to store coefficient estimates

matrix(2,!nrolls) coefmat ' where 2 is the number of coefficients

'series to store forecast estimates

series 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 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 - 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 = yf

next

smpl @all

show coefmat

show fcast.line

d(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

### Re: Basic Rolling Regression

Posted: **Sat Sep 08, 2012 10:06 am**

by **doudou**

Hi Esther,

I ran this programe but says error

Please see screen shot.

### Re: Basic Rolling Regression

Posted: **Mon Sep 10, 2012 9:48 am**

by **EViews Esther**

Please change the line

Code: Select all

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

to

Code: Select all

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

### Re: Basic Rolling Regression

Posted: **Wed Sep 12, 2012 3:10 am**

by **doudou**

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!