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

Postby mjfl » Mon Jul 18, 2011 7:43 pm

Code: Select all

'create some data
create u 100

series y=nrnd
series x1=nrnd
series x2=nrnd
series z=nrnd

'-------------------------------------------------------------------------------------
'run rolling regression

' set window size
!window = 20

' 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(3,!nrolls) coefmat ' where 3 is the number of coefficients

'series to store forecast estimates
series fcast

'redundant series for catching start and end points
series 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 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 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 = yf
next

smpl @all
show coefmat
show fcast.line

d(noerr) ser


EViews Esther
EViews Developer
 
Posts: 39
Joined: 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

Postby Jelmer » Wed Jul 20, 2011 8:49 am

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: 12314
Joined: Tue Sep 16, 2008 5:38 pm

Re: Basic Rolling Regression

Postby EViews Gareth » Wed Jul 20, 2011 9:15 am

It might be best to just run the program with maximum errors set to something high. That might just do what you want.
Follow us on Twitter @IHSEViews

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

Re: Basic Rolling Regression

Postby fariz888 » Wed Aug 10, 2011 7:27 pm

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

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

Re: Basic Rolling Regression

Postby dongyadu » Thu Sep 15, 2011 7:26 am

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: 12314
Joined: Tue Sep 16, 2008 5:38 pm

Re: Basic Rolling Regression

Postby EViews Gareth » Thu Sep 15, 2011 7:52 am

What have you done so far?
Follow us on Twitter @IHSEViews

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

Re: Basic Rolling Regression

Postby dongyadu » Thu Sep 15, 2011 8:54 am

EViews Gareth wrote:What have you done so far?


Hi,
Many Thanks for the reply.

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: 12314
Joined: Tue Sep 16, 2008 5:38 pm

Re: Basic Rolling Regression

Postby EViews Gareth » Thu Sep 15, 2011 9:03 am

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.
Follow us on Twitter @IHSEViews

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

Re: Basic Rolling Regression

Postby VictorV » Tue May 29, 2012 7:06 am

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"

Could someone please help me out with this?

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

'redundant series for catching start and end points
series 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 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 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 = yf
next

smpl @all
show coefmat
show fcast.line

d(noerr) ser


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

Re: Basic Rolling Regression

Postby EViews Esther » Tue May 29, 2012 3:59 pm

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

smpl @all
show coefmat
show fcast.line

d(noerr) yf

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

Re: Basic Rolling Regression

Postby VictorV » Wed May 30, 2012 3:05 am

Thanks!!!

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

Re: Basic Rolling Regression

Postby VictorV » Wed May 30, 2012 4:11 am

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:

' 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

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

Postby EViews Esther » Wed May 30, 2012 8:06 am

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

Postby VictorV » Thu May 31, 2012 1:55 am

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

Postby EViews Esther » Thu May 31, 2012 8:14 am

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?


Return to “Program Repository”

Who is online

Users browsing this forum: No registered users and 4 guests