Skip to contents

Extracts formula from a formula GARCH object.

Methods

Methods for formula defined in package fGarch:

object = "fGARCH"

Extractor function for formula expression.

Details

formula is a generic function which extracts the formula expression from objects returned by modeling functions.

The "fGARCH" method extracts the @formula expression slot from an object of class "fGARCH" as returned by the function garchFit.

The returned formula has always a left hand side. If the argument data was an univariate time series and no name was specified to the series, then the left hand side is assigned the name of the data.set. In the multivariate case the rectangular data object must always have column names, otherwise the fitting will be stopped with an error message

The class of the returned value depends on the input to the function garchFit who created the object. The returned value is always of the same class as the input object to the argument data in the function garchFit, i.e. if you fit a "timeSeries" object, you will get back from the function fitted also a "timeSeries" object, if you fit an object of class "zoo", you will get back again a "zoo" object. The same holds for a "numeric" vector, for a "data.frame", and for objects of class "ts", "mts".

In contrast, the slot itself returns independent of the class of the data input always a numeric vector, i.e. the function call rslot(object, "fitted") will return a numeric vector.

Note

(GNB) Contrary to the description of the returned value of the "fGARCH" method, it is always "numeric".

TODO: either implement the documented behaviour or fix the documentation.

Author

Diethelm Wuertz for the Rmetrics R-port

See also

Examples

## garchFit -
   fit = garchFit(~garch(1, 1), data = garchSim(), trace = FALSE)
   
## formula - 
   formula(fit)
#> data ~ garch(1, 1)
#> attr(,"data")
#> [1] "data = garchSim()"
#> <environment: 0x569a13451430>

## A Bivariate series and mis-specified formula:
   x = garchSim(n = 500)
   y = garchSim(n = 500)
   z = cbind(x, y)
   colnames(z)
#> [1] "garch.1" "garch.2"
   class(z)
#> [1] "timeSeries"
#> attr(,"package")
#> [1] "timeSeries"
   if (FALSE) {
   garchFit(z ~garch(1, 1), data = z, trace = FALSE)
   }
   # Returns:
   # Error in .garchArgsParser(formula = formula, data = data, trace = FALSE) :  
   #   Formula and data units do not match.
   
## Doubled column names in data set - formula can't fit:
   colnames(z) <- c("x", "x")
   z[1:6,]
#> GMT 
#>                        x             x
#> 2022-12-17 -0.0023426733  0.0026281998
#> 2022-12-18  0.0012113489 -0.0004620617
#> 2022-12-19  0.0001135257  0.0043161485
#> 2022-12-20 -0.0042403482 -0.0015096423
#> 2022-12-21 -0.0093567474  0.0013723818
#> 2022-12-22  0.0026138964 -0.0047791439
   if (FALSE) {
   garchFit(x ~garch(1, 1), data = z, trace = FALSE)
   }
   # Again the error will be noticed:
   # Error in garchFit(x ~ garch(1, 1), data = z) : 
   #   Column names of data are not unique.

## Missing column names in data set - formula can't fit:
   z.mat <- as.matrix(z)
   colnames(z.mat) <- NULL
   z.mat[1:6,]
#>                     [,1]          [,2]
#> 2022-12-17 -0.0023426733  0.0026281998
#> 2022-12-18  0.0012113489 -0.0004620617
#> 2022-12-19  0.0001135257  0.0043161485
#> 2022-12-20 -0.0042403482 -0.0015096423
#> 2022-12-21 -0.0093567474  0.0013723818
#> 2022-12-22  0.0026138964 -0.0047791439
   if (FALSE) {
   garchFit(x ~ garch(1, 1), data = z.mat, trace = FALSE)
   }
   # Again the error will be noticed:
   # Error in .garchArgsParser(formula = formula, data = data, trace = FALSE) : 
   #   Formula and data units do not match