Description Usage Arguments Details Value Engine Details See Also Examples
View source: R/parsnip-garch_multivariate_reg.R
garch_multivariate_reg()
allows you to model the volatility of various time series. This can be done with the multivariate equivalent
of the univariate GARCH model. Estimating multivariate GARCH models turns out to be significantly more difficult than univariate GARCH models,
but this function facilitates the task through different engines such as rugarch, dcc_rmgarch, gogar_rmgarch etc.
1 | garch_multivariate_reg(mode = "regression", type = NULL)
|
mode |
A single character string for the type of model (Only regression is supported). |
type |
A single character string for the type of model or specification (See details below). Other options and argument can be set using |
Available engines:
rugarch (default): Connects to rugarch::multispec()
and rugarch::multifit()
dcc_rmgarch: Connects to rugarch::multispec()
, rugarch::multifit()
, rmgarch::dccspec()
and rmgarch::dccfit()
.
c_rmgarch: Connects to rugarch::multispec()
, rugarch::multifit()
, rmgarch::cgarchspec()
and rmgarch::cgarchfit()
.
gogarch_rmgarch: Connects to rmgarch::gogarchspec()
and rmgarch::gogarchspec()
.
A model specfication
rugarch (default)
The engine uses rugarch::multispec()
and then rugarch::multifit()
Main Arguments
type
: You can choose between ugarchspec
(default) or arfimaspec
. Depending on which one you choose,
you will select either a univariate GARCH model for each of your variables or an Arfima model as specification,
which will then be passed to rugarch::multispec()
.
You must pass an argument through set_engine()
called specs which will
be a list consisting of the arguments to be passed to each of the specifications used
in rugarch::multispec()
. Other arguments that you wish to pass to rugarch::multifit()
can
also be passed through set_engine()
For example, imagine you have a data frame with 3 variables. For each of those variables you must define a specification (you can check the arguments you can use for a specification in ?rugarch::ugarchspec). Once the specifications have been decided, the way to pass it through set_engine would be as follows:
garch_multivariate_reg(mode = "regression") %>% set_engine("rugarch" , specs = list(spec1 = list(mean.model = list(armaOrder = c(1,0))), spec2 = list(mean.model = list(armaOrder = c(1,0))), spec3 = list(mean.model = list(armaOrder = c(1,0)))), out.sample = 10)
In the fit section we will see how to pass variables through parsnip::fit (See Fit Section below).
Parameter Notes:
xreg
- This engine does support xregs, but you have to provide them to each model in an
array through set_engine. For more information see ?rugarch::ugarchspec. The xregs can be provided
through variance.model$external.regressors
or mean.model$external.regressors
(or both) for the
specifications of the desired variables.
dcc_rmgarch
The engine uses rugarch::multispec()
, rugarch::multifit()
, rmgarch::dccspec()
and rmgarch::dccfit()
.
Main Arguments
type
: Only ugarchspec
is supported for this engine. This will then be passed to rugarch::multispec()
.
You must pass an argument through set_engine()
called specs which will
be a list consisting of the arguments to be passed to each of the specifications used
in rugarch::multispec()
. Other arguments that you wish to pass to rugarch::multifit()
can
also be passed through set_engine()
. To pass arguments to dccfit()
you must pass a list through
set_engine
called dcc_specs.
For example, imagine you have a data frame with 3 variables. For each of those variables you must define a specification (you can check the arguments you can use for a specification in ?rugarch::ugarchspec). Once the specifications have been decided, the way to pass it through set_engine would be as follows:
garch_fit_model <- garch_multivariate_reg(type = "ugarchspec") %>% set_engine("dcc_rmgarch" , specs = list(spec1 = list(mean.model = list(armaOrder = c(1,0))), spec2 = list(mean.model = list(armaOrder = c(1,0))), spec3 = list(mean.model = list(armaOrder = c(1,0)))), dcc_specs = list(dccOrder = c(2,2), distribution = "mvlaplace"))
In the fit section we will see how to pass variables through parsnip::fit (See Fit Section below).
c_rmgarch
The engine uses rugarch::multispec()
, rugarch::multifit()
, rmgarch::cgarchspec()
and rmgarch::cgarchfit()
.
Main Arguments
type
: Only ugarchspec
is supported for this engine. This will then be passed to rugarch::multispec()
.
You must pass an argument through set_engine()
called specs which will
be a list consisting of the arguments to be passed to each of the specifications used
in rugarch::multispec()
. Other arguments that you wish to pass to rugarch::multifit()
can
also be passed through set_engine()
. To pass arguments to cgarchfit()
you must pass a list through
set_engine
called c_specs.
For example, imagine you have a data frame with 3 variables. For each of those variables you must define a specification (you can check the arguments you can use for a specification in ?rugarch::ugarchspec). Once the specifications have been decided, the way to pass it through set_engine would be as follows:
garch_fit_model <- garch_multivariate_reg(type = "arfima") %>% set_engine("c_rmgarch" , specs = list(spec1 = list(mean.model = list(armaOrder = c(1,0))), spec2 = list(mean.model = list(armaOrder = c(1,0))), spec3 = list(mean.model = list(armaOrder = c(1,0)))), c_specs = list(dccOrder = c(2,2))) %>% fit(value ~ date + id, data = rX_longer_train)
In the fit section we will see how to pass variables through parsnip::fit (See Fit Section below).
gogarch_rmgarch
The engine uses rmgarch::gogarchspec()
and rmgarch::gogarchfit()
.
Main Arguments
type
: Not available for this engine.
You must pass an argument through set_engine()
called gogarch_specs which will
be a list consisting of the arguments to be passed to each of the specifications used
in rmgarch::gogarchspec()
. Other arguments that you wish to pass to rmgarch::gogarchfit()
can
also be passed through set_engine()
.
For example, imagine you have a data frame with 3 variables. For each of those variables you must define a specification (you can check the arguments you can use for a specification in ?rugarch::ugarchspec). Once the specifications have been decided, the way to pass it through set_engine would be as follows:
model_fit_garch <- garch_multivariate_reg(type = "ugarchspec") %>% set_engine("gogarch_rmgarch" , gogarch_specs = list(variance.model = list(garchOrder = c(2,2)))) %>% fit(value ~ date + id, data = rX_longer_train)
In the fit section we will see how to pass variables through parsnip::fit (See Fit Section below).
fit.model_spec()
, set_engine()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | library(tidymodels)
library(garchmodels)
library(modeltime)
library(tidyverse)
library(timetk)
library(lubridate)
rX_longer <- rX_longer %>%
dplyr::mutate(date = as.Date(date)) %>%
group_by(id) %>%
future_frame(.length_out = 3, .bind_data = TRUE) %>%
ungroup()
rX_longer_train <- rX_longer %>% drop_na()
rX_longer_future <- rX_longer %>% filter(is.na(value))
#RUGARCH ENGINE
model_fit_garch <- garch_multivariate_reg() %>%
set_engine("rugarch" , specs = list(spec1 = list(mean.model = list(armaOrder = c(1,0))),
spec2 = list(mean.model = list(armaOrder = c(1,0))),
spec3 = list(mean.model = list(armaOrder = c(1,0))))) %>%
fit(value ~ date + id, data = rX_longer_train)
predict(model_fit_garch, new_data = rX_longer_future)
#DCC ENGINE
model_fit_garch <- garch_multivariate_reg(type = "ugarchspec") %>%
set_engine("dcc_rmgarch" , specs = list(spec1 = list(mean.model = list(armaOrder = c(1,0))),
spec2 = list(mean.model = list(armaOrder = c(1,0))),
spec3 = list(mean.model = list(armaOrder = c(1,0)))),
dcc_specs = list(dccOrder = c(2,2), distribution = "mvlaplace")) %>%
fit(value ~ date + id, data = rX_longer_train)
predict(model_fit_garch, rX_longer_future)
# COPULA ENGINE
model_fit_garch <- garch_multivariate_reg(type = "ugarchspec") %>%
set_engine("c_rmgarch" , specs = list(spec1 = list(mean.model = list(armaOrder = c(1,0))),
spec2 = list(mean.model = list(armaOrder = c(1,0))),
spec3 = list(mean.model = list(armaOrder = c(1,0)))),
c_specs = list(dccOrder = c(2,2))) %>%
fit(value ~ date + id, data = rX_longer_train)
# GO-GARCH ENGINE
model_fit_garch <- garch_multivariate_reg(type = "ugarchspec") %>%
set_engine("gogarch_rmgarch" , gogarch_specs = list(variance.model = list(garchOrder = c(2,2)))) %>%
fit(value ~ date + id, data = rX_longer_train)
predict(model_fit_garch, rX_longer_future)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.