Point ahead forecast + moving coefficients

For questions of any nature based on EViews 5 or earlier versions of EViews.

Moderators: EViews Gareth, EViews Moderator

Marc
Posts: 5
Joined: Wed May 09, 2012 2:25 am

Point ahead forecast + moving coefficients

Postby Marc » Fri May 11, 2012 6:37 pm

Dear Eview users

I am trying to get into eviews and especially what it can do in forecasting. I am trying to run a forecast for a known series ( ICI, 755 observations will be used for the forecast, the remainder of the 1254 observations will be used to judge the model ). It's quite simple what I am trying to do. I looked through the manual and found some code. I found this code below and understand most the code but I can't even get it to run, let alone evaluate it's correctness ( luckily I have matlab so if something is off, I can compare it )
I am Trying to construct Construct 1,2,3,4,5 ahead point forecasts for the sample period. Hence at each time T (T = 755, 756, . . . , 1254) I want to an forecast ICIT+h|T (h = 1, 2, 3, 4, 5), then I wan to re-estimate the AR(3) model repeatedly every 25 observations, 'using a 'moving 'window approach with a sample length of 755 observations of the ICI ( implied correlations index )

Any suggestions ? Is trying to solve it in this way even good ?

I also get an error saying @ifirst is an illegal or reserved name.

Perhaps you can help me or did something similar before and can show how you programmed this into this software.


Code: Select all

'DATA is already in the series file which contains the ICI

'Program description

' I am Trying to contruct Construct one-, two-, three-, four and
'five-step ahead point forecasts for the sample period. Hence at each time T (T = 755, 756, . . . , 1254) I want to an forecast ICIT+h|T (h = 1, 2, 3, 4, 5), then I wan to re-estimate the AR(3) model repeatedly every 25 observations, 'using a 'moving 'window approach with a sample length of 755 observations of the ICI ( implied correlations index )

'Date last modified 12/03/12 03:25 am

   '------------------------------------------------------------------------------------

    ' set window size
    !window = 25

    ' 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(4,!nrolls) coefmat ' where 4 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 AR(3) model
       eq1.ls ICI c AR(1) AR(2) AR(3)
       
       ' store coefficients
       colplace(coefmat,eq1.@coefs,!j)
       
       ' 5-period-ahead forecast
       %5pers = @otod(@dtoo(%start)+!i+!window-1)      'start point
       %5pere = @otod(@dtoo(%start)+!i+!window+2)   'end point: %5pere - %5pers +1 = 5
       if {%end} < {%5pere} then   'check whether the forecast end point is greater than the workfile end point
          return
       endif
       
       ' set smpl for forecasting period
       smpl {%5pers} {%5pere}   
       
       ' forecast with command *forecast* (see also *fit*)
       eq1.forecast(f=na) ICIf     
       
       ' set sampl to obtain the 5th period observation
       smpl {%5pere} {%5pere}   
       
       ' store forecasts
       fcast = ICIf
    next

    smpl @all
    show coefmat
    show fcast.line

    d(noerr) ser


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

Re: Point ahead forecast + moving coefficients

Postby EViews Gareth » Fri May 11, 2012 6:45 pm

@ifirst was introduced in EViews 7. If you're not using EViews 7, the code won't run. On the other hand if you know the start date and end date of your data, you can modify the lines that contain @ifirst and @ilast to put in the dates manually.
Follow us on Twitter @IHSEViews

Mo'
Posts: 10
Joined: Wed Aug 01, 2012 5:05 am

Re: Point ahead forecast + moving coefficients

Postby Mo' » Sun Aug 05, 2012 11:00 am

Hello eveyone,

I have looked through most of the relevant posts to help me piece together a code that carries out a 5-step ahead rolloing forecast(as I am relatively new in programmig with Eviews).
I tried runnung the program but I get the error message: Syntax error in "IF @LAST < 804 THEN". Below is my code.

Any comments would be appreciated.

Thanks in advance.


Code: Select all

' set window size
!window =800

' get size of workfile
!length = @obsrange

' declare equation for estimation
equation eq01
%cmnd = _this.@command 'EDIT: get the equation specification

' set step size
!step = 1

'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)

'matrix to store coefficient estimates
matrix(4,!nrolls) coefmat 'where the number of coefficients is 4.
series fcast  'series to store forecast estimates
series fcastse '
series fcastvar

%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 !length-!window+1-!step step !step
   !j = !j +1
   %first = @otod(@dtoo(%start)+!i-1)
   %last = @otod(@dtoo(%start)+!i+!window-2)
   smpl {%first} {%last}

   'estimate equation - Error catching , any errors mean we'll keep going.

   !maxerr = @maxerrcount
   setmaxerrs !maxerr+1   
   _this.{%cmnd}   'estimate equation
   if @lasterrnum>0 then
      clearerrs
   else
      colplace(coefmat,eq01.@coefs,!j) 'store coefficients     
   
       ' 5-period-ahead forecast
       %5pers = @otod(@dtoo(%start)+!i+!window-1)      'start point
       %5pere = @otod(@dtoo(%start)+!i+!window+2)   'end point: %5pere - %5pers +1 = 5
       if {%end} < {%5pere} then   'check whether the forecast end point is greater than the workfile end point
          return
       endif
       
       ' set smpl for forecasting period
       smpl {%5pers} {%5pere}   
     
      eq01.fit(f=na) r_f1 r_se r_var     
         
      ' store forecasts vars
      fcast = r_f1
      fcastse =  r_se
      fcastvar = r_var
   endif
next

smpl @all

Mo'
Posts: 10
Joined: Wed Aug 01, 2012 5:05 am

Re: Point ahead forecast + moving coefficients

Postby Mo' » Mon Aug 20, 2012 6:13 pm

Still stuck :(

EViews Glenn
EViews Developer
Posts: 2530
Joined: Wed Oct 15, 2008 9:17 am

Re: Point ahead forecast + moving coefficients

Postby EViews Glenn » Fri Aug 24, 2012 2:02 pm

The @last doesn't work in in a IF statement, only in a smpl statement.

There are lots of ways to find out whether an observation is greater than then end of the workfile. I will note thatby definition @last has to be within the workfile since it's part of a sample which has to be within the workfle. You can use information on the number of observations to set your condition.


Return to “EViews 5 and Earlier”

Who is online

Users browsing this forum: No registered users and 1 guest