Skip to contents
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.4921  -0.155  -0.7003   0.5784   2.905  0.5895  -0.9631  -0.1178
#> 2    0.4843  -0.275  -0.0562  -1.1777   1.058  0.9196  -1.1992   0.1966
#> 3   -0.4738  -0.921   0.5156   2.1713  -1.633  0.6157   0.3601   0.6358
#> 4    0.4932  -0.285   0.2012  -0.4185   0.499  0.0877  -0.0237  -0.3498
#> 5   -0.1393  -0.244   0.7644   0.2718   1.140  0.3975  -0.0663   0.2805
#> 6    0.4751  -0.315  -0.3293   0.6890  -0.862  0.6535   0.5109   0.3444
#> 7    0.2908  -0.103   0.0365  -0.0732   0.256  0.5757  -0.8235  -0.2397
#> 8    0.4008  -0.701   0.5792   0.3020  -0.898  0.0358  -1.4165  -0.4451
#> 9    0.1115  -0.230   0.3050   0.6406   0.459  0.4456  -1.3779  -0.6035
#> 10  -0.0969  -0.139   0.3943   1.4965  -0.423  0.7879  -0.6231   0.0967
#> # ... 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    0.783  -0.1638   0.1127  -0.259  -0.67255   0.928  -0.3763  -0.0126
#> 2    0.449   0.3458   0.0457   0.373   0.53879   1.227   0.5847   0.2117
#> 3    0.205  -0.0418   0.0563   0.354  -0.02180   1.478  -0.0977  -0.2921
#> 4    0.468  -0.1293  -0.0435   0.162  -0.36924   0.827   0.1697   0.3414
#> 5    0.230  -0.0739   0.2206  -0.289  -0.00185   0.823  -0.1138   0.2977
#> 6    0.622  -0.1946  -0.2517  -0.317  -0.00746   0.924  -0.0209  -0.2230
#> 7    0.206  -0.0369  -0.2124  -0.548   0.10582   0.929   0.3860   0.1759
#> 8    0.530  -0.2121  -0.0872  -0.332   0.05217   1.016   0.6429   0.2989
#> 9    0.151  -0.1150  -0.2478  -0.128   1.11925   0.983  -0.0842   0.0960
#> 10   0.313  -0.2547  -0.0561   0.125  -0.40390   0.809  -0.0928  -0.0338
#> # ... 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]    phi[8]
#> 1    0.746  -0.1474   0.0163   0.1608   0.6299   0.686  -0.1483   0.04892
#> 2    0.782  -0.1226   0.3099   0.1796  -0.0158   1.024  -0.0040   0.00892
#> 3    0.695  -0.3333   0.0883   0.1597  -1.5414   1.066   0.0455  -0.01154
#> 4    0.810  -0.2066   0.0136  -0.6759   0.3660   0.967   0.3618   0.06549
#> 5    0.444  -0.3046   0.0848   0.1412  -1.0565   1.536   0.9537   0.48068
#> 6    0.674  -0.1240  -0.3114   0.1216   0.3484   0.859  -0.7789  -0.13360
#> 7    0.729  -0.2027  -0.0335  -0.0959  -0.2526   1.196  -0.7062   0.10999
#> 8    0.347  -0.1764  -0.2712  -0.2650   0.7368   1.365  -0.2235   0.16534
#> 9    0.593  -0.1681  -0.0343   0.3555  -0.2289   1.066   0.2626   0.26957
#> 10   0.651  -0.0568   0.2706   0.1776   0.3047   1.600  -0.2297   0.38483
#> # ... 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]   phi[8]
#> 1    0.2142  -0.2022   0.15877  -0.515  -0.0402   0.281   0.0040   0.0972
#> 2    0.1566   0.3006  -0.29109   0.616   1.1516  -0.245   0.3503  -0.0500
#> 3    0.0925  -0.0598   0.50103   0.423  -0.6778   0.454  -0.1982  -0.5168
#> 4    0.6185  -0.0177   0.05708  -0.157  -0.3354   0.797  -0.3575   0.1071
#> 5   -0.2165   0.0272   0.04515   0.689  -0.2052   0.946   0.1012  -0.1717
#> 6    0.3853  -0.1334   0.20925   0.457  -0.3868   0.356  -0.0611   0.1293
#> 7    0.1007   0.0376   0.13787   0.284   0.1936   0.835  -0.2127  -0.1254
#> 8    0.3780  -0.1415   0.19086   0.519  -0.2368   0.499  -0.4758  -0.0641
#> 9    0.1879  -0.0606   0.00789   0.531   0.2823   0.761   0.2512   0.3007
#> 10   0.5111  -0.0577  -0.00401   0.412  -0.3087   1.039  -0.6937  -0.2520
#> # ... 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")