Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


⚠️There's a newer version (2.2.2) of this package.Take me there.

bvhar

Overview

bvhar provides functions to analyze multivariate time series time series using

  • VAR
  • VHAR (Vector HAR)
  • BVAR (Bayesian VAR)
  • BVHAR (Bayesian VHAR)

Basically, the package focuses on the research with forecasting.

Installation

install.packages("bvhar")

Development version

You can install the development version from develop branch.

# install.packages("remotes")
remotes::install_github("ygeunkim/bvhar@develop")

We started to develop a Python version in python directory.

Models

library(bvhar) # this package
library(dplyr)

Repeatedly, bvhar is a research tool to analyze multivariate time series model above

Modelfunctionprior
VARvar_lm()
VHARvhar_lm()
BVARbvar_minnesota()Minnesota (will move to var_bayes())
BVHARbvhar_minnesota()Minnesota (will move to vhar_bayes())
BVARvar_bayes()SSVS, Horseshoe, Minnesota, NG, DL
BVHARvhar_bayes()SSVS, Horseshoe, Minnesota, NG, DL

This readme document shows forecasting procedure briefly. Details about each function are in vignettes and help documents. Note that each bvar_minnesota() and bvhar_minnesota() will be integrated into var_bayes() and vhar_bayes() and removed in the next version.

h-step ahead forecasting:

h <- 19
etf_split <- divide_ts(etf_vix, h) # Try ?divide_ts
etf_tr <- etf_split$train
etf_te <- etf_split$test

VAR

VAR(5):

mod_var <- var_lm(y = etf_tr, p = 5)

Forecasting:

forecast_var <- predict(mod_var, h)

MSE:

(msevar <- mse(forecast_var, etf_te))
#>   GVZCLS   OVXCLS VXFXICLS VXEEMCLS VXSLVCLS   EVZCLS VXXLECLS VXGDXCLS 
#>    5.381   14.689    2.838    9.451   10.078    0.654   22.436    9.992 
#> VXEWZCLS 
#>   10.647

VHAR

mod_vhar <- vhar_lm(y = etf_tr)

MSE:

forecast_vhar <- predict(mod_vhar, h)
(msevhar <- mse(forecast_vhar, etf_te))
#>   GVZCLS   OVXCLS VXFXICLS VXEEMCLS VXSLVCLS   EVZCLS VXXLECLS VXGDXCLS 
#>     6.15     2.49     1.52     1.58    10.55     1.35     8.79     4.43 
#> VXEWZCLS 
#>     3.84

BVAR

Minnesota prior:

lam <- .3
delta <- rep(1, ncol(etf_vix)) # litterman
sig <- apply(etf_tr, 2, sd)
eps <- 1e-04
(bvar_spec <- set_bvar(sig, lam, delta, eps))
#> Model Specification for BVAR
#> 
#> Parameters: Coefficent matrice and Covariance matrix
#> Prior: Minnesota
#> ========================================================
#> 
#> Setting for 'sigma':
#>   GVZCLS    OVXCLS  VXFXICLS  VXEEMCLS  VXSLVCLS    EVZCLS  VXXLECLS  VXGDXCLS  
#>     3.77     10.63      3.81      4.39      5.99      2.27      4.88      7.45  
#> VXEWZCLS  
#>     7.03  
#> 
#> Setting for 'lambda':
#> [1]  0.3
#> 
#> Setting for 'delta':
#> [1]  1  1  1  1  1  1  1  1  1
#> 
#> Setting for 'eps':
#> [1]  1e-04
#> 
#> Setting for 'hierarchical':
#> [1]  FALSE
mod_bvar <- bvar_minnesota(y = etf_tr, p = 5, bayes_spec = bvar_spec)

MSE:

forecast_bvar <- predict(mod_bvar, h)
(msebvar <- mse(forecast_bvar, etf_te))
#>   GVZCLS   OVXCLS VXFXICLS VXEEMCLS VXSLVCLS   EVZCLS VXXLECLS VXGDXCLS 
#>    4.651   13.248    1.845   10.356    9.894    0.667   21.040    6.262 
#> VXEWZCLS 
#>    8.864

BVHAR

BVHAR-S:

(bvhar_spec_v1 <- set_bvhar(sig, lam, delta, eps))
#> Model Specification for BVHAR
#> 
#> Parameters: Coefficent matrice and Covariance matrix
#> Prior: MN_VAR
#> ========================================================
#> 
#> Setting for 'sigma':
#>   GVZCLS    OVXCLS  VXFXICLS  VXEEMCLS  VXSLVCLS    EVZCLS  VXXLECLS  VXGDXCLS  
#>     3.77     10.63      3.81      4.39      5.99      2.27      4.88      7.45  
#> VXEWZCLS  
#>     7.03  
#> 
#> Setting for 'lambda':
#> [1]  0.3
#> 
#> Setting for 'delta':
#> [1]  1  1  1  1  1  1  1  1  1
#> 
#> Setting for 'eps':
#> [1]  1e-04
#> 
#> Setting for 'hierarchical':
#> [1]  FALSE
mod_bvhar_v1 <- bvhar_minnesota(y = etf_tr, bayes_spec = bvhar_spec_v1)

