## Basic Rolling Regression

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

mjfl
Posts: 49
Joined: Mon Jul 18, 2011 8:18 am

### Re: Basic Rolling Regression

Code: Select all

`'create some datacreate u 100series y=nrndseries x1=nrndseries x2=nrndseries z=nrnd'-------------------------------------------------------------------------------------'run rolling regression' set window size!window = 20' 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(3,!nrolls) coefmat ' where 3 is the number of coefficients'series to store forecast estimatesseries fcast'redundant series for catching start and end pointsseries 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 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 y=c(1) + c(2)*x1 + c(3)*x2   eq1.ls y c x1 x2      ' store coefficients   colplace(coefmat,eq1.@coefs,!j)      ' 4-period-ahead forecast   %4pers = @otod(@dtoo(%start)+!i+!window-1)      'start point   %4pere = @otod(@dtoo(%start)+!i+!window+2)   'end point: %4pere - %4pers +1 = 4   if {%end} < {%4pere} then   'check whether the forecast end point is greater than the workfile end point      return   endif      ' set smpl for forecasting period   smpl {%4pers} {%4pere}         ' forecast with command *forecast* (see also *fit*)   eq1.forecast(f=na) yf            ' set sampl to obtain the 4th period observation   smpl {%4pere} {%4pere}         ' store forecasts   fcast = yfnextsmpl @allshow coefmatshow fcast.lined(noerr) serEViews Esther EViews Developer Posts: 39Joined: Fri Sep 03, 2010 7:57 amTop`

hi im getting invalis reurn on "REturn". is there something worng with my eviews7?

Jelmer
Posts: 1
Joined: Wed Jul 20, 2011 8:36 am

### Re: Basic Rolling Regression

Hi,

I have been trying to create my own rolling window using the example from Esther.
My data = (Range 1980M01 - 2011M06, Window 60M)

However, some series have only got 10 years data, which leaves the first samples with only NA-observations. I get an error, but I would like to see NA in the matrix if there are not enough observations. Alternatively a dynamic range based on the first observation. How do I do this?

Second, I couldnt figure out the command "ifirst" in: %start = @otod(@ifirst(ser))

Third, is there a way to grab the probability from a ls regression. @coefs, @tstats. But what about prob?

Jelmer

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

### Re: Basic Rolling Regression

It might be best to just run the program with maximum errors set to something high. That might just do what you want.

fariz888
Posts: 4
Joined: Mon Aug 08, 2011 4:18 pm

### Re: Basic Rolling Regression

Dear users,

I m recently doing my dissertation and faced with problem in estimation basic rolling GARCh (1,1) process. I have 2500 observation and need to forecast 1 day ahead volatility in rolling form. I will highly appreciate if advanced users provide me assistance in that issue.. I looked guideline but there was no information. In addition I have 6 day remaining to finish my dissertation. So I need your help immediately. Please share any knowledge that you have in that issue

In addition how can I estimate AGARCH in eviews? Iwant to capture asymmetry in time series? ( not by the method of EGARCH and GJR GARCH)
Sincerely

Fariz

Thanks all

Posts: 12
Joined: Mon Sep 05, 2011 7:43 pm

### Re: Basic Rolling Regression

Hi all,
I have same question as above

My forecasting equation is: Exchange rate=a_1+a_2*inflation+a_3*outputgap+a_4*real exchange rate+a5*interest rate differential

I want to run the out-of sample forecasting test with both rolling window forecasting scheme and recursive window forecasting scheme.
I have monthly data for all the variables from 1999m01 to 2011m04. And I want to set to estimation rolling window with 96 months from 199901 to 2006m12 and the evaluation window from 2007m01 to 2011mo4.
I want to evaluate the model for every time adding a new observation( one month ahead) by the mean squared prediction error of the linear model compare to the mean squared prediction error of the random walk model (y_t=error_t)

Please can anyone help me with the program code?

Thanks very much.

Dongya

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

### Re: Basic Rolling Regression

What have you done so far?

Posts: 12
Joined: Mon Sep 05, 2011 7:43 pm

### Re: Basic Rolling Regression

EViews Gareth wrote:What have you done so far?

Hi,

To be honest, I haven't done much. . I am totally new to programming.
But, I have run the test of forecasting equation with data from 1999m1 to 200612.
I have also tried to change the Esther's code to fit my work, but, it didn't work.

