conditional forecasts from VAR via Kalman Filter and DLM

Questions and discussions on Vector Autoregressions
tclark
Posts: 99
Joined: Wed Nov 08, 2006 3:20 pm

conditional forecasts from VAR via Kalman Filter and DLM

Unread post by tclark »

Tom --

I expect the answer to this will be immediate to you. I am interested in using a Kalman Filter approach to getting conditional forecasts from a Bayesian VAR (replicating the forecasts that one could also get from the minimum-MSE approach of Doan, Litterman, and Sims (1984) that is embedded in condition.src), as outlined in this paper: https://dipot.ulb.ac.be/dspace/bitstrea ... tional.pdf.

The authors of this paper describe a general missing data approach and seem to indicate that, over the forecast horizon, the state variance innovation variance would be zero for all observations (missing or not). In a footnote on p.14, they reference an equivalent approach used in past work by some of the authors. In the past, I have coded up that equivalence approach and verified that it gives the same results for point forecasts and bands as does the min-MSE approach incorporated in condition.src.

My question relates to the appropriate specification of the measurement equation's error variance (SV) over the forecast horizon. In practice, in the way I have coded this up using DLM in the attached procedure, to get forecast confidence bands as wide as those I get based on the conditional forecasting approach included condition.src (holding parameter and Sigma estimates the same across efforts here), I need to specify the elements of SV to be 0 for those observations on y that are conditions and to be really diffuse for variable observations that do not correspond to conditions. If I instead set all elements of SV to 0 (or instead use NAs when I don't have conditions), I get confidence bands that are quite a bit narrower than I get with condition.src. It is hard for me to make complete sense of this because I can't see behind the scenes how DLM is dealing with missing data versus conditions over the forecast horizon. Is it in fact correct that, to replicate the min-MSE conditional forecasts of DLM using the KF, I need to set the SV matrix to be 0's everywhere except where I have a condition, at which point it should be extremely diffuse? Is it easy to explain why?

Many thanks for your help.
Attachments
conditforecastbyKF.src
procedure for conditional forecasting using Kalman Filter
(5.22 KiB) Downloaded 1034 times
Todd Clark
Economic Research Dept.
Federal Reserve Bank of Cleveland
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: conditional forecasts from VAR via Kalman Filter and DLM

Unread post by TomDoan »

It's actually Kalman smoothing, not Kalman filtering. (TYPE=CSIMULATE is a smoothing operation). DLM handles all the adjustment for partially missing observations by itself. The following does the same calculation as the CONDITION.RPF example. There's no SV in the model because all the uncertainty is loaded into the W's. The ugliest part of this is actually pulling out the (fully observable) state vector at FSTART-1 which requires rearranging the explanatory variables of the model at FSTART since the state vector is blocked by lag rather than variable.

Code: Select all

compute nlags=4
compute a=%modelcompanion(canmodel)
compute f=%identity(%nvar)~~%zeros(%rows(a)-%nvar,%nvar)
compute c=f
compute z=%xrow(%modelgetcoeffs(canmodel),%nreg)~%zeros(1,%rows(a)-%nvar)
compute fstart=2007:1,fend=2009:4
*
set grow5 fstart fend = %na
compute grow5(2007:4)=logusagdp(2006:4)+.05
compute grow5(2008:4)=logusagdp(2006:4)+.10
*
compute x00=%xsubvec(%eqnxvector(%modeleqn(canmodel,1),fstart),1,%nreg-1)
compute x0=%vec(tr(%vectorect(x00,nlags)))
dlm(a=a,f=f,z=z,sw=%sigma,c=c,x0=x0,y=||%na,%na,%na,%na,%na,grow5||,type=smooth) fstart fend xstates
tclark
Posts: 99
Joined: Wed Nov 08, 2006 3:20 pm

Re: conditional forecasts from VAR via Kalman Filter and DLM

Unread post by tclark »

Thanks, Tom. That's helpful, conceptually and for simplifying the code and calculations. I am able to get point forecasts from the Kalman-based approach that match up with what I get under the conditions/src/DLS approach. What I am having trouble matching up (now with code that aligns with what you sent) is the width of forecast distribution/confidence bands. Under the Kalman approach, using type=csimulate to do the smoothing and simulate shocks, I get confidence bands that are narrower than what I get with the DLS conditional approach (under which, for each MCMC draw of coefficients and Sigma, I draw shocks under the conditions, per some older version of the condition.src code, and produce simulated data over the forecast horizon). It seems as though, under the backward simulation/smoothing, I am not drawing shocks from a wide/large enough variance. That was part of why I tried making SV non-zero to get things to widen up to match what I have under the condition.src approach. Is there something else I should be doing to get the width of confidence bands to match up? (I should note that, in the DLS approach, my implementation does not follow the Waggoner-Zha method of taking the conditions into account in computing parameter estimates.) Thanks again.

Code: Select all

****************** calculations: loop over draws of coefs to form forecasts
do draws = 1,ndraws

 ** assign draws of coefficients to state space params
 comp %modelsetcoeffs(varmodel,pires(draws))         ;* assign coefs to defined VAR, for use below in computations
 comp amat = %modelcompanion(varmodel)               ;* companion form slope coefficients into coef matrix of state equation

 compute cmat = %identity(nvar)~~%zeros(%rows(amat)-nvar,nvar)
 compute zvec = %xrow(%modelgetcoeffs(varmodel),statedim+1)~%zeros(1,%rows(amat)-nvar)

 compute x00=%xsubvec(%eqnxvector(%modeleqn(varmodel,1),endpt+1),1,statedim)
 compute x0=%vec(tr(%vectorect(x00,lags)))

 ** now do simulation smoother to draw conditional forecasts
 dlm(c=cmat,a=amat,y=ystsp,sw=sigmares(draws),f=cmat,z=zvec,x0=x0,type=csimulate) endpt+1 endpt+fcper states
 
 ** now store forecasts
 do i = 1,nvar
  set forecastres(draws,i) endpt-(%calendar()(6)) endpt = y(i){0}   ;* back-fill the forecasts with actual data, for computation of 4Q or 12M averages of some variables
  set forecastres(draws,i) endpt+1 endpt+fcper = states(t)(i)
 end do i
 
end do draws
Todd Clark
Economic Research Dept.
Federal Reserve Bank of Cleveland
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: conditional forecasts from VAR via Kalman Filter and DLM

Unread post by TomDoan »

OK, I see what's happening. The Durbin-Koopman idea for doing the conditional simulation is still OK, but the second smoothing step needs to match the shape of the Y information that the first one used which it currently doesn't (it conditions on the whole Y, which with this model means that it zeros out the increment since SV is zero). The conditionally simulated draw can be done with something like:

Code: Select all

set grow5 fstart fend = %na
set simgrow5 fstart fend = %na
compute grow5(2007:4)=logusagdp(2006:4)+.05
compute grow5(2008:4)=logusagdp(2006:4)+.10
dlm(a=a,f=f,z=z,sw=%sigma,c=c,x0=x0,y=||%na,%na,%na,%na,%na,grow5||,type=smooth) fstart fend sstates
dlm(a=a,f=f,z=z,sw=%sigma,c=c,x0=x0,type=simulate) fstart fend simstates
compute simgrow5(2007:4)=simstates(2007:4)(6)
compute simgrow5(2008:4)=simstates(2008:4)(6)
dlm(a=a,f=f,z=z,sw=%sigma,c=c,x0=x0,y=||%na,%na,%na,%na,%na,simgrow5||,type=smooth) fstart fend simsmoothstates
do t=fstart,fend
   compute can(t)(draw)=sstates(t)(1)+simstates(t)(1)-simsmoothstates(t)(1)
end do t
so the second smoothing step conditions on the unconditionally simulated data at the same locations as the constraints. Then the conditionally simulated data are the original smoothed + the difference between the unconditional draw and the smoothed simulated draw.
tclark
Posts: 99
Joined: Wed Nov 08, 2006 3:20 pm

Re: conditional forecasts from VAR via Kalman Filter and DLM

Unread post by tclark »

Ok, thanks, Tom.
Todd Clark
Economic Research Dept.
Federal Reserve Bank of Cleveland
Post Reply