Stochastic Volatility Models

library(bvhar)
etf <- etf_vix[1:55, 1:3]
# Split-------------------------------
h <- 5
etf_eval <- divide_ts(etf, h)
etf_train <- etf_eval$train
etf_test <- etf_eval$test

Models with Stochastic Volatilities

By specifying cov_spec = set_sv(), var_bayes() and vhar_bayes() fits VAR-SV and VHAR-SV with shrinkage priors, respectively.

set_sv()
#> Model Specification for SV with Cholesky Prior
#> 
#> Parameters: Contemporaneous coefficients, State variance, Initial state
#> Prior: Cholesky
#> ========================================================
#> Setting for 'shape':
#> [1]  rep(3, dim)
#> 
#> Setting for 'scale':
#> [1]  rep(0.01, dim)
#> 
#> Setting for 'initial_mean':
#> [1]  rep(1, dim)
#> 
#> Setting for 'initial_prec':
#> [1]  0.1 * diag(dim)

SSVS

(fit_ssvs <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, coef_spec = set_ssvs(), cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun"))
#> Call:
#> vhar_bayes(y = etf_train, num_chains = 2, num_iter = 20, coef_spec = set_ssvs(), 
#>     cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun")
#> 
#> BVHAR with Stochastic Volatility
#> Fitted by Gibbs sampling
#> Number of chains: 2
#> Total number of iteration: 20
#> Number of burn-in: 10
#> ====================================================
#> 
#> Parameter Record:
#> # A draws_df: 10 iterations, 2 chains, and 177 variables
#>       phi[1]   phi[2]   phi[3]  phi[4]   phi[5]    phi[6]    phi[7]   phi[8]
#> 1    0.89831  -0.0598   0.0916  -1.865  -0.0828  -0.65925  -0.22286   1.6086
#> 2    0.11407   0.4634  -0.0177  -0.455  -0.0287  -0.70330   0.30113   1.1983
#> 3    0.40934   0.1782  -0.0727   0.293  -0.0828   0.14479  -2.33795  -0.0102
#> 4   -0.74241  -0.1366  -0.0390   0.228   0.3003  -0.39379  -0.43347  -0.0058
#> 5   -0.37297   0.1443  -0.0122   0.548   0.1616  -0.07647  -0.30578   0.1469
#> 6    0.50086  -0.3762   0.0158  -0.456   0.0902  -0.20554   0.29393   0.1053
#> 7   -0.00826  -0.0281   0.0223   0.626   0.1477  -0.00516   0.01021   0.3152
#> 8    0.00691   0.0454  -0.0528   0.852   0.0367  -0.03074   0.01977   0.2252
#> 9   -0.01061  -0.2206   0.1335   0.614  -0.0474  -0.04643  -0.09296   0.0145
#> 10  -0.04089   0.0248  -0.0169   0.531   0.0107   0.03038   0.00174   0.3850
#> # ... with 10 more draws, and 169 more variables
#> # ... hidden reserved variables {'.chain', '.iteration', '.draw'}

Horseshoe

(fit_hs <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, coef_spec = set_horseshoe(), cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun"))
#> Call:
#> vhar_bayes(y = etf_train, num_chains = 2, num_iter = 20, coef_spec = set_horseshoe(), 
#>     cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun")
#> 
#> BVHAR with Stochastic Volatility
#> Fitted by Gibbs sampling
#> Number of chains: 2
#> Total number of iteration: 20
#> Number of burn-in: 10
#> ====================================================
#> 
#> Parameter Record:
#> # A draws_df: 10 iterations, 2 chains, and 211 variables
#>      phi[1]   phi[2]   phi[3]   phi[4]     phi[5]    phi[6]   phi[7]   phi[8]
#> 1    0.2362   0.1463  -0.0517  -0.0742  -1.66e-03  -0.06187   0.1833   0.1611
#> 2    0.1831   0.1819  -0.1090   0.1610   8.89e-03  -0.00887   0.0232   0.1321
#> 3    0.2455   0.1286  -0.0703   0.1222  -8.73e-03  -0.05949  -0.1382   0.1039
#> 4    0.0963   0.1087  -0.1558   0.1166   5.65e-03   0.02191   0.1070   0.1130
#> 5    0.0372   0.1497  -0.1538   0.1946  -2.67e-03  -0.02359  -0.0237   0.2995
#> 6   -0.0573   0.1079  -0.2566   0.5879   7.73e-04   0.01944   0.0156   0.0960
#> 7    0.1053   0.0943  -0.1837   0.2004   1.80e-03   0.10304   0.0697   0.2996
#> 8    0.0232  -0.0412  -0.1501   0.3045  -2.18e-04  -0.13582   0.0191  -0.0158
#> 9    0.0504   0.1025  -0.1617   0.2406   9.16e-05   0.00157  -0.0346   0.2380
#> 10   0.0223   0.0831  -0.1558   0.1374  -1.42e-04  -0.01194   0.0992   0.1018
#> # ... with 10 more draws, and 203 more variables
#> # ... hidden reserved variables {'.chain', '.iteration', '.draw'}

Normal-Gamma prior

(fit_ng <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, coef_spec = set_ng(), cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun"))
#> Call:
#> vhar_bayes(y = etf_train, num_chains = 2, num_iter = 20, coef_spec = set_ng(), 
#>     cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun")
#> 
#> BVHAR with Stochastic Volatility
#> Fitted by Metropolis-within-Gibbs
#> Number of chains: 2
#> Total number of iteration: 20
#> Number of burn-in: 10
#> ====================================================
#> 
#> Parameter Record:
#> # A draws_df: 10 iterations, 2 chains, and 184 variables
#>       phi[1]    phi[2]    phi[3]   phi[4]   phi[5]    phi[6]   phi[7]  phi[8]
#> 1   -0.12129   0.46645   0.00633  -0.2542   0.0983  -0.12326   0.8472   1.195
#> 2   -0.06070  -0.03576   0.26003   0.3627  -0.0493   0.10581  -0.6588  -0.233
#> 3   -0.12030   0.09924   0.06952   0.6217   0.2413   0.20229  -0.3341   0.896
#> 4   -0.05398  -0.83427   0.32929  -0.7151   0.5682  -0.77103   1.8176   0.311
#> 5   -0.08097  -0.00469  -0.01688   1.0261  -0.0247   0.20556  -0.7039   0.113
#> 6   -0.09683   0.00503   0.00561   0.9219  -0.3035  -0.02819  -0.8611   0.264
#> 7   -0.04153   0.00751  -0.03171   0.8208   0.4102  -0.07181   0.0765   0.490
#> 8    0.00445  -0.18934   0.07037   0.4607   0.3786   0.07077   0.0405   0.923
#> 9   -0.00375   0.07738  -0.05003  -0.0199  -0.1697   0.08190  -0.0237   1.379
#> 10  -0.04228  -0.07593   0.11735  -0.0910   0.0161   0.00741  -0.0349   1.455
#> # ... with 10 more draws, and 176 more variables
#> # ... hidden reserved variables {'.chain', '.iteration', '.draw'}

Dirichlet-Laplace prior

(fit_dl <- vhar_bayes(etf_train, num_chains = 2, num_iter = 20, coef_spec = set_dl(), cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun"))
#> Call:
#> vhar_bayes(y = etf_train, num_chains = 2, num_iter = 20, coef_spec = set_dl(), 
#>     cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun")
#> 
#> BVHAR with Stochastic Volatility
#> Fitted by Gibbs sampling
#> Number of chains: 2
#> Total number of iteration: 20
#> Number of burn-in: 10
#> ====================================================
#> 
#> Parameter Record:
#> # A draws_df: 10 iterations, 2 chains, and 178 variables
#>       phi[1]    phi[2]     phi[3]    phi[4]    phi[5]    phi[6]   phi[7]
#> 1    0.16969  -0.24454  -0.126475  -0.06212  -0.00613   0.10133   0.2047
#> 2    0.13486  -0.04642  -0.148850   0.29445  -0.00510   0.03525   0.1231
#> 3    0.09879  -0.00417   0.012937   0.08343  -0.00992  -0.03586   0.0190
#> 4   -0.05609  -0.02515  -0.009510   0.27036  -0.04458  -0.00890  -0.0160
#> 5    0.00416   0.02970   0.007852  -0.08386  -0.01198  -0.13536   0.0647
#> 6   -0.00753  -0.13360  -0.053984   0.06215   0.01830   0.02951  -0.1006
#> 7    0.03670   0.06412  -0.129178  -0.00837   0.00700   0.06118   0.1877
#> 8    0.04795   0.01647  -0.091950   0.01753   0.02061   0.03345   0.4122
#> 9    0.00319   0.01126   0.000962   0.01404  -0.00825  -0.01743   0.3645
#> 10   0.04626  -0.09924   0.000798  -0.00658   0.02443   0.00132   0.3979
#>        phi[8]
#> 1    8.58e-05
#> 2   -8.17e-04
#> 3   -7.97e-04
#> 4    2.09e-03
#> 5    5.46e-03
#> 6    1.57e-02
#> 7    3.77e-01
#> 8    5.26e-01
#> 9    4.34e-01
#> 10   3.80e-01
#> # ... with 10 more draws, and 170 more variables
#> # ... hidden reserved variables {'.chain', '.iteration', '.draw'}

Bayesian visualization

autoplot() also provides Bayesian visualization. type = "trace" gives MCMC trace plot.

autoplot(fit_hs, type = "trace", regex_pars = "tau")

type = "dens" draws MCMC density plot.

autoplot(fit_hs, type = "dens", regex_pars = "tau")