Overview
tsbs provides advanced bootstrap methods for time series data, with a focus on capturing complex temporal dependencies including regime-switching behavior and conditional heteroskedasticity. The package implements several bootstrap approaches ranging from classical block methods to sophisticated model-based resampling.
Installation
Install from GitHub:
# install.packages("devtools")
devtools::install_github("mahovo/tsbs")Bootstrap Methods
The package supports the following bootstrap types via the main tsbs() function:
| Method | bs_type |
Description |
|---|---|---|
| Moving Block | "moving" |
Fixed-length blocks sampled with replacement |
| Stationary Block | "stationary" |
Random block lengths (geometric distribution) |
| Hidden Markov Model | "hmm" |
Regime-switching with discrete states |
| MS-VAR | "msvar" |
Markov-Switching Vector Autoregression |
| MS-VARMA-GARCH | "ms_varma_garch" |
Markov-Switching VARMA with GARCH errors |
| Wild Bootstrap | "wild" |
Residual-based with random sign flips |
Quick Start
library(tsbs)
# Simple stationary block bootstrap
set.seed(123)
x <- arima.sim(n = 200, list(ar = 0.8))
result <- tsbs(
x = as.matrix(x),
bs_type = "stationary",
block_length = 10,
num_blocks = 20,
num_boots = 100,
func = mean
)
# Bootstrap distribution of the mean
hist(unlist(result$func_outs), main = "Bootstrap Distribution")
abline(v = result$func_out_means, col = "red", lwd = 2)Documentation
Primary Documentation
The main entry point for the package is the tsbs() function, which provides comprehensive documentation including detailed specification examples:
file:///Users/mhvpbp13/git/tsbs/docs/reference/tsbs.html
In R with tsbs package installed and loaded:
?tsbsFull reference manual:
https://mahovo.github.io/tsbs/
Vignettes
The package includes vignettes for specialized topics:
| Vignette | Description |
|---|---|
vignette("portfolio-optimization-demo", package = "tsbs") |
Comprehensive demo of portfolio optimization w/ tsbs |
vignette("bootstrap_diagnostics", package = "tsbs") |
Diagnostic system for output bootstrap series |
vignette("ms-varma-garch_diagnostics.Rmd", package = "tsbs") |
Diagnostic system for monitoring EM convergence, parameter evolution, and numerical stability |
vignette("ms-varma-garch_inference", package = "tsbs") |
Statistical inference for DCC, CGARCH and GOGARCH parameters |
vignette("multivariate_garch_comparison", package = "tsbs") |
Diagnostic vignette comparing DCC, CGARCH and GOGARCH models |
Demos
See a pre-rendered version of “portfolio-optimization.Rmd” :
https://github.com/mahovo/tsbs/blob/main/inst/demos/portfolio-optimization.md
library(tsbs)
# See what demos are available
list_package_demos()
# Get path to a demo (choose demo name from list)
demo_path <- get_demo_path("portfolio-optimization")
# Render it (choose your output location)
demo_output_dir <- "demo-output"
rmarkdown::render(demo_path, output_dir = demo_output_dir)
# Or use in a pipeline
get_demo_path(demo_list[[1]]) |>
rmarkdown::render(output_dir = demo_output_dir)See also https://github.com/mahovo/tsbs/tree/main/inst/demos
Learning from Test Files
The package test files contain extensive examples of model specification and usage patterns. Examining these files can be a helpful way to understand how to specify models for different scenarios:
# Location of test files (after installation)
system.file("tests", package = "tsbs")Key test files include:
-
test-ms_varma_garch_bs.R— Comprehensive examples of MS-VARMA-GARCH specifications
-
test-cgarch.R— Testing the CGARCH integration
-
test-gogarch.R— Testing the GOGARCH integration
-
test-blockBootstrap
-
test-hmm_bootstrap
test-wild_bootstrap
Key Features
-
Unified Interface: Single
tsbs()function for all bootstrap methods - Flexible Function Application: Apply arbitrary functions to bootstrap replicates
- Parallel Processing: Built-in support for parallel computation
- Comprehensive Diagnostics: Monitor convergence and numerical stability for complex models
Citation
If you use tsbs in your research, please cite:
@software{tsbs,
title = {tsbs: Time Series Bootstrap Methods},
author = {Vognsen, Martin Hoshi},
url = {https://github.com/mahovo/tsbs}
}
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
