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, bayes_spec = set_ssvs(), cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun"))
#> Call:
#> vhar_bayes(y = etf_train, num_chains = 2, num_iter = 20, bayes_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.7111   0.00356  -0.23538   1.4005   0.5242   0.377  -0.550  -0.626
#> 2    0.6241   0.03417  -0.12995   1.4909  -0.3586   0.449  -0.749  -0.841
#> 3    0.6142   0.17479   0.24270   0.6042   0.4286   0.645   0.323  -0.394
#> 4    0.4109   0.02641   0.53723   1.2111  -0.0232   0.320  -0.449  -0.420
#> 5    0.6222  -0.17643  -0.34837  -0.0556  -0.2778   0.379  -0.339  -0.672
#> 6    0.1518  -0.06113  -0.49744   0.0800   0.6765   0.262  -1.434  -0.897
#> 7    0.2580  -0.02949  -0.01048   0.1506   0.4941   0.597  -0.675  -0.277
#> 8   -0.1787  -0.14138  -0.12811  -0.5231  -0.5781   0.127  -0.373  -0.464
#> 9    0.0970   0.00117   0.00711   0.1189   0.5781   0.710   0.748  -0.186
#> 10   0.0558   0.03821   0.26387  -0.2719   0.7129   0.664  -1.296  -0.784
#> # ... 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, bayes_spec = set_horseshoe(), cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun"))
#> Call:
#> vhar_bayes(y = etf_train, num_chains = 2, num_iter = 20, bayes_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    1.9047   0.10675  -3.0428  -1.4967  13.881  -0.021  -1.7332  -0.3254
#> 2   -1.1849  -0.14683   0.0659   1.3729   4.433   1.027   1.4436  -0.2240
#> 3    0.5951   0.32890   1.0851  -1.8757   0.787   1.256   2.2909   0.3748
#> 4    0.9921   0.18626   0.2809  -0.6060   1.338   0.625  -0.0329   0.0596
#> 5   -0.0508  -0.13929  -0.1525  -0.0089   1.492   1.026  -0.1330  -0.0765
#> 6    0.7467  -0.00729   0.2119  -0.1068   1.244   0.853   0.4273  -0.1003
#> 7    0.3877   0.37317   0.0221   0.2599   0.787   0.794   0.2481  -0.0294
#> 8    0.2332   0.50406   0.1071   0.3790   0.644   0.924   0.0103  -0.0212
#> 9    0.0457  -0.12205   0.0303   0.1126   0.225   0.913   0.1012   0.1684
#> 10   0.0166   0.02253  -0.0299  -0.0358   0.229   0.903  -0.3036  -0.0316
#> # ... 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, bayes_spec = set_ng(), cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun"))
#> Call:
#> vhar_bayes(y = etf_train, num_chains = 2, num_iter = 20, bayes_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]
#> 1    0.16282  -0.001510  -0.02646  -1.02780   0.5815  -0.0183  -0.004602
#> 2    0.27451   0.008656   0.01154   0.21912   0.3532   0.6041  -0.001096
#> 3    0.07962  -0.009056  -0.08852  -0.20976   0.3575   0.5401   0.004027
#> 4    0.20349  -0.003115   0.16441  -0.18843   0.0525   0.3825   0.038894
#> 5    0.11482  -0.009128  -0.25878   0.28820  -0.2782   0.2964   0.010516
#> 6   -0.01976  -0.000144  -0.24067   0.06668   0.2959   0.2881   0.006220
#> 7   -0.00607   0.000302  -0.20520   0.13341   0.0121   0.5838   0.008863
#> 8    0.07834  -0.015244  -0.05813   0.22248  -0.2392   0.6203  -0.001102
#> 9    0.05004   0.003470  -0.02611   0.00133   0.0721   0.5530   0.000463
#> 10   0.14497   0.024345   0.00387  -0.00341  -0.2428   0.7579   0.000830
#>       phi[8]
#> 1   -0.18781
#> 2   -0.13008
#> 3   -0.14159
#> 4    0.01105
#> 5   -0.01520
#> 6   -0.13692
#> 7   -0.03704
#> 8   -0.05997
#> 9   -0.02026
#> 10   0.00428
#> # ... 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, bayes_spec = set_dl(), cov_spec = set_sv(), include_mean = FALSE, minnesota = "longrun"))
#> Call:
#> vhar_bayes(y = etf_train, num_chains = 2, num_iter = 20, bayes_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.66196  -3.37e-02   0.02690  -0.02595   1.1088  -4.55e-03   0.01696
#> 2    0.48403   4.42e-02  -0.03458   0.01613   0.0914  -5.42e-03   0.00626
#> 3    0.29808  -9.21e-02  -0.02248  -0.02748   0.1457  -1.38e-02   0.10091
#> 4    0.27450   1.92e-01  -0.02035  -0.01319  -0.2982   1.82e-02  -0.00349
#> 5   -0.04541   6.25e-02  -0.00833   0.01974  -0.2197  -1.30e-04  -0.00109
#> 6   -0.30669  -2.12e-05   0.00729   0.01402   0.7581   4.65e-05  -0.00389
#> 7    0.07643   5.67e-06  -0.01991  -0.01810   0.0871  -2.21e-06  -0.07152
#> 8   -0.03875   7.78e-05   0.01445  -0.00371  -0.0453   4.33e-06   0.07340
#> 9    0.00181   4.47e-05  -0.01553  -0.11883   0.7590  -3.83e-06   0.20148
#> 10   0.00215  -9.06e-04  -0.01055  -0.03061   0.7278   1.23e-04   0.02111
#>      phi[8]
#> 1    0.4839
#> 2    0.6876
#> 3    0.1069
#> 4   -0.0503
#> 5    0.0250
#> 6   -0.3637
#> 7   -0.0708
#> 8   -0.0946
#> 9   -0.0350
#> 10  -0.1484
#> # ... 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")