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.
- Three different prior for innovation covariance, and specify through
bayes_spec
- Minneosta prior
- BVAR:
set_bvar()
- BVHAR:
set_bvhar()
andset_weight_bvhar()
- BVAR:
- SSVS prior:
set_ssvs()
- Horseshoe prior:
set_horseshoe()
- NG prior:
set_ng()
- DL prior:
set_dl()
- Minneosta prior
-
sv_spec
: prior settings for SV,set_sv()
-
intercept
: prior for constant term,set_intercept()
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.71105 0.00356 -0.2354 1.4005 0.5242 0.377 -0.5504 -0.626
#> 2 0.62412 0.03416 -0.1300 1.4909 -0.3586 0.449 -0.7490 -0.841
#> 3 0.61407 0.17488 0.2433 0.6047 0.4285 0.645 0.3232 -0.394
#> 4 0.41066 0.02684 0.5377 1.2127 -0.0233 0.320 -0.4488 -0.420
#> 5 0.62156 -0.17664 -0.3490 -0.0559 -0.2779 0.379 -0.3396 -0.673
#> 6 0.14841 -0.06202 -0.4995 0.0806 0.6769 0.263 -1.4350 -0.898
#> 7 0.22024 -0.02836 -0.0231 0.1458 0.4921 0.594 -0.7086 -0.273
#> 8 -0.23065 -0.15851 -0.0929 -0.7372 -0.6345 0.140 -0.4590 -0.522
#> 9 -0.00424 -0.02825 0.1001 0.0354 0.4155 0.928 0.2185 -0.165
#> 10 -0.10142 -0.09113 0.4434 0.2203 -0.5776 1.030 0.0774 -0.442
#> # ... 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.18625 0.2809 -0.6060 1.338 0.625 -0.0329 0.0596
#> 5 -0.0508 -0.13928 -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.37315 0.0221 0.2599 0.787 0.794 0.2481 -0.0294
#> 8 0.2332 0.50406 0.1071 0.3790 0.643 0.925 0.0102 -0.0212
#> 9 0.0456 -0.12203 0.0302 0.1127 0.225 0.914 0.1009 0.1686
#> 10 0.0165 0.02265 -0.0299 -0.0358 0.229 0.903 -0.3033 -0.0313
#> # ... 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.0265 -1.02780 0.5815 -0.0183 -0.004602
#> 2 0.27451 0.008657 0.0115 0.21912 0.3532 0.6041 -0.001096
#> 3 0.07962 -0.009057 -0.0885 -0.20976 0.3575 0.5401 0.004027
#> 4 0.20349 -0.003115 0.1644 -0.18843 0.0525 0.3825 0.038893
#> 5 0.11482 -0.009128 -0.2588 0.28820 -0.2782 0.2964 0.010517
#> 6 -0.01974 -0.000145 -0.2407 0.06672 0.2959 0.2881 0.006225
#> 7 -0.00601 0.000303 -0.2053 0.13345 0.0120 0.5838 0.008869
#> 8 0.07843 -0.015252 -0.0583 0.22260 -0.2394 0.6201 -0.001104
#> 9 0.10169 0.002507 -0.0766 -0.00289 0.0498 0.5533 0.000464
#> 10 0.08147 0.000114 -0.0616 -0.02339 -0.0502 0.7777 0.000499
#> phi[8]
#> 1 -0.18781
#> 2 -0.13008
#> 3 -0.14159
#> 4 0.01105
#> 5 -0.01519
#> 6 -0.13691
#> 7 -0.03704
#> 8 -0.05995
#> 9 -0.02037
#> 10 0.00613
#> # ... 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.79e-05 0.01445 -0.00371 -0.0453 4.33e-06 0.07340
#> 9 0.00181 4.48e-05 -0.01553 -0.11883 0.7590 -3.83e-06 0.20149
#> 10 0.00215 -9.07e-04 -0.01055 -0.03061 0.7278 1.23e-04 0.02112
#> 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")