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