garch_multivariate_reg.Rd
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.
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 |
A model specfication
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()
.
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()
#>#> v broom 0.7.2 v recipes 0.1.15 #> v dials 0.0.9 v rsample 0.0.9 #> v dplyr 1.0.5 v tibble 3.1.0 #> v ggplot2 3.3.3 v tidyr 1.1.3 #> v infer 0.5.3 v tune 0.1.3 #> v modeldata 0.1.0 v workflows 0.2.2 #> v purrr 0.3.4 v yardstick 0.0.8#> Warning: package 'dplyr' was built under R version 4.0.4#> Warning: package 'rsample' was built under R version 4.0.4#> Warning: package 'tibble' was built under R version 4.0.4#> Warning: package 'tidyr' was built under R version 4.0.4#> Warning: package 'tune' was built under R version 4.0.4#> Warning: package 'workflows' was built under R version 4.0.4#> Conflicts ----------------------------------------- tidymodels_conflicts() -- #> x purrr::discard() masks scales::discard() #> x dplyr::filter() masks stats::filter() #> x dplyr::first() masks rmgarch::first() #> x dplyr::lag() masks stats::lag() #> x dplyr::last() masks rmgarch::last() #> x purrr::reduce() masks rugarch::reduce() #> x recipes::step() masks stats::step()#>#>#>#>#>#>#>#>#>#>#>#>#>#>#>#>#>#>#>#>#>#>#>#>#> Attaching packages --------------------------------------- tidyverse 1.3.0 --#> v readr 1.4.0 v forcats 0.5.1 #> v stringr 1.4.0#> Warning: package 'forcats' was built under R version 4.0.4#> Conflicts ------------------------------------------ tidyverse_conflicts() -- #> x readr::col_factor() masks scales::col_factor() #> x purrr::discard() masks scales::discard() #> x dplyr::filter() masks stats::filter() #> x dplyr::first() masks rmgarch::first() #> x stringr::fixed() masks recipes::fixed() #> x dplyr::lag() masks stats::lag() #> x dplyr::last() masks rmgarch::last() #> x purrr::reduce() masks rugarch::reduce() #> x readr::spec() masks yardstick::spec()#> Warning: package 'lubridate' was built under R version 4.0.4#> #>#>#> #>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)#>#> #>#>#>#>#> #>#>#>#> # A tibble: 18 x 4 #> .pred_name .pred_value .pred_date$date .pred_.name #> <chr> <dbl> <date> <chr> #> 1 rIBM 0.000369 2018-04-28 Series #> 2 rBP 0.000473 2018-04-28 Series #> 3 rGOOG 0.000750 2018-04-28 Series #> 4 rIBM 0.000342 2018-04-29 Series #> 5 rBP 0.000465 2018-04-29 Series #> 6 rGOOG 0.000851 2018-04-29 Series #> 7 rIBM 0.000342 2018-04-30 Series #> 8 rBP 0.000465 2018-04-30 Series #> 9 rGOOG 0.000852 2018-04-30 Series #> 10 rIBM 0.0164 2018-04-28 Sigma #> 11 rBP 0.0133 2018-04-28 Sigma #> 12 rGOOG 0.0195 2018-04-28 Sigma #> 13 rIBM 0.0162 2018-04-29 Sigma #> 14 rBP 0.0134 2018-04-29 Sigma #> 15 rGOOG 0.0196 2018-04-29 Sigma #> 16 rIBM 0.0160 2018-04-30 Sigma #> 17 rBP 0.0135 2018-04-30 Sigma #> 18 rGOOG 0.0196 2018-04-30 Sigma#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)#> # A tibble: 5 x 2 #> .name .pred #> <chr> <named list> #> 1 H <list [1]> #> 2 R <list [1]> #> 3 Q <list [1]> #> 4 Rbar <list [1]> #> 5 mu <dbl[,3,1] [3 x 3 x 1]># 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)#> Warning: la condición tiene longitud > 1 y sólo el primer elemento será usado#> Warning: la condición tiene longitud > 1 y sólo el primer elemento será usado#> # A tibble: 11 x 2 #> .name .pred #> <chr> <named list> #> 1 factor.sigmas <dbl[,3,1] [3 x 3 x 1]> #> 2 mu <dbl[,3,1] [3 x 3 x 1]> #> 3 A <dbl[,3] [3 x 3]> #> 4 Y <dbl[,3] [2,850 x 3]> #> 5 W <dbl[,3] [3 x 3]> #> 6 K <dbl[,3] [3 x 3]> #> 7 Kinv <dbl[,3] [3 x 3]> #> 8 U <dbl[,3] [3 x 3]> #> 9 arcoef <dbl[,3] [2 x 3]> #> 10 garchcoef <dbl[,3] [5 x 3]> #> 11 timer <drtn [1]># }