Forecast function with shocks
Posted: Tue Sep 17, 2019 2:59 pm
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
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