MSE:

forecast_bvhar_v1 <- predict(mod_bvhar_v1, h)
(msebvhar_v1 <- mse(forecast_bvhar_v1, etf_te))
#>   GVZCLS   OVXCLS VXFXICLS VXEEMCLS VXSLVCLS   EVZCLS VXXLECLS VXGDXCLS 
#>    3.199    6.067    1.471    5.142    5.946    0.878   12.165    2.553 
#> VXEWZCLS 
#>    6.462

BVHAR-L:

day <- rep(.1, ncol(etf_vix))
week <- rep(.1, ncol(etf_vix))
month <- rep(.1, ncol(etf_vix))
#----------------------------------
(bvhar_spec_v2 <- set_weight_bvhar(sig, lam, eps, day, week, month))
#> Model Specification for BVHAR
#> 
#> Parameters: Coefficent matrice and Covariance matrix
#> Prior: MN_VHAR
#> ========================================================
#> 
#> Setting for 'sigma':
#>   GVZCLS    OVXCLS  VXFXICLS  VXEEMCLS  VXSLVCLS    EVZCLS  VXXLECLS  VXGDXCLS  
#>     3.77     10.63      3.81      4.39      5.99      2.27      4.88      7.45  
#> VXEWZCLS  
#>     7.03  
#> 
#> Setting for 'lambda':
#> [1]  0.3
#> 
#> Setting for 'eps':
#> [1]  1e-04
#> 
#> Setting for 'daily':
#> [1]  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1
#> 
#> Setting for 'weekly':
#> [1]  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1
#> 
#> Setting for 'monthly':
#> [1]  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1
#> 
#> Setting for 'hierarchical':
#> [1]  FALSE
mod_bvhar_v2 <- bvhar_minnesota(y = etf_tr, bayes_spec = bvhar_spec_v2)

MSE:

forecast_bvhar_v2 <- predict(mod_bvhar_v2, h)
(msebvhar_v2 <- mse(forecast_bvhar_v2, etf_te))
#>   GVZCLS   OVXCLS VXFXICLS VXEEMCLS VXSLVCLS   EVZCLS VXXLECLS VXGDXCLS 
#>     3.63     3.85     1.64     5.12     5.75     1.08    13.60     2.58 
#> VXEWZCLS 
#>     5.54

Citation

Please cite this package with following BibTeX:

