Вы находитесь на странице: 1из 27

MARKOV-SWITCHING GARCH MODELS IN R:

THE MSGARCH PACKAGE

Keven Bluteau

joint work with:

David Ardia
Kris Boudt
Leopoldo Catania
Brian Peterson
Denis-Alexandre Trottier

useR!2017, July 3-7


https://github.com/keblu/MSGARCH

Keven Bluteau v01 1


Keven Bluteau v01 2
Keven Bluteau v01 3
Keven Bluteau v01 4
Keven Bluteau v01 5
Keven Bluteau v01 6
Keven Bluteau v01 7
Keven Bluteau v01 8
Keven Bluteau v01 9
GO TO CRAN

– Problem:
No R package dealing with these kind of model in a generalized way.

– Solution:
Create one ! The MSGARCH package.

Keven Bluteau v01 10


IN BRIEF

– MSGARCH implements Haas et al. (2004a) specification:

1. K separate single-regime conditional variance processes.


2. Possibly K separate conditional distributions.
3. A Markov chain dictates the switches between regimes.
4. Assumes a zero mean process.

– Core of the package is in C++ (thanks to Rcpp) to allow for fast and
efficient computations.
– Easy estimation and specification creation (similar to rugarch).
– Functionality for visualization, simulation, model selection, and risk
measure forecasting.

Keven Bluteau v01 11


VOLATILITY MODELS

Bollerslev (1986)

Nelson (1991)

Glosten et al. (1993)

Zakoian (1994)

Creal et al. (2013)

Keven Bluteau v01 12


CONDITIONAL DISTRIBUTIONS

- Skewed versions also available using the Fernández and Steel (1998)
transformation.

Keven Bluteau v01 13


CREATING A SPECIFICATION

– First step is to create a specification

– Inputs:
– model: “sGARCH”, “eGARCH”, “gjrGARCH”,
“tGARCH”, “GAS”
– distribution: “norm”, “std”,“ged”
– do.skew: Skewed distribution Boolean.
– do.mix: Mixture of GARCH specification of Haas et al. (2004b).
– do.shape.ind: Make it so that only the conditional volatility
models switches (distribution and shape
parameter stays the same across regime).

Keven Bluteau v01 14


EXAMPLES

– Simple GARCH(1,1) normal:

– Two-state MSGARCH model with GARCH(1,1) normal in both


regimes:

– Complex MSGARCH model:

Keven Bluteau v01 15


WHAT IS INSIDE ?

– A specification is an S3 R class that gives you access to all the


MSGARCH functionalities.
– Embedded C++ templated class inside. Why ?
– C++ : Fast calculations of likelihood.
– Templated: Easy future extensions.
– This means adding conditional volatility models and conditional
distributions with minimal work (and debugging).

Keven Bluteau v01 16


TEMPLATED?

class Normal
{ … };

template<typename underlying>
class Skewed
{ … };

template <typename distribution>


class sGARCH
{ … };

template <typename Model>


class SingleRegime
{ … };

typedef SingleRegime <sGARCH <Skewed <Normal>>> sGARCH_norm_skew;

The MSgarch class takes a vector of K SingleRegime objects class as parameters.

Keven Bluteau v01 17


ILLUSTRATION – DATA

– SMI log-returns from 1990-11-12 to 2000-10-20.

Keven Bluteau v01 18


ILLUSTRATION – MLE ESTIMATION

– Make use of DEoptim (global) & nmkb from dfoptim (local)

Keven Bluteau v01 19


ILLUSTRATION – BAYESIAN ESTIMATION

– Make use of adaptMCMC

Keven Bluteau v01 20


AND SO WHAT?

– Available functionalities:
– Filtered volatilities.
– Filtered probabilities.
– N-step ahead simulation.
– Predictive density.
– Risk measures (VaR and ES).
– Information criteria.
– And more !

– All functionalities are compatible for both MLE and Bayesian estimation.

Keven Bluteau v01 21


ILLUSTRATION – VOLATILITIES & STATE

Keven Bluteau v01 22


PREDICTIVE DENSITY

1. Object can take a specification:


1. In case of a specification, theta and y must be provided.
2. Useful when using the same fitted model on new data y.
2. Object can take a fitted model:
1. No need to input theta and y.
2. Useful shortcut.
3. The variable x are what we want to evaluate.
4. If do.its = TRUE, x is not needed as we evaluated the function with the
in-sample observation (in-sample).
5. If do.its = FALSE, x is evaluated as a 1-step ahead draws.

Log-likelihood function: Use kernel() to include the


priors:

Keven Bluteau v01 23


ILLUSTRATION – PREDICTIVE DENSITY

MLE

MCMC

Keven Bluteau v01 24


ILLUSTRATION – RISK MEASURES

– The risk function works similarly to the pred function.


– It also leverages the pred function to calculate risk measures.
- do.its = TRUE will calculate the in-sample risk measures for all dates.
- do.its = FALSE will calculate the one-step ahead risk measures.

Keven Bluteau v01 25


WHAT NEXT?

– Google Summer of Code 2017 (Leopoldo Catania).


– Working paper where we demonstrate a large scale empirical study the advantage of
such model.
– Wish list:
– Improved starting value strategy for faster optimization.
– Multi-step ahead forecasts (by simulation).
– Parameters constraints.
– Standard errors of the estimates (MLE).
– Custom MLE and MCMC optimizers (including custom priors).
– Multivariate model with regime-switching copulas.
– And more!

Some are currently implemented in MSGARCH 0.19 (available on GitHub)!

Keven Bluteau v01 26


MSGARCH PACKAGE

Thanks for your attention and hope you’ll enjoy our package!!

https://CRAN.R-project.org/package=MSGARCH V. 0.17.7
https://github.com/keblu/MSGARCH V. 0.19.0

V. 1.00.0 and new documentation coming to CRAN this August !

Keven Bluteau v01 27

Вам также может понравиться