Question about out-of-sample forecast in state-space model

Discussion of State Space and Dynamic Stochastic General Equilibrium Models
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Question about out-of-sample forecast in state-space model

Unread post by fan »

Hi Tom,

I am trying to generate 1-year out-of-sample forecasts. However, I could not get the forecasts. I am not sure where I made mistakes. Could you please kindly check my codes?

Code: Select all

dlm(presample=ergodic,a=af,c=1.0,z=zf,MU=lineareq,f=1.0,sv=sv1,sw=sw1,y=ewrd,method=bfgs,vhat=vhat,svhat=svhat,type=filter) / xstates vstates
dlm(a=af,c=1.0,z=zf,MU=lineareq,f=1.0,sv=sv1,sw=sw1,x0=xstates(2007:12),sx0=vstates(2007:12),yhat=yhat,svhat=svhat) 2008:01 2010:12
set forecast 2008:01 2010:12 = %scalar(yhat)
set stderr 2008:01 2010:12 = sqrt(%scalar(svhat))
set lower 2008:01 2010:12 = forecast + %invnormal(0.25)*stderr
set upper 2008:01 2010:12 = forecast + %invnormal(0.75)*stderr
graph(footer="out-of-sample forecast with 50% CI") 4
# ewrd 1953:4 2007:12
# forecast / 2
# lower / 3
# upper / 3
Thank you
Attachments
forecast.docx
(20.3 KiB) Downloaded 734 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Question about out-of-sample forecast in state-space mod

Unread post by TomDoan »

Are ZF and LINEAREQ computable during the forecast period?
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: Question about out-of-sample forecast in state-space mod

Unread post by fan »

TomDoan wrote:Are ZF and LINEAREQ computable during the forecast period?
Dear Tom,

Thank you for your reply. I do not think ZF and LINEAREQ are not computable during the forecast period. Is there any way I could solve the problem? I attached my complete codes here, in case you need to see what I am doing here. Again, thank you for your help

Code: Select all

linreg vwrd
# constant term{1} default{1} dyield{1}
frml(lastreg,vector=b) lineareq vwrd

set du = %resids-%resids{1}
linreg du
# yr34 yr34{1}
compute theta1=%beta(1)
compute theta2=%beta(2)
compute se=sqrt(%seesq)
compute sn=sqrt(0.01*%seesq)

dec frml[symm] sw1 sv1 zf cf af

nonlin b alpha theta1 theta2=-alpha*theta1 se sn


frml af = ||alpha||
compute alpha = 0.7
frml zf = ||d1*yr34+d2*yr34{1}||
frml sw1 = ||sn^2||
frml sv1 = ||se^2||

dlm(presample=ergodic,a=af,c=1.0,z=zf,MU=lineareq,f=1.0,sv=sv1,sw=sw1,y=vwrd,method=bfgs,vhat=vhat,svhat=svhat,type=filter) / xstates vstates
dlm(a=af,c=1.0,z=zf,MU=lineareq,f=1.0,sv=sv1,sw=sw1,x0=xstates(2007:12),sx0=vstates(2007:12),yhat=yhat,svhat=svhat) 2008:01 2010:12
set forecast 2008:01 2010:12 = %scalar(yhat)
set stderr 2008:01 2010:12 = sqrt(%scalar(svhat))
set lower 2008:01 2010:12 = forecast + %invnormal(0.25)*stderr
set upper 2008:01 2010:12 = forecast + %invnormal(0.75)*stderr
graph(footer="out-of-sample forecast with 50% CI") 4
# vwrd 1953:4 2007:12

TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Question about out-of-sample forecast in state-space mod

Unread post by TomDoan »

Those use actual data. Are the data series they reference (term, default, dyield, yr34) defined through the forecast period?
Post Reply