@Manual{,
  title = {{bvhar}: Bayesian Vector Heterogeneous Autoregressive Modeling},
  author = {Young Geun Kim and Changryong Baek},
  year = {2023},
  doi = {10.32614/CRAN.package.bvhar},
  note = {R package version 2.1.0},
  url = {https://cran.r-project.org/package=bvhar},
}

@Article{,
  title = {Bayesian Vector Heterogeneous Autoregressive Modeling},
  author = {Young Geun Kim and Changryong Baek},
  journal = {Journal of Statistical Computation and Simulation},
  year = {2024},
  volume = {94},
  number = {6},
  pages = {1139--1157},
  doi = {10.1080/00949655.2023.2281644},
}

Code of Conduct

Please note that the bvhar project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Copy Link

Version

Install

install.packages('bvhar')

Monthly Downloads

279

Version

2.1.0

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Young Geun Kim

Last Published

September 16th, 2024

Functions in bvhar (2.1.0)

autoplot.summary.bvharsp

Plot the Heatmap of SSVS Coefficients
bvar_flat

Fitting Bayesian VAR(p) of Flat Prior
bvar_horseshoe

Fitting Bayesian VAR(p) of Horseshoe Prior
bvar_minnesota

Fitting Bayesian VAR(p) of Minnesota Prior
VHARtoVMA

Convert VHAR to VMA(infinite)
VARtoVMA

Convert VAR to VMA(infinite)
bvar_ssvs

Fitting Bayesian VAR(p) of SSVS Prior
bvhar_ssvs

Fitting Bayesian VHAR of SSVS Prior
bvhar_sv

Fitting Bayesian VHAR-SV
bound_bvhar

Setting Empirical Bayes Optimization Bounds
autoplot.summary.normaliw

Density Plot for Minnesota Prior VAR Model
choose_bvar

Finding the Set of Hyperparameters of Individual Bayesian Model
choose_bayes

Finding the Set of Hyperparameters of Bayesian Model
FPE

Final Prediction Error Criterion
confusion

Evaluate the Sparsity Estimation Based on Confusion Matrix
compute_dic

Deviance Information Criterion of Multivariate Time Series Model
coef

Coefficient Matrix of Multivariate Time Series Models
HQ

Hannan-Quinn Criterion
mae

Evaluate the Model Based on MAE (Mean Absolute Error)
conf_prec

Evaluate the Sparsity Estimation Based on Precision
mape

Evaluate the Model Based on MAPE (Mean Absolute Percentage Error)
divide_ts

Split a Time Series Dataset into Train-Test Set
mrae

Evaluate the Model Based on MRAE (Mean Relative Absolute Error)
geom_eval

Adding Test Data Layer
mase

Evaluate the Model Based on MASE (Mean Absolute Scaled Error)
fromse

Evaluate the Estimation Based on Frobenius Norm
conf_recall

Evaluate the Sparsity Estimation Based on Recall
conf_fscore

Evaluate the Sparsity Estimation Based on F1 Score
conf_fnr

Evaluate the Sparsity Estimation Based on FNR
bvhar_horseshoe

Fitting Bayesian VHAR of Horseshoe Prior
bvar_sv

Fitting Bayesian VAR-SV
gg_loss

Compare Lists of Models
init_ssvs

Initial Parameters of Stochastic Search Variable Selection (SSVS) Model
forecast_expand

Out-of-sample Forecasting based on Expanding Window
mse

Evaluate the Model Based on MSE (Mean Square Error)
forecast_roll

Out-of-sample Forecasting based on Rolling Window
choose_ssvs

Choose the Hyperparameters Set of SSVS-VAR using a Default Semiautomatic Approach
sim_mnormal

Generate Multivariate Normal Random Vector
rmsfe

Evaluate the Model Based on RMSFE
choose_var

Choose the Best VAR based on Information Criteria
bvhar_minnesota

Fitting Bayesian VHAR of Minnesota Prior
sim_mniw

Generate Normal-IW Random Family
set_bvar

Hyperparameters for Bayesian Models
reexports

Objects exported from other packages
predict

Forecasting Multivariate Time Series
set_ldlt

Covariance Matrix Prior Specification
fitted

Fitted Matrix from Multivariate Time Series Models
%>%

Pipe operator
set_dl

Dirichlet-Laplace Hyperparameter for Coefficients and Contemporaneous Coefficients
set_ng

Normal-Gamma Hyperparameter for Coefficients and Contemporaneous Coefficients
spne

Evaluate the Estimation Based on Spectral Norm Error
financial_history_appendix

Time points and Financial Events
sim_iw

Generate Inverse-Wishart Random Matrix
set_horseshoe

Horseshoe Prior Specification
sim_horseshoe_var

Generate Horseshoe Parameters
bvhar-package

bvhar: Bayesian Vector Heterogeneous Autoregressive Modeling
compute_logml

Extracting Log of Marginal Likelihood
stableroot

Roots of characteristic polynomial
summary.varlse

Summarizing Vector Autoregressive Model
summary.vharlse

Summarizing Vector HAR Model
residuals

Residual Matrix from Multivariate Time Series Models
rmafe

Evaluate the Model Based on RMAFE
spillover

h-step ahead Normalized Spillover
sim_vhar

Generate Multivariate Time Series Process Following VAR(p)
rmape

Evaluate the Model Based on RMAPE (Relative MAPE)
var_bayes

Fitting Bayesian VAR with Coefficient and Covariance Prior
var_lm

Fitting Vector Autoregressive Model of Order p Model
sim_gig

Generate Generalized Inverse Gaussian Distribution
set_ssvs

Stochastic Search Variable Selection (SSVS) Hyperparameter for Coefficients Matrix and Cholesky Factor
rmase

Evaluate the Model Based on RMASE (Relative MASE)
conf_fdr

Evaluate the Sparsity Estimation Based on FDR
sim_mncoef

Generate Minnesota BVAR Parameters
sim_matgaussian

Generate Matrix Normal Random Matrix
vhar_bayes

Fitting Bayesian VHAR with Coefficient and Covariance Prior
sim_ssvs_var

Generate SSVS Parameters
sim_var

Generate Multivariate Time Series Process Following VAR(p)
dynamic_spillover

Dynamic Spillover
etf_vix

CBOE ETF Volatility Index Dataset
vhar_lm

Fitting Vector Heterogeneous Autoregressive Model
is.stable

Stability of the process
irf.varlse

Impulse Response Analysis
set_intercept

Prior for Constant Term
relspne

Evaluate the Estimation Based on Relative Spectral Norm Error
relmae

Evaluate the Model Based on RelMAE (Relative MAE)
set_lambda

Hyperpriors for Bayesian Models
sim_mnvhar_coef

Generate Minnesota BVAR Parameters
print.summary.bvharsp

Summarizing BVAR and BVHAR with Shrinkage Priors
sim_mvt

Generate Multivariate t Random Vector
summary.normaliw

Summarizing Bayesian Multivariate Time Series Model
autoplot.bvharsp

Plot the Result of BVAR and BVHAR MCMC
autoplot.bvharirf

Plot Impulse Responses
autoplot.predbvhar

Plot Forecast Result
autoplot.normaliw

Residual Plot for Minnesota Prior VAR Model
autoplot.bvhardynsp

Dynamic Spillover Indices Plot