I would be thankful if you can show me how to program the code.

Dongya

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

### Re: Basic Rolling Regression

Your best bet is to read through the programming guides here on the forum, and in the manuals, until you're at a point where you can understand Esther's code, and then modify it to your needs. We'll be happy to help with any specific bugs you encounter along the way.

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

### Re: Basic Rolling Regression

I'm having some difficulty trying to apply the 4-period-ahead forecasts, based on LS equation. I coppied the whole code and made only 2 adjustments.
My original series is a monthly stock price index from 1980m01 - 2010m12 (372 obs). The equation I want to forecast is just "P c P(-1)". Therefore the only adjustments I made were the equation deffinition(P c P(-1) instead of y c x1 x2) and the number of coefficients of the coefficent matrix (2 instead of 3).

When running the code below I get the following error:
Syntax error in "IF 2002M07 < 2002 M11 THEN"

Code: Select all

`'run rolling regression' set window size!window = 20' 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'redundant series for catching start and end pointsseries 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 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 P c P(-1)      ' store coefficients   colplace(coefmat,eq1.@coefs,!j)      ' 4-period-ahead forecast   %4pers = @otod(@dtoo(%start)+!i+!window-1)      'start point   %4pere = @otod(@dtoo(%start)+!i+!window+2)   'end point: %4pere - %4pers +1 = 4   if {%end} < {%4pere} then   'check whether the forecast end point is greater than the workfile end point      return   endif      ' set smpl for forecasting period   smpl {%4pers} {%4pere}         ' forecast with command *forecast* (see also *fit*)   eq1.forecast(f=na) yf            ' set sampl to obtain the 4th period observation   smpl {%4pere} {%4pere}         ' store forecasts   fcast = yfnextsmpl @allshow coefmatshow fcast.lined(noerr) ser`

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

### Re: Basic Rolling Regression

Please note that there are some changes in the program (see *EDITED). I believe that it should work.

Code: Select all

`'run rolling regression' set window size!window = 20' 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 P c P(-1)      ' store coefficients   colplace(coefmat,eq1.@coefs,!j)      ' 4-period-ahead forecast   %4pers = @otod(@dtoo(%start)+!i+!window-1)      'start point   %4pere = @otod(@dtoo(%start)+!i+!window+2)      'end point: %4pere - %4pers +1 = 4   '*EDITED  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*)   eq1.forecast(f=na) yf            ' set sampl to obtain the 4th period observation   smpl {%4pere} {%4pere}        ' store forecasts   fcast = yfnextsmpl @allshow coefmatshow fcast.lined(noerr) yf`

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

### Re: Basic Rolling Regression

Thanks!!!

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

### Re: Basic Rolling Regression

Dear Esther,

I have one more question regarding your forecasting model. If I would now like to use a 1-period-ahead forecast rolling regression only, could I simply change the '+2' in '-1' in the following code:

%4pers = @otod(@dtoo(%start)+!i+!window-1) 'start point
%4pere = @otod(@dtoo(%start)+!i+!window+2) 'end point: %4pere - %4pers +1 = 4

I was wondering if I did this if most of your code then would be redundant or if this would indeed be the correct way to model a 1-period-ahead forecast.

Forgive me if this is a rather 'stupid' question but I am new to programming in Eviews.

Thank you

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

### Re: Basic Rolling Regression

The difference between start (%1pers) and end (%1pere) points should be 1 so that you can write the program as follows:

Code: Select all

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

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

### Re: Basic Rolling Regression

Dear Esther,

I had another look at 4-period-ahead forecast code you helped me with but I think it is still not correct.
When running the rolling regression with a window of 20, the spreadsheet gives output from the 13th entry. When adjusting the window this does not change and even with a window of a 100 the first 12 entries show "NA" en then the forecasted regression output is given. If I'm correct, in the case of a window of 20 and a 4-period-ahead forecast, the spreadsheet should give ouput from the 24th entry right? And in the case of a window of a 100 it should be from the 104th entry.

I'm deeply sorry for all these questions but I do not know anyone who could help me.

Thanks!

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

### Re: Basic Rolling Regression

VictorV wrote:If I'm correct, in the case of a window of 20 and a 4-period-ahead forecast, the spreadsheet should give ouput from the 24th entry right?
Yes, it is. Can you post your workfile?