Source-linked AI summary
Dealing with Stochastic Volatility in Time Series Using the R Package stochvol
Gregor Kastner
TL;DR
Stochastic volatility models have seen limited applied use partly because estimation methods are varied and ready-to-use software is scarce. This paper presents stochvol, an R package implementing fully Bayesian MCMC inference and demonstrating its use with exchange-rate data and other MCMC samplers. The examples show improved predictive performance from heteroskedastic modeling, with SV outperforming vanilla GARCH(1,1) in predictive accuracy.
Problem
Stochastic volatility has limited applied use partly because estimation methods may be incompatible and ready-to-use software packages are lacking.
Method
The paper introduces stochvol, a fully Bayesian simulation-based R package using MCMC to infer stochastic-volatility parameters and latent variables, including as a plug-in for other MCMC samplers.
Results
Out-of-sample cumulative predictive Bayes factors showed that heteroskedastic modeling substantially improves predictive performance in turbulent times, with SV outperforming vanilla GARCH(1,1) in predictive accuracy.
Takeaways & Limitations
stochvol provides a stand-alone and plug-in workflow for Bayesian stochastic-volatility analysis, illustrated through exchange-rate data and a Bayesian linear model with SV errors.
Takeaways & Limitations
For financial datasets with n ≲1000, prior hyperparameters can strongly influence φ when the underlying process is near-homoskedastic; prior choices must also reflect whether returns are logged or percentage-logged.
Abstract
from arXiv · showhide
The R package stochvol provides a fully Bayesian implementation of heteroskedasticity modeling within the framework of stochastic volatility. It utilizes Markov chain Monte Carlo (MCMC) samplers to conduct inference by obtaining draws from the posterior distribution of parameters and latent variables which can then be used for predicting future volatilities. The package can straightforwardly be employed as a stand-alone tool; moreover, it allows for easy incorporation into other MCMC samplers. The main focus of this paper is to show the functionality of stochvol. In addition, it provides a brief mathematical description of the model, an overview of the sampling schemes used, and several illustrative examples using exchange rate data.
1. Introduction
Stochastic volatility models offer a probabilistic alternative to deterministic GARCH models, but their applied use has been limited by estimation-method diversity and scarce ready-to-use software. The paper and stochvol address this software gap with an R implementation for efficiently estimating SV models.
- Financial returns are commonly analyzed with models that estimate and predict potentially time-varying volatilities.
- GARCH models represent volatility evolution deterministically, whereas stochastic volatility models represent it probabilistically through a latent autoregressive state process.
- Despite early evidence favoring stochastic volatility, applied use has lagged because estimation methods vary and compatible standard software is scarce.
- The paper and stochvol package target the lack of ready-to-use software for efficiently estimating stochastic volatility models.
2. Model specification and estimation
The paper specifies stochastic volatility as a hierarchical model with latent log-variance dynamics and Bayesian priors, then estimates parameters and latent states using MCMC. Its sampler combines joint volatility updates, efficient implementation, and ASIS reparameterization to improve sampling across parameterizations.
- 2.1. The SV model: The SV model gives each return its own contemporaneous variance, whose logarithm follows an autoregressive process rather than varying unrestrictedly over time.
- 2.1. The SV model: The parameter vector θ contains the log-variance level µ, persistence φ, and log-variance volatility ση, while h denotes the latent log-variance process.
- 2.2. Prior distribution: Independent priors are assigned to µ, φ, and ση; the persistence prior restricts φ to (−1, 1), guaranteeing stationarity of the autoregressive volatility process.
- 2.2. Prior distribution: For financial datasets with n ≲1000, hyperparameters a0 and b0 can strongly influence the posterior of φ when the data are near-homoskedastic.
- 2.3. MCMC sampling: MCMC produces posterior draws of θ and latent log-variances h, whose dependence requires careful algorithm design and convergence assessment.
- 2.3. MCMC sampling: The sampler jointly updates all instantaneous volatilities using AWOL and auxiliary finite-mixture error approximations, reducing draw correlation significantly.
- 2.3. MCMC sampling: Core computations run in compiled C and interface with R through Rcpp, combining computational efficiency with R-based convenience functions and MCMC-output frameworks.
- 2.3. MCMC sampling: ASIS samples parameters in centered and non-centered forms because neither parameterization is uniformly superior across stochastic volatility processes.
3. The stochvol package
The stochvol workflow prepares return data, specifies priors and sampler settings, runs svsample, and assesses posterior output. It supports real or simulated series, volatility forecasts, convergence-oriented summaries, and diagnostic plots.
- Workflow: The stand-alone workflow comprises data preparation, prior and configuration specification, sampling, and output assessment.The package documents these steps as a complete fitting workflow and also supports incorporation into other MCMC samplers.
- Preparing the data: svsample accepts a numeric return vector without missing values and warns about zero returns, while example preparation uses demeaned EUR-USD log returns.The package also provides svsim for generating realizations of an SV process.
- Priors and configuration: Users specify priors for the log-variance level, persistence, and variance parameter through priormu, priorphi, and priorsigma.The documentation notes that persistence-prior hyperparameters can be influential, whereas the variance-prior choice is usually less influential in typical applications.
- Priors and configuration: Burn-in, retained draws, thinning, starting values, verbosity, and expert sampler options control the MCMC run.The default burn-in is 1000 iterations and the default number of post-burn-in draws is 10 000; users are encouraged to check convergence carefully.
- Sampling and output: svsample wraps the C-coded MCMC sampler, converts results to coda-compatible objects, and returns an svdraws object containing posterior and latent-volatility information.The returned object also includes posterior summaries, while coda compatibility provides access to convergence diagnostics.
- Assessing the output: The package supplies print, summary, volatility, trace, density, combined, and residual plotting methods for assessing posterior output and model fit.Posterior summaries can be configured through updatesummary and passed through additional arguments.
4. Using stochvol within other samplers
The paper demonstrates embedding stochastic volatility updates within an existing Bayesian normal linear-model sampler by replacing homoskedastic variance sampling with stochvol calls. The workflow alternates latent-volatility and regression-parameter updates, then stores and summarizes posterior draws.
- Using stochvol within other samplers: stochvol can incorporate stochastic volatility into an existing MCMC sampler, including samplers coded in R or C/C++.The example adapts a hand-coded Gibbs sampler for a Bayesian normal linear model.
- Bayesian normal linear model: The homoskedastic model uses an identity-scaled covariance matrix and Gibbs draws from conditional distributions for β and σ²ϵ.The sampler alternates conditional Gaussian regression-coefficient draws with conditional Inverse-Gamma variance draws.
- Bayesian normal linear model with SV errors: The stochastic-volatility version replaces the σ²ϵ update with svsample2, which samples latent volatilities and parameters conditional on the regression coefficients.The regression coefficients are then sampled conditional on the updated latent volatilities after transforming the design matrix and response.
- Bayesian normal linear model with SV errors: svsample2 is a minimal-overhead version of svsample with full sampling functionality, simplified returns, fewer input checks, and required startpara and startlatent states.Its reduced overhead makes it more suitable for repeated calls, but incompatible inputs can cause runtime failures in compiled code.
- Bayesian normal linear model with SV errors: The example stores posterior draws for μ, φ, σ, regression coefficients, and latent volatilities before visualizing and summarizing them.The illustrated configuration uses 50,000 draws, 1,000 burn-in iterations, and thinning by 10.
- Computational considerations: The R-level svsample2 interface remains costly to interpret inside every MCMC iteration, while a C/C++ single-step update is provided to avoid that overhead.The paper identifies interpreted-language overhead as the reason for providing a C/C++ implementation path.
5. Illustrative predictive exercise
The exchange-rate exercise compares homoskedastic, SV, and GARCH(1,1) error specifications in an AR(1) model for log prices. Across residual diagnostics and predictive evaluation, heteroskedastic models—especially SV—adapt better to changing volatility, while broader generalization requires further studies.
- 5.1. Model setup: The analysis models EUR/USD log prices with an AR(1) specification under homoskedastic, SV, and GARCH(1,1) errors.The setup uses daily prices from January 3, 2000 to April 4, 2012, with lagged log prices as predictors.
- 5.2. Posterior inference: Posterior coefficients spread around (0, 1)⊤, consistent with the random-walk behavior visible in the log-price scatterplot.The scatterplot compares daily log prices at time t and t + 1 against the identity line.
- 5.2. Posterior inference: SV errors nearly eliminate residual dependence and produce approximately normal standardized residuals, whereas homoskedastic and GARCH errors retain stronger deficiencies.Homoskedastic residuals show pronounced dependence and heavy tails; GARCH improves fit but still shows heavy tails.
- 5.4. Results: After a 1000-day training period, SV predictive intervals and likelihoods respond substantially better to inflated volatility, with intervals around twice as wide in early 2009.The evaluation begins at t = 1001, corresponding to December 4, 2003.
- 5.4. Results: Cumulative predictive Bayes factors strongly favor heteroskedastic models and decisively favor SV over vanilla GARCH(1,1), reaching approximately 25 000 : 1.The final cumulative log predictive Bayes factors are 176.52 for SV and 166.37 for GARCH.
- 5.4. Results: The authors report similar qualitative results across other exchange rates and caution that universal claims require more datasets and competing models.The requested broader studies could include realized volatility measures.
6. Conclusion
The article introduces stochvol as a fully Bayesian, simulation-based tool for stochastic-volatility inference and demonstrates its use with exchange-rate data and other MCMC samplers. Predictive analyses show that heteroskedastic modeling improves out-of-sample performance, particularly during turbulent periods, with SV outperforming vanilla GARCH(1,1) in predictive accuracy.
- stochvol provides fully Bayesian simulation-based inference for stochastic-volatility models.
- The package supports both stand-alone analysis and plug-in use within other MCMC samplers, illustrated with a Bayesian linear model with SV errors.
- Out-of-sample exchange-rate analyses found that heteroskedastic regression residuals substantially improve predictive performance, especially in turbulent periods.
- SV residuals achieved higher predictive accuracy than vanilla GARCH(1,1) in the direct comparison.
Affiliation:
The paper identifies Gregor Kastner's affiliation as the Institute for Statistics and Mathematics.
- Gregor Kastner is affiliated with the Institute for Statistics and Mathematics.