garch_reg: General Interface for GARCH Models

Description Usage Arguments Details Value Engine Details Fit Details See Also Examples

View source: R/parsnip-garch_reg.R

Description

General Interface for GARCH Models

Usage

1
2
3
4
5
6
7
8
garch_reg(
  mode = "regression",
  arch_order = NULL,
  garch_order = NULL,
  ar_order = NULL,
  ma_order = NULL,
  tune_by = NULL
)

Arguments

mode

A single character string for the type of model.

arch_order

An integer giving the order of the ARCH part for the variance model.

garch_order

An integer giving the order of the GARCH part for the variance model.

ar_order

An integer giving the order of the AR part for the mean model.

ma_order

An integer giving the order of the MA part for the mean model.

tune_by

Default is set to NULL, when no tuning. If you want to tune, you must choose between "seriesFor" or "sigmaFor" options. This will cause the function to not return a nested tibble and be able to tune.

These arguments are converted to their specific names at the time that the model is fit.

Other options and argument can be set using set_engine() (See Engine Details below).

Details

Available engines:

Value

A model specification

Engine Details

rugarch (default)

The engine uses rugarch::ugarchspec() and rugarch::ugarchfit().

Function Parameters:

 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
## Formal class 'standardGeneric' [package "methods"] with 8 slots
##   ..@ .Data     :function (variance.model = list(model = "sGARCH", garchOrder = c(1, 1), 
##     submodel = NULL, external.regressors = NULL, variance.targeting = FALSE), 
##     mean.model = list(armaOrder = c(1, 1), include.mean = TRUE, archm = FALSE, 
##         archpow = 1, arfima = FALSE, external.regressors = NULL, archex = FALSE), 
##     distribution.model = "norm", start.pars = list(), fixed.pars = list(), 
##     ...)  
##   ..@ generic   : chr "ugarchspec"
##   .. ..- attr(*, "package")= chr "rugarch"
##   ..@ package   : chr "rugarch"
##   ..@ group     : list()
##   ..@ valueClass: chr(0) 
##   ..@ signature : chr [1:5] "variance.model" "mean.model" "distribution.model" "start.pars" ...
##   ..@ default   :Formal class 'derivedDefaultMethod' [package "methods"] with 4 slots
##   .. .. ..@ .Data  :function (variance.model = list(model = "sGARCH", garchOrder = c(1, 1), 
##     submodel = NULL, external.regressors = NULL, variance.targeting = FALSE), 
##     mean.model = list(armaOrder = c(1, 1), include.mean = TRUE, archm = FALSE, 
##         archpow = 1, arfima = FALSE, external.regressors = NULL, archex = FALSE), 
##     distribution.model = "norm", start.pars = list(), fixed.pars = list(), 
##     ...)  
##   .. .. ..@ target :Formal class 'signature' [package "methods"] with 3 slots
##   .. .. .. .. ..@ .Data  : chr "ANY"
##   .. .. .. .. ..@ names  : chr "variance.model"
##   .. .. .. .. ..@ package: chr "methods"
##   .. .. ..@ defined:Formal class 'signature' [package "methods"] with 3 slots
##   .. .. .. .. ..@ .Data  : chr "ANY"
##   .. .. .. .. ..@ names  : chr "variance.model"
##   .. .. .. .. ..@ package: chr "methods"
##   .. .. ..@ generic: chr "ugarchspec"
##   .. .. .. ..- attr(*, "package")= chr "rugarch"
##   ..@ skeleton  : language (new("derivedDefaultMethod", .Data = function (variance.model = list(model = "sGARCH",      garchOrder = c(1, 1),| __truncated__ ...

The Garch order for the variance model is provided using arch_order and garch_order parameters.. The ARMA order for the mean model is provided using ar_order and ma_order parameters. Other options and arguments can be set using set_engine().

#' Parameter Notes:

Fit Details

Date and Date-Time Variable

It's a requirement to have a date or date-time variable as a predictor. The fit() interface accepts date and date-time features and handles them internally.

Univariate (No xregs, Exogenous Regressors):

For univariate analysis, you must include a date or date-time feature. Simply use:

Multivariate (xregs, Exogenous Regressors)

The xreg parameter is populated using the fit() function:

Xreg Example: Suppose you have 3 features:

  1. y (target)

  2. date (time stamp),

  3. month.lbl (labeled month as a ordered factor).

The month.lbl is an exogenous regressor that can be passed to the garch_reg() using fit():

Note that date or date-time class values are excluded from xreg.

See Also

fit.model_spec(), set_engine()

Examples

 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
library(tidymodels)
library(garchmodels)
library(modeltime)
library(tidyverse)
library(timetk)
library(lubridate)

rIBM_extended <- rIBM %>%
    future_frame(.length_out = 24, .bind_data = TRUE) 

rIBM_train  <- rIBM_extended %>% drop_na()
rIBM_future <- rIBM_extended %>% filter(is.na(daily_returns))

model_garch_fit <-garchmodels::garch_reg(mode = "regression",
                                          arch_order = 1,
                                          garch_order = 1) %>%
    set_engine("rugarch") %>%
    fit(daily_returns ~ date, data = rIBM_train)

predict(model_garch_fit, rIBM_future)

model_garch_fit <-garchmodels::garch_reg(mode = "regression",
                                        arch_order = 2,
                                        garch_order = 2) %>%
    set_engine("rugarch", variance.model = list(model='gjrGARCH', 
                                                garchOrder=c(1,1)),
               mean.model     = list(armaOrder=c(0,0))) %>%
    fit(daily_returns ~ date, data = rIBM_train)

predict(model_garch_fit, rIBM_future)
 

garchmodels documentation built on April 13, 2021, 1:05 a.m.