Learn R Programming

MSGARCH (version 2.51)

FitMCMC: MCMC/Bayesian estimation.

Description

Method that performs MCMC/Bayesian estimation of a MSGARCH_SPEC object on a set of observations.

Usage

FitMCMC(spec, data, ctr = list())

Value

A list of class MSGARCH_MCMC_FIT with the following elements:

  • par: The MCMC chain (matrix from the R package coda (Plummer et al., 2006) of size nmcmc / nthin x d).

  • accept: Acceptance rate of the sampler.

  • spec: Model specification of class MSGARCH_SPEC created with CreateSpec.

  • data: Vector (of size T) of observations.

  • ctr: list of the control used for the fit.

The MSGARCH_MCMC_FIT with the following methods:

  • DIC: Deviance Information Criterion (DIC).

  • simulate: Simulation.

  • Volatility: In-sample conditional volatility.

  • predict: Forecast of the conditional volatility (and predictive distribution).

  • UncVol: Unconditional volatility.

  • PredPdf: Predictive density (pdf).

  • PIT: Probability Integral Transform.

  • Risk: Value-at-Risk and Expected-Shortfall.

  • State: State probabilities (smoothed, filtered, predictive, Viterbi).

  • ExtractStateFit: Single-regime model extractor.

  • summary: Summary of the fit.

Arguments

spec

Model specification of class MSGARCH_SPEC created with CreateSpec.

data

Vector (of size T) of observations.

ctr

A list of control parameters:

  • par0: Vector (of size d) where d must have the same length as the default parameters of the specification. It is the starting value for the chain (if empty the the method automatically set starting parameters; see *Details*).

  • nburn (integer >= 0): Number of discarded draws. (Default: nburn = 5000L)

  • nmcmc (integer > 0): Number of draws. (Default: nmcmc = 10000L)

  • nthin (integer > 0): Thinning factor (every nthin draws are kept). (Default: nthin = 10L)

  • do.sort (bool): Logical indicating if the MCMC draws are post-sorted following Geweke (2007). By default, do.sort = TRUE, such that the MCMC draws are ordered to ensure that unconditional variance is an increasing function of the regime (identification constraint). If the user sets do.sort = FALSE, no sorting is imposed, and label switching can occur (see *Details*).

  • SamplerFUN: Custom MCMC sampler (see *Details*).

Details

The total number of draws is equal to nmcmc / nthin. The MCMC/Bayesian estimation relies on an Rcpp implementation of the adaptive sampler of Vihola (2012). The implementation is based on the R package adaptMCMC (Andreas, 2012). Starting values when par0 is not provided are chosen automatically before sampling (see Ardia et al. (2019) for more details).
SamplerFUN allows for a custom sampler to be used. The function must take the form:
function(f_posterior, data, spec, par0, ctr),
where f_posterior is the function to optimize, data is the data, spec is the specification, par0 are the starting parameters, and ctr are the control parameters. The inputs spec and data, must be passed as inputs in the sampler (see *Examples*). The custom sampler must output a matrix containing the MCMC chain.
When do.sort = TRUE, sorting of each MCMC draw conditional on the unconditional variance is done across homogeneous regime specification.

References

Andreas, S. (2012). adaptMCMC: Implementation of a generic adaptive Monte Carlo Markov chain sampler. https://cran.r-project.org/package=adaptMCMC

Ardia, D. Bluteau, K. Boudt, K. Catania, L. Trottier, D.-A. (2019). Markov-switching GARCH models in R: The MSGARCH package. Journal of Statistical Software, 91(4), 1-38. tools:::Rd_expr_doi("10.18637/jss.v091.i04")

Geweke J (2007). Interpretation and Inference in Mixture Models: Simple MCMC Works. Computational Statistics & Data Analysis, 51(7), 3529-3550. tools:::Rd_expr_doi("10.1016/j.csda.2006.11.026")

MacDonald, I.L., Zucchini, W. (1997). Hidden Markov and other models for discrete-valued time series. CRC press.

Plummer, M. Best, N. Cowles, K. & Vines, K. (2006). coda: Convergence diagnosis and output analysis for MCMC. R News, 6, 7-11. https://cran.r-project.org/package=coda

Vihola, M. (2012). Robust adaptive Metropolis algorithm with coerced acceptance rate. Statistics and Computing, 22, 997-1008. tools:::Rd_expr_doi("10.1007/s11222-011-9269-5")

Examples

Run this code
# create model specification
spec <- CreateSpec()

# load data
data("SMI", package = "MSGARCH")

# fit the model on the data by MCMC
set.seed(123)
fit <- FitMCMC(spec = spec, data = SMI, ctr = list(nburn = 500L, nmcmc = 500L, nthin = 1L))
summary(fit)

# custom sampler example
if (FALSE) {
library("mcmc")
f_MCMC <- function(f_posterior, data, spec, par0, ctr){
  par <- mcmc::metrop(f_posterior, initial = par0, nbatch = ctr$nmcmc + ctr$nburn,
                        data = data, spec = spec)$batch
  colnames(par) = names(par0)
  return(par)
}

set.seed(123)
fit <- FitMCMC(spec, data = SMI, ctr  = list(SamplerFUN = f_MCMC,
                                             nburn = 500L, nmcmc = 500L, nthin = 1L))
summary(fit)
}

Run the code above in your browser using DataLab