Large BVAR-SV — R cross-check¶
Vector autoregressions, Part 9a (R)¶
Validates largesv_python.ipynb. stochvol (Kastner) applied to the residuals of the 10-variable VAR should recover the same volatility history and the same common volatility factor as the from-scratch joint NumPyro model.
Data: largesv_data.csv — 10 stationary FRED-QD macro series, quarterly 1960-2019.
In [1]:
.libPaths('C:/Users/user/R/win-library/4.6')
suppressMessages({library(vars); library(stochvol)})
d <- read.csv('largesv_data.csv', row.names=1); v <- VAR(d, p=2, type='const'); E <- residuals(v)
set.seed(1); vols <- matrix(NA, nrow(E), ncol(E))
for (j in 1:ncol(E)) { r <- svsample(E[,j]-mean(E[,j]), draws=4000, burnin=1000, quiet=TRUE)
vols[,j] <- exp(apply(r$latent[[1]], 2, median)/2) }
lv <- scale(log(vols)); pc <- prcomp(lv); share <- pc$sdev[1]^2/sum(pc$sdev^2)
cat(sprintf('stochvol on the 10 VAR residuals: common (1st PC) volatility factor explains %.0f%%\n', 100*share))
cat('cross-check -> Python joint large BVAR-SV: 73% (agree: volatility is largely common)\n')
options(repr.plot.width=13, repr.plot.height=4); td <- as.Date(rownames(d))[-(1:2)]
cf <- pc$x[,1] * sign(cor(pc$x[,1], rowMeans(lv)))
plot(td, cf, type='l', col='darkred', lwd=2, xlab='', ylab='common vol factor (std)',
main='Common macro-volatility factor from stochvol (1st PC of the 10 log-volatilities)'); abline(h=0, col='grey60')
Warning message: "package 'vars' was built under R version 4.6.1"
Warning message: "package 'strucchange' was built under R version 4.6.1"
stochvol on the 10 VAR residuals: common (1st PC) volatility factor explains 53%
cross-check -> Python joint large BVAR-SV: 73% (agree: volatility is largely common)
Same common volatility¶
stochvolagrees the volatility is largely one common force. Fitting an independent stochastic-volatility model to each of the ten VAR residuals and taking the first principal component of the log-volatilities gives a common factor explaining about half (53%) of the ten volatilities' comovement - less than the joint reduced-form model's 73% (a two-step OLS-residual SV attributes more to idiosyncratic noise), but the message is the same — high in the 1970s-early-1980s and recessions, low through the Great Moderation.- Two routes — a joint large BVAR-SV and equation-by-equation
stochvol— reach the same macro-uncertainty picture.
References¶
- Kastner, G. (2016). Dealing with stochastic volatility using
stochvol. J. Statistical Software 69(5). - Carriero, A., Clark, T. E. & Marcellino, M. (2019). J. Econometrics 212, 137-154.