Learn R Programming

MSGARCH (version 1.3)

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())

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*).

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

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

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

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

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 N.mcmc / N.thin x d).

  • accept: Acceptation 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:

  • AIC: Compute Akaike information criterion (AIC).

  • BIC: Compute Bayesian information criterion (BIC).

  • DIC: Compute Deviance Information Criterion (DIC).

  • Volatility: In-sample conditional volatility filterting of the overall process.

  • Forecast: Forecast of the conditional volatility of the overall process.

  • UncVol: Unconditional volatility in each regime and the overall process.

  • Pred: Predictive method.

  • PIT: Probability integral transform.

  • Risk: Value-at-Risk And Expected-Shortfall methods.

  • Sim: Simulation method.

  • State: State probabilities methods.

  • ExtractStateFit: Single-regime model extractor.

  • summary: Summary of the fit.

Details

The total number of draws is equal to n.mcmc / n.thin. 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. (2016) 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.

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. (2016). Markov-switching GARCH models in R: The MSGARCH package. https://ssrn.com/abstract=2845809

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.

Examples

Run this code
# NOT RUN {
# load data
data("SMI", package = "MSGARCH")

# create model specification
# MS(2)-GARCH(1,1)-Normal (default)
spec <- CreateSpec()

# fit the model on the data by MCMC
set.seed(123)
fit <- FitMCMC(spec = spec, data = SMI, ctr = list(n.burn = 500L, n.mcmc = 500L, n.thin = 1L))
summary(fit)

# custom sampler example
# }
# NOT RUN {
library("mcmc")
f_MCMC <- function(f_posterior, data, spec, par0, ctr){
  par <- mcmc::metrop(f_posterior, initial = par0, nbatch = ctr$n.mcmc + ctr$n.burn,
                        data = data, spec = spec)$batch
  return(par)
}

set.seed(123)
fit <- FitMCMC(spec, data = SMI, ctr  = list(SamplerFUN = f_MCMC,
                                             n.burn = 500L, n.mcmc = 500L, n.thin = 1L))
summary(fit)
# }

Run the code above in your browser using DataLab