Simplify Rolling Forecast

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

vginn
Posts: 5
Joined: Sun Sep 19, 2010 11:05 am

Simplify Rolling Forecast

Postby vginn » Mon Jan 17, 2011 10:08 pm

I am trying to forecast a variable (gp) using different variables, including the AR model below. I am going to look at different steps of 1,3,9,and 12 for three different periods. This can be quite cumbersome and time consuming, but doable. I would appreciate it if someone could look over my code and let me know how I could shorten this process and put together a table that will show the RMSEs for each horizon and a graph that will combine all other graphs.

If you have any other suggestions about how I could also simplify the process for other periods of out-of-sample forecasting and putting them all together, I would greatly appreciate it. Thank you for your help.

Code: Select all

' rolling forecast, re-estimating coefs ' for Eviews version 7 ' last updated 1/17/2011 ' fetch workfile wf chapter1 m 1983:1 2010:3 ' fill data series gp ' set window size !window = 24 ' get size of workfile !length = @obssmpl ' declare eqation for estimation equation eq1 ' declare series for final results series gphat ' point estimates series gphat_se ' forecast std.err. series gphat1 series gphat_se1 series gphat2 series gphat_se2 series gphat3 series gphat_se3 ' set step size to 1 !step = 1 ' move sample !step obs at a time for !i = 1 to !window+1-!step step !step ' set sample to estimation period smpl @first+96 @last-97 ' estimate equation eq1.LS DLOG(GP) C AR(1) AR(2) AR(3) AR(4) AR(5) AR(6) AR(7) AR(8) AR(9) AR(10) AR(11) AR(12) AR(13) AR(14) AR(15) ' reset sample to forecast period smpl @last-96+!i-1 @last-74+!i+!step-24 ' make forecasts in temporary series first eq1.forecast(f=na) tmp_gphat tmp_se ' copy data in current forecast sample gphat = tmp_gphat gphat_se = tmp_se next ' construct forecast confidence bounds ' approximate 95% interval assuming normal distribution smpl 2000:1 2004:12 series gphat_upp = gphat + 2.0*gphat_se series gphat_low = gphat - 2.0*gphat_se ' plot actual and rolling forecasts with confidence bounds graph graph1.line gp gphat gphat_upp gphat_low graph1.options size(8,2) linepat graph1.setelem(1) lcolor(blue) lpat(solid) legend(actual) graph1.setelem(2) lcolor(red) lpat(solid) legend(rolling forecast) graph1.setelem(3) lcolor(red) lpat(dash1) legend(95% bound) graph1.setelem(4) lcolor(red) lpat(dash1) legend() graph1.legend position(0,0) columns(1) graph1.addtext(t) 1-Step Ahead Rolling Forecast show @rmse(gp, gphat, "2003:1 2004:12") show graph1 ' set step size to 3 !step = 3 ' move sample !step obs at a time for !i = 1 to !window+1-!step step !step ' set sample to estimation period smpl @first+96 @last-97 ' estimate equation eq1.LS DLOG(GP) C AR(1) AR(2) AR(3) AR(4) AR(5) AR(6) AR(7) AR(8) AR(9) AR(10) AR(11) AR(12) AR(13) AR(14) AR(15) ' reset sample to forecast period smpl @last-96+!i-1 @last-74+!i+!step-24 ' make forecasts in temporary series first eq1.forecast(f=na) tmp_gphat1 tmp_se1 ' copy data in current forecast sample gphat1= tmp_gphat1 gphat_se1 = tmp_se1 next ' construct forecast confidence bounds ' approximate 95% interval assuming normal distribution smpl 2000:1 2004:12 series gphat_upp1 = gphat1 + 2.0*gphat_se1 series gphat_low1 = gphat1 - 2.0*gphat_se1 ' plot actual and rolling forecasts with confidence bounds graph graph2.line gp gphat1 gphat_upp1 gphat_low1 graph2.options size(8,2) linepat graph2.setelem(1) lcolor(blue) lpat(solid) legend(actual) graph2.setelem(2) lcolor(red) lpat(solid) legend(rolling forecast) graph2.setelem(3) lcolor(red) lpat(dash1) legend(95% bound) graph2.setelem(4) lcolor(red) lpat(dash1) legend() graph2.legend position(0,0) columns(1) graph2.addtext(t) 3-Step Ahead Rolling Forecast show @rmse(gp, gphat1, "2003:1 2004:12") show graph2 ' set step size to 9 !step = 9 ' move sample !step obs at a time for !i = 1 to !window+1-!step step !step ' set sample to estimation period smpl @first+96 @last-97 ' estimate equation eq1.LS DLOG(GP) C AR(1) AR(2) AR(3) AR(4) AR(5) AR(6) AR(7) AR(8) AR(9) AR(10) AR(11) AR(12) AR(13) AR(14) AR(15) ' reset sample to forecast period smpl @last-96+!i-1 @last-74+!i+!step-24 ' make forecasts in temporary series first eq1.forecast(f=na) tmp_gphat2 tmp_se2 ' copy data in current forecast sample gphat2= tmp_gphat2 gphat_se2 = tmp_se2 next ' construct forecast confidence bounds ' approximate 95% interval assuming normal distribution smpl 2000:1 2004:12 series gphat_upp2 = gphat2 + 2.0*gphat_se2 series gphat_low2 = gphat2 - 2.0*gphat_se2 ' plot actual and rolling forecasts with confidence bounds graph graph3.line gp gphat2 gphat_upp2 gphat_low2 graph3.options size(8,2) linepat graph3.setelem(1) lcolor(blue) lpat(solid) legend(actual) graph3.setelem(2) lcolor(red) lpat(solid) legend(rolling forecast) graph3.setelem(3) lcolor(red) lpat(dash1) legend(95% bound) graph3.setelem(4) lcolor(red) lpat(dash1) legend() graph3.legend position(0,0) columns(1) graph3.addtext(t) 9-Step Ahead Rolling Forecast show @rmse(gp, gphat2, "2003:1 2004:12") show graph3 ' set step size to 12 !step = 12 ' move sample !step obs at a time for !i = 1 to !window+1-!step step !step ' set sample to estimation period smpl @first+96 @last-97 ' estimate equation eq1.LS DLOG(GP) C AR(1) AR(2) AR(3) AR(4) AR(5) AR(6) AR(7) AR(8) AR(9) AR(10) AR(11) AR(12) AR(13) AR(14) AR(15) ' reset sample to forecast period smpl @last-96+!i-1 @last-74+!i+!step-24 ' make forecasts in temporary series first eq1.forecast(f=na) tmp_gphat3 tmp_se3 ' copy data in current forecast sample gphat3 = tmp_gphat3 gphat_se3 = tmp_se3 next ' construct forecast confidence bounds ' approximate 95% interval assuming normal distribution smpl 2000:1 2004:12 series gphat_upp3 = gphat3 + 2.0*gphat_se3 series gphat_low3 = gphat3 - 2.0*gphat_se3 ' plot actual and rolling forecasts with confidence bounds graph graph4.line gp gphat3 gphat_upp3 gphat_low3 graph4.options size(8,2) linepat graph4.setelem(1) lcolor(blue) lpat(solid) legend(actual) graph4.setelem(2) lcolor(red) lpat(solid) legend(rolling forecast) graph4.setelem(3) lcolor(red) lpat(dash1) legend(95% bound) graph4.setelem(4) lcolor(red) lpat(dash1) legend() graph4.legend position(0,0) columns(1) graph4.addtext(t) 12-Step Ahead Rolling Forecast show @rmse(gp, gphat3, "2003:1 2004:12") show graph4

vginn
Posts: 5
Joined: Sun Sep 19, 2010 11:05 am

Re: Simplify Rolling Forecast

Postby vginn » Wed Jan 19, 2011 11:42 am

Since I am new to this forum, is there a better approach for me to take to get answers for my question? I have posted before and never had any feedback and I am concerned that I will not get any feedback for this post. Please let me know how I can be more efficient in my questions that will allow for more effective feedback from others. Thank you.

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

Re: Simplify Rolling Forecast

Postby EViews Gareth » Wed Jan 19, 2011 11:51 am

I think this particular question is simply too complicated cumbersome for anyone to answer. You've essentially said "here's my 200 line program. Could someone please go through it line by line and make it "better"". I'd be surprised if anyone has any particular interest in doing so.

You might want to target your questions a little more. Something along the lines of "My program appears to be going slowly. I believe it is because of these 8 lines. Does anyone have any idea on how to make it faster".

vginn
Posts: 5
Joined: Sun Sep 19, 2010 11:05 am

Re: Simplify Rolling Forecast

Postby vginn » Wed Jan 19, 2011 12:07 pm

Thank you for the reply Gareth and I agree. What I would like to know specifically is how I can loop the steps more succinctly and input the RMSEs into a matrix. If this is still too broad, please let me know. I will keep trying until I get it right! :D

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

Re: Simplify Rolling Forecast

Postby EViews Gareth » Wed Jan 19, 2011 12:11 pm

Still too broad. Nobody is going to look through your 200 lines and figure out a way to make whatever loops are in there more "succinct" (whatever that means).


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest