Forecast function with shocks

Questions and discussions on Vector Autoregressions
lali62
Posts: 21
Joined: Wed Mar 22, 2017 7:04 pm

Forecast function with shocks

Unread post by lali62 »

Hi,
Could you tell me if I am understanding the output computation when a shocks variable is introduced in the forecast function correctly here:
https://estima.com/ratshelp/index.html? ... ction.html

SYSTEM(MODEL=var1)
VARIABLES v1 v2 v3 v4 v5
LAGS 1 TO 3
DET Constant
END(SYSTEM)
ESTIMATE(resids=varresids) 1985:01 2017:09

compute hstart = 2016:10
compute hend = 2017:09
forecast(paths,from=hstart,to=hend,model=var1,results=withoilshocks)
#oilshocks

where oilshocks is a 12 * 5 array of shocks series

now I am trying to understand if the following computation in R is what the forecast function does above

y <- data
var1<-reduced.form.var(y,p=3)
#intercept is a 1 * 5 array
intercept <- var1$intercept
#coefs are the coefficients without the intercept. It is a 15 * 5 array
coefs <- var1$coefs
# we reshape this coefs matrix into (nvar,nvar,nlag) for the below computation
nvar<-5
nlag<-3
dim(coefs)<-c(nvar,nvar,nlag)
capT<-nrow(y)
yhat<-rbind(y,matrix(0,ncol=nvar,nrow=nsteps))
nsteps<-12
uu=t(resid) %*% resid
nobs=length(resid)
Sh=uu/nobs
A0=t(chol(Sh))
# Compute the deterministic part of the forecasts (less the intercept!)
# Now loop over the forecast horizon
for(h in 1:nsteps)
{ yhat[capT + h, ] <- (yhat[capT + h - 1,] %*% coefs[,,1] + intercept + (shocks[h,]%*%A0))
if (p>1) {for(i in 2:p)
{ yhat[capT + h, ] <- (yhat[capT + h, ] + (yhat[capT + h - i, ] %*% coefs[,,i]))
}}
}
output <- yhat

withoilshocks<-tail(output,nsteps)

Is this above logic correct
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Forecast function with shocks

Unread post by TomDoan »

What's the origin of the "SHOCKS"?

This adjustment: (shocks[h,]%*%A0)

is multiplying the input shock matrix by the Cholesky factor of the residuals, so they are orthogonalized shocks. (Seems rather odd since the Cholesky factor isn't even known until you estimate the model).
lali62
Posts: 21
Joined: Wed Mar 22, 2017 7:04 pm

Re: Forecast function with shocks

Unread post by lali62 »

so should I just multiply them with the shocks instead

shocks are computed as:

compute bfactor = %decomp(%sigma)
compute identvector=||1.0,1.0,0.0,0.0,1.0||
compute oil=bfactor*%diag(identvector)*inv(bfactor)
dec vect[series] oilshocks(5)
do t=hstart,hend
compute %pt(oilshocks,t,oil*%xt(varresids,t))
end do t
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Forecast function with shocks

Unread post by TomDoan »

If what you're trying to do is to shut down the orthogonalized residuals for variables other than 1, 2 and 5, then that's correct.
Post Reply