Title: | Univariate GARCH Models |
---|---|
Description: | Multiple flavors of the Generalized Autoregressive Conditional Heteroskedasticity (GARCH) model with a large choice of conditional distributions. Methods for specification, estimation, prediction, filtering, simulation, statistical testing and more. Represents a partial re-write and re-think of 'rugarch', making use of automatic differentiation for estimation. |
Authors: | Alexios Galanos [aut, cre, cph] |
Maintainer: | Alexios Galanos <[email protected]> |
License: | GPL-2 |
Version: | 1.0.4 |
Built: | 2024-12-12 22:26:20 UTC |
Source: | https://github.com/tsmodels/tsgarch |
Combine univariate GARCH specifications into a multi-specification object
## S3 method for class 'tsgarch.spec' x + y
## S3 method for class 'tsgarch.spec' x + y
x |
an object of class “tsgarch.spec” |
y |
an object of class “tsgarch.spec” |
A simple method for combining multiple specifications into an object which can then be estimated using parallel resources. Note that the returned object is effectively a validated list of specification objects with no names. Names can be assigned post-construction (see example).
an object of class “tsgarch.multispec”
library(xts) x <- xts(rnorm(1000), as.Date(1:1000, origin = "1970-01-01")) y <- xts(rnorm(1000), as.Date(1:1000, origin = "1970-01-01")) z <- xts(rnorm(1000), as.Date(1:1000, origin = "1970-01-01")) mspec <- garch_modelspec(x, model = "egarch") + garch_modelspec(y, model = "cgarch") + garch_modelspec(z, model = "aparch") names(mspec) <- c("x", "y", "z") sapply(mspec, function(x) x$model$model)
library(xts) x <- xts(rnorm(1000), as.Date(1:1000, origin = "1970-01-01")) y <- xts(rnorm(1000), as.Date(1:1000, origin = "1970-01-01")) z <- xts(rnorm(1000), as.Date(1:1000, origin = "1970-01-01")) mspec <- garch_modelspec(x, model = "egarch") + garch_modelspec(y, model = "cgarch") + garch_modelspec(z, model = "aparch") names(mspec) <- c("x", "y", "z") sapply(mspec, function(x) x$model$model)
Extract the AIC from an estimated model.
## S3 method for class 'tsgarch.estimate' AIC(object, ..., k = 2)
## S3 method for class 'tsgarch.estimate' AIC(object, ..., k = 2)
object |
an object of class “tsgarch.estimate”. |
... |
not currently used. |
k |
the penalty per parameter to be used; the default k = 2 is the classical AIC. |
A numeric value.
Transforms a “benchmark.fcp” or “benchmark.laurent” object into a flextable.
## S3 method for class 'benchmark.laurent' as_flextable(x, digits = 4, ...) ## S3 method for class 'benchmark.fcp' as_flextable(x, digits = 4, ...)
## S3 method for class 'benchmark.laurent' as_flextable(x, digits = 4, ...) ## S3 method for class 'benchmark.fcp' as_flextable(x, digits = 4, ...)
x |
an object of class “benchmark.fcp” or “benchmark.aparch”. |
digits |
integer, used for number formatting. Optionally, to avoid scientific notation, set ‘options(scipen=999)’. |
... |
additional arguments passed to flextable method. |
A flextable object.
Transforms a “summary.tsgarch” object into a flextable with options on symbolic representation and model equation.
## S3 method for class 'summary.tsgarch.estimate' as_flextable( x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), include.symbols = TRUE, include.equation = TRUE, include.statistics = TRUE, table.caption = paste0(toupper(x$model), " Model Summary"), ... )
## S3 method for class 'summary.tsgarch.estimate' as_flextable( x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), include.symbols = TRUE, include.equation = TRUE, include.statistics = TRUE, table.caption = paste0(toupper(x$model), " Model Summary"), ... )
x |
an object of class “summary.tsgarch”. |
digits |
integer, used for number formatting. Optionally, to avoid scientific notation, set ‘options(scipen=999)’. |
signif.stars |
logical. If TRUE, ‘significance stars’ are printed for each coefficient. |
include.symbols |
logical. If TRUE, replaces parameter names with their symbols (if they exist). |
include.equation |
logical. If TRUE, adds a section with the symbolic model equation. |
include.statistics |
logical. If TRUE, adds a section with summary statistics on the model. |
table.caption |
an optional string for the table caption. |
... |
additional arguments passed to flextable method. |
A flextable object.
The GARCH(1,1) FCP benchmark.
benchmark_fcp(control = nloptr_fast_options())
benchmark_fcp(control = nloptr_fast_options())
control |
control arguments for the nloptr solver. |
The benchmark of Fiorentini et al. (1996) on the Deutsche Mark British Pound returns is based on a GARCH(1,1) model with a constant in the conditional mean equation, and normally distributed errors.
An object of class “benchmark.fcp” which has a “as_flextable” method for nice printing of the results.
Fiorentini G, Calzolari G, Panattoni L (1996). “Analytic derivatives and the computation of GARCH estimates.” Journal of Applied Econometrics, 11(4), 399–417.
The APARCH(1,1) benchmark of Laurent (2003).
benchmark_laurent(control = nloptr_fast_options())
benchmark_laurent(control = nloptr_fast_options())
control |
control arguments for the nloptr solver. |
The benchmark of Laurent (2003) on the Nikkei daily log returns is based on an APARCH(1,1) model with a constant in the conditional mean equation, and normally distributed errors.
An object of class “benchmark.aparch” which has a “as_flextable” method for nice printing of the results.
Laurent S (2004). “Analytical derivates of the APARCH model.” Computational Economics, 24, 51–57.
Extract the BIC from an estimated model.
## S3 method for class 'tsgarch.estimate' BIC(object, ...)
## S3 method for class 'tsgarch.estimate' BIC(object, ...)
object |
an object of class “tsgarch.estimate”. |
... |
not currently used. |
A numeric value.
Bread Method
## S3 method for class 'tsgarch.estimate' bread(x, ...)
## S3 method for class 'tsgarch.estimate' bread(x, ...)
x |
an object of class “tsgarch.estimate”. |
... |
not currently used. |
The analytic hessian of the model.
Alexios Galanos
Extract the estimated coefficients of a model.
## S3 method for class 'tsgarch.estimate' coef(object, ...)
## S3 method for class 'tsgarch.estimate' coef(object, ...)
object |
an object of class “tsgarch.estimate”. |
... |
not currently used. |
A numeric named vector of estimated coefficients.
Confidence Intervals for Model Parameters
## S3 method for class 'tsgarch.estimate' confint(object, parm, level = 0.95, vcov_type = "H", ...)
## S3 method for class 'tsgarch.estimate' confint(object, parm, level = 0.95, vcov_type = "H", ...)
object |
an object of class tsgarch.estimate. |
parm |
a specification of which parameters are to be given confidence intervals, either a vector of numbers or a vector of names. If missing, all parameters are considered. |
level |
the confidence level required. |
vcov_type |
valid choices are “H” for using the analytic hessian for the bread, “OP” for the outer product of gradients, “QMLE” for the Quasi-ML sandwich estimator (Huber-White), and “NW” for the Newey-West adjusted sandwich estimator (a HAC estimator). |
... |
additional parameters passed to the Newey-West bandwidth function to determine the optimal lags. |
A matrix (or vector) with columns giving lower and upper confidence limits for each parameter. These will be labelled as (1-level)/2 and 1 - (1-level)/2 in % (by default 2.5% and 97.5%).
The Bollerslev-Ghysel benchmark dataset. The variables in the data set are the daily percentage nominal returns computed as 100
, where Pt is the bilateral Deutschemark/British pound rate constructed from the corresponding U.S. dollar rates, and a dummy variable that takes the value of 1 on Mondays and other days following no trading in the Deutschemark or British pound/ U.S. dollar market during regular European trading hours, and 0 otherwise. The data spans the period from 1984-01-03 through 1991-12-31, but exact dates are not known as this dataset did not provide an index. This dataset is included as it is used for the GARCH benchmark.
dmbp
dmbp
dmbp
A data.frame containing 2x1974 observations
The exchange rate
Dummy indicator (see descriptiom)
Journal of Business & Economic Statistics Data Archive
Score Method
## S3 method for class 'tsgarch.estimate' estfun(x, ...)
## S3 method for class 'tsgarch.estimate' estfun(x, ...)
x |
an object of class “tsgarch.estimate”. |
... |
not currently used. |
The function returns the scores of the negative of the log likelihood at the optimal solution. The scores are from the second pass of the optimizer using scaling and hence represent the scaled scores. These are then rescaled before returning the matrix.
The score matrix
Alexios Galanos
Estimates an GARCH model given a specification object using maximum likelihood and autodiff
## S3 method for class 'tsgarch.spec' estimate( object, solver = "nloptr", control = NULL, stationarity_constraint = 0.999, keep_tmb = FALSE, ... ) ## S3 method for class 'tsgarch.multispec' estimate( object, solver = "nloptr", control = NULL, stationarity_constraint = 0.999, keep_tmb = FALSE, ... )
## S3 method for class 'tsgarch.spec' estimate( object, solver = "nloptr", control = NULL, stationarity_constraint = 0.999, keep_tmb = FALSE, ... ) ## S3 method for class 'tsgarch.multispec' estimate( object, solver = "nloptr", control = NULL, stationarity_constraint = 0.999, keep_tmb = FALSE, ... )
object |
an object of class “tsgarch.spec” or “tsgarch.multispec” |
solver |
only “nloptr” is currently supported (see |
control |
solver control parameters. |
stationarity_constraint |
the bound on the inequality constraint for ensuring the stationary of the GARCH process (see details). |
keep_tmb |
whether to save and return the TMB object. This is can be used for example when passing different parameters to the model to extract a new output set given the same dataset (used in “tsmarch” package for calculating partitioned standard errors). The downside is that it can increase the size of the returned object by a factor of 8. |
... |
not currently used. |
The underlying code is written using the TMB framework which uses automatic differentiation and hence allows the generation of analytic derivatives.
Stationarity is usually based on the condition that the persistence of the model is less than 1. The argument “stationarity_constraint” allows to fine tune this. For example, setting it to a very high value will effectively render this constraint inactive. The default of 0.999 has been found to be a reasonable bound since values close to one may lead to problems.
Since the nloptr solver make use of analytic Jacobians for the inequality constraint, these are either provided in closed form or calculated as part of the automatic differentiation algorithms implemented in the package.
The estimation makes 2 passes to the solver. The first pass uses no parameter scaling, whilst in the second pass the parameters (as well as bounds) are scaled making use of the estimated hessian from the first pass in order to generate a hopefully more robust solution.
For the multiple specification estimation, parallel functionality is available through
the future_lapply
function. The user needs to setup a
plan
in order to make use of this.
An object of class “tsgarch.estimate” or “tsgarch.multi_estimate”.
Alexios Galanos
Extract the fitted values of the estimated model.
## S3 method for class 'tsgarch.estimate' fitted(object, ...) ## S3 method for class 'tsgarch.multi_estimate' fitted(object, ...)
## S3 method for class 'tsgarch.estimate' fitted(object, ...) ## S3 method for class 'tsgarch.multi_estimate' fitted(object, ...)
object |
an object of class “tsgarch.estimate” or “tsgarch.multi_estimate”. |
... |
not currently used. |
An xts vector of the fitted values for the univariate type objects. In the case of a multi-estimate object, a list of xts vectors is returned if the individual univariate objects have unequal indices, else an xts matrix is returned.
Specifies a GARCH model prior to estimation.
garch_modelspec( y, model = "garch", constant = FALSE, order = c(1, 1), variance_targeting = FALSE, vreg = NULL, multiplicative = FALSE, init = c("unconditional", "sample", "backcast"), backcast_lambda = 0.7, sample_n = 10, distribution = "norm", ... )
garch_modelspec( y, model = "garch", constant = FALSE, order = c(1, 1), variance_targeting = FALSE, vreg = NULL, multiplicative = FALSE, init = c("unconditional", "sample", "backcast"), backcast_lambda = 0.7, sample_n = 10, distribution = "norm", ... )
y |
an xts vector. |
model |
the type of GARCH model. Valid choices are “garch” for vanilla GARCH, “gjr” for asymmetric GARCH, “egarch” for exponential GARCH, “aparch” for asymmetric power ARCH, “csGARCH” for the component GARCH, “igarch” for the integrated GARCH. |
constant |
whether to estimate a constant (mean) for y, |
order |
the (p,q) GARCH order. |
variance_targeting |
whether to use variance targeting rather than estimating the conditional variance intercept. |
vreg |
an optional xts matrix of regressors in the conditional variance equation. |
multiplicative |
whether to exponentiate the contribution of the regressors else will be additive. In the case of the “egarch” model, since this is already a multiplicative model, the regressors are additive irrespective of the choice made. |
init |
the method to use to initialize the recursion of the conditional variance. |
backcast_lambda |
the decay power for the exponential smoothing used when initializing the recursion using the backcast method. |
sample_n |
the number of data points to use when initializing the recursion using the sample method. |
distribution |
a valid distribution from the available re-parameterized distributions of the package. |
... |
not used. |
The specification object holds the information and data which is then passed to the maximum likelihood estimation routines.
An object of class “tsgarch.spec”.
Alexios Galanos
Calculates and returns the half-life of a model.
## S3 method for class 'tsgarch.estimate' halflife(object, ...)
## S3 method for class 'tsgarch.estimate' halflife(object, ...)
object |
an object. |
... |
not currently used. |
The half life is defined as the period it
takes a series to reach half its long-term average values. For a GARCH model
this is defined as where P is the persistence.
a numeric value representing the half life in periods based on the frequency of the underlying data.
Extract the log likelihood of the model at the estimated optimal parameter values.
## S3 method for class 'tsgarch.estimate' logLik(object, ...)
## S3 method for class 'tsgarch.estimate' logLik(object, ...)
object |
an object of class “tsgarch.estimate”. |
... |
not currently used. |
An object of class “logLik” with attributes for “nobs” and “df”. The latter is equal to the number of estimated parameters plus 1 (the variance initialization value).
General method the news impact of a model
newsimpact(object, epsilon = NULL, ...) ## S3 method for class 'tsgarch.estimate' newsimpact(object, epsilon = NULL, ...)
newsimpact(object, epsilon = NULL, ...) ## S3 method for class 'tsgarch.estimate' newsimpact(object, epsilon = NULL, ...)
object |
an object of class “tsgarch.estimate”. |
epsilon |
a user supplied zero mean noise vector. If this is NULL then a vector is created from the actual data using the minimum and maximum range. |
... |
additional parameters passed to the method. |
An object of class “tsgarch.newsimpact”.
The method does not support higher order GARCH models.
The daily log returns in percent of the NIKKEI stock index spanning the period 1984-01-04 to 2000-12-22. In the original dataset there was a duplicate date on 2000-08-31 (but with a different value). Therefore, in order to correct this we have moved up the duplicate 2000-08-31 to become 2000-09-01, and the 2000-09-01 to 2000-09-02. Since the next date after this was 2000-09-04, no further adjustments were made. These changes preserve the original data in the order they appeared, with a minimal adjustment only to the index which has no impact on estimation, but avoiding internal warnings which arise on checks to the index. This dataset is included as it is used for the APARCH benchmark.
nikkei
nikkei
nikkei
A data.frame containing 4246 observations in 2 columns:
The string date in YYYY-MM-DD format.
The daily log returns
Journal of Applied Econometrics Data Archive 2003-v18.6/giot-laurent from the paper “Value-at-Risk for Long and Short Trading Positions” by Giot, Pierre and Sebastien Laurent, 2003, Journal of Applied Econometrics, 18(6), pp. 641–664.
Default options for nloptr solver
nloptr_fast_options( trace = FALSE, xtol_rel = 1e-14, maxeval = 1000, xtol_abs = 1e-12 ) nloptr_global_options( trace = FALSE, xtol_rel = 1e-14, maxeval = 1000, xtol_abs = 1e-12 )
nloptr_fast_options( trace = FALSE, xtol_rel = 1e-14, maxeval = 1000, xtol_abs = 1e-12 ) nloptr_global_options( trace = FALSE, xtol_rel = 1e-14, maxeval = 1000, xtol_abs = 1e-12 )
trace |
equivalent to option “print_level” for nloptr. High values results in more details. |
xtol_rel |
Stop when an optimization step (or an estimate of the optimum) changes every parameter by less than xtol_rel multiplied by the absolute value of the parameter. |
maxeval |
top when the number of function evaluations exceeds maxeval. This is not a strict maximum: the number of function evaluations may exceed maxeval slightly, depending upon the algorithm |
xtol_abs |
is a vector of length n (the number of elements in x) giving the tolerances: stop when an optimization step (or an estimate of the optimum) changes every parameter x(i) by less than xtol_abs(i). |
These as just a set of pre-created defaults which work well, particularly the “nloptr_fast_options” which uses an SQP solver. nloptr has many other solvers and combination of solvers which can be used. However, keep in mind that the solver must accept analytic derivatives as well as nonlinear inequality constraints.
A list with options which can be passed to the solver.
Extract the number of observations from an estimated model. This is principally intended to be used in computing BIC and used in other tidy methods
## S3 method for class 'tsgarch.estimate' nobs(object, ...)
## S3 method for class 'tsgarch.estimate' nobs(object, ...)
object |
an object of class “tsgarch.estimate”. |
... |
not currently used. |
A numeric value.
Returns the intercept of a GARCH model.
omega(object, ...) ## S3 method for class 'tsgarch.estimate' omega(object, ...) ## S3 method for class 'tsgarch.spec' omega(object, ...)
omega(object, ...) ## S3 method for class 'tsgarch.estimate' omega(object, ...) ## S3 method for class 'tsgarch.spec' omega(object, ...)
object |
an object. |
... |
additional parameters passed to the method. |
The intercept is either estimated directly as part of the model else indirectly if variance targeting was selected.
a numeric value representing the value of the intercept.
General method the persistence of a model.
persistence(object, ...) ## S3 method for class 'tsgarch.estimate' persistence(object, ...) ## S3 method for class 'tsgarch.spec' persistence(object, ...)
persistence(object, ...) ## S3 method for class 'tsgarch.estimate' persistence(object, ...) ## S3 method for class 'tsgarch.spec' persistence(object, ...)
object |
an object of some class. |
... |
additional parameters passed to the method. |
The persistence of the estimated model. For GARCH models, the formulation varies by the type of model. See the vignette for more details.
Calculates and returns the conditional probability integral transform given the data and estimated density
## S3 method for class 'tsgarch.estimate' pit(object, ...)
## S3 method for class 'tsgarch.estimate' pit(object, ...)
object |
an object. |
... |
not currently used. |
The PIT is essentially the probabilities returned from the cumulative distribution function (*p) given the data and estimated value of the mean, conditional standard deviation and any other distributional parameters.
An xts vector of the conditional probabilities.
Plot method for “tsgarch.estimate” class.
## S3 method for class 'tsgarch.estimate' plot(x, y = NULL, ...)
## S3 method for class 'tsgarch.estimate' plot(x, y = NULL, ...)
x |
an object of class “tsgarch.estimate”. |
y |
not used. |
... |
not used. |
a panel with plots for the estimated sigma value, the news impact curve and a “QQ” plot of the standardized residuals.
Plot method for newsimpact class.
## S3 method for class 'tsgarch.newsimpact' plot(x, y = NULL, ...)
## S3 method for class 'tsgarch.newsimpact' plot(x, y = NULL, ...)
x |
an object of class “tsgarch.newsimpact”. |
y |
not used. |
... |
additional arguments pass to |
a plot of the newsimpact curve
Prediction function for class “tsgarch.estimate”.
## S3 method for class 'tsgarch.estimate' predict( object, h = 1, newxreg = NULL, newvreg = NULL, nsim = 0, sim_method = c("parametric", "bootstrap"), block = 1, forc_dates = NULL, init_states = NULL, seed = NULL, ... )
## S3 method for class 'tsgarch.estimate' predict( object, h = 1, newxreg = NULL, newvreg = NULL, nsim = 0, sim_method = c("parametric", "bootstrap"), block = 1, forc_dates = NULL, init_states = NULL, seed = NULL, ... )
object |
an object of class “tsgarch.estimate”. |
h |
the forecast horizon. |
newxreg |
not currently used, |
newvreg |
variance regressors rows equal to h. This can be either a numeric or xts matrix. Only needed if the model was estimated with regressors in the variance equation. |
nsim |
the number of simulations to use for generating the simulated predictive distribution. Defaults to zero (no simulated distribution). |
sim_method |
the simulation method to use when nsim great than zero. The “parametric” method samples from the model distribution whilst the “bootstrap” from the standardized model residuals. |
block |
for the “bootstrap” sim_method, this allows to generate block length samples (defaults to 1). |
forc_dates |
an optional vector of forecast dates equal to h. If NULL will use the implied periodicity of the data to generate a regular sequence of dates after the last available date in the data. |
init_states |
an optional vector of states to initialize the forecast. If NULL, will use the last available state from the estimated model. This must be equal to the max of the ARCH and GARCH terms. |
seed |
an integer that will be used in a call to set.seed before simulating. |
... |
additional arguments for future expansion options. |
The bootstrap method considered here, is based on re-sampling innovations from the empirical distribution of the fitted GARCH model to generate future realizations of the series and sigma. This only considers distributional uncertainty and will not generate prediction intervals for the 1-step ahead sigma forecast for which only the parameter uncertainty is relevant in GARCH type models (and not currently implemented). When the horizon h is equal to 1, no simulation is performaed since there is no uncertainty to account for.
A “tsgarch.predict” object.
Pascual,L., Romo,J., Ruiz,E. (2006). “Bootstrap prediction for returns and volatilities in GARCH models.” Computational Statistics & Data Analysis, 50(9), 2293–2312.
Print method for class “summary.tsgarch.estimate”
## S3 method for class 'summary.tsgarch.estimate' print( x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), ... )
## S3 method for class 'summary.tsgarch.estimate' print( x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), ... )
x |
an object of class “summary.tsgarch.estimate”. |
digits |
integer, used for number formatting. Optionally, to avoid scientific notation, set ‘options(scipen=999)’. |
signif.stars |
logical. If TRUE, ‘significance stars’ are printed for each coefficient. |
... |
not currently used. |
Invisibly returns the original summary object.
Print method for class “summary.tsgarch.profile”
## S3 method for class 'summary.tsgarch.profile' print(x, digits = max(3L, getOption("digits") - 3L), ...)
## S3 method for class 'summary.tsgarch.profile' print(x, digits = max(3L, getOption("digits") - 3L), ...)
x |
an object of class “summary.tsgarch.estimate.profile”. |
digits |
integer, used for number formatting. Optionally, to avoid scientific notation, set ‘options(scipen=999)’. |
... |
not currently used. |
Invisibly returns the original summary object.
Extract the residuals of the estimated model.
## S3 method for class 'tsgarch.estimate' residuals(object, standardize = FALSE, ...) ## S3 method for class 'tsgarch.multi_estimate' residuals(object, standardize = FALSE, ...)
## S3 method for class 'tsgarch.estimate' residuals(object, standardize = FALSE, ...) ## S3 method for class 'tsgarch.multi_estimate' residuals(object, standardize = FALSE, ...)
object |
an object of class “tsgarch.estimate” or “tsgarch.multi_estimate”. |
standardize |
logical. Whether to standardize the residuals by the conditional volatility. |
... |
not currently used. |
An xts vector of the model residuals for the univariate type objects. In the case of a multi-estimate object, a list of xts vectors is returned if the individual univariate objects have unequal indices, else an xts matrix is returned. Note that If the model had no constant in the conditional mean equation then this just returns the original data (which is assumed to be zero mean noise).
Extract the conditional standard deviation from a GARCH model.
## S3 method for class 'tsgarch.estimate' sigma(object, ...) ## S3 method for class 'tsgarch.multi_estimate' sigma(object, ...)
## S3 method for class 'tsgarch.estimate' sigma(object, ...) ## S3 method for class 'tsgarch.multi_estimate' sigma(object, ...)
object |
an object of class “tsgarch.estimate”, “tsgarch.predict”, “tsgarch.simulate” or a “tsgarch.multi_estimate”. |
... |
not currently used. |
An xts vector of the conditional volatility for the univariate type objects. In the case of a multi-estimate object, a list of xts vectors is returned if the individual univariate objects have unequal indices, else an xts matrix is returned.
Simulates paths of a GARCH model.
## S3 method for class 'tsgarch.spec' simulate( object, nsim = 1, seed = NULL, h = 1000, var_init = NULL, innov = NULL, innov_init = NULL, vreg = NULL, burn = 0, ... )
## S3 method for class 'tsgarch.spec' simulate( object, nsim = 1, seed = NULL, h = 1000, var_init = NULL, innov = NULL, innov_init = NULL, vreg = NULL, burn = 0, ... )
object |
an object of class “tsgarch.spec”. |
nsim |
the number of sample paths to generate. |
seed |
an integer that will be used in a call to set.seed before simulating. |
h |
the number of time steps to simulate paths for. |
var_init |
the seed value for initializing the variance equation recursion. If NULL, the variance target value is used based on the supplied parameters. This should be a vector and assumes all sample paths are seeded the same way. |
innov |
an optional matrix of dimensions nsim by h of zero mean unit variance (standardized) innovations which will be used instead of the model distribution for simulation. No checks are performed on whether the supplied values are standardized. |
innov_init |
an optional vector of initialization values for the standardized innovations. This allows the seeding of the initial innovations with user supplied values (useful when simulating forward from an existing model for the purpose of continuing the modeled series from some fixed point). |
vreg |
an optional vector of length h representing any pre-multiplied variance regressors to use in the simulation. |
burn |
burn in. Will be discarded before returning the output. |
... |
for aparch, fgarch, egarch and gjrgarch models, an optional vector of length max(q,p) with values for initializing the ARCH equation and named “arch_initial”. This is mostly used for validation purposes. The “arch_initial” value is always returned by an estimated object. |
Once a GARCH model is specified via garch_modelspec
,
the slot “parmatrix” contains initial values for the parameters
which can be used to set them to any value for the simulation. This matrix
as well as details of the model (type, order, distribution) are the only
pieces of information used in the simulation. The “vreg” argument in
the spec will be ignored. Instead, the user can supply a pre-multiplied vector
to the simulate function which will be used. Note that the “multiplicative”
argument in the specification will be used in this case to determine how the
regressors enter the conditional variance equation. While the “innov”
argument must be a matrix, all other values are vectors and assume that they
will be the same across all sample paths. If the user wants to assign different values
for arguments “var_init”, “innov_init” and “vreg”, then
the simulate method should be called multiple times.
An object of class “tsgarch.simulate” with slots for the simulated sigma and series simulated distributions which are each of class “tsmodel.distribution”. The simulated error (not returned) is equal to the simulated series less the mean equation constant if not equal to zero.
Summary method for class “tsgarch.estimate”
## S3 method for class 'tsgarch.estimate' summary(object, digits = 4, vcov_type = "H", include_persistence = TRUE, ...)
## S3 method for class 'tsgarch.estimate' summary(object, digits = 4, vcov_type = "H", include_persistence = TRUE, ...)
object |
an object of class “tsgarch.estimate”. |
digits |
integer, used for number formatting. Optionally, to avoid scientific notation, set ‘options(scipen=999)’. |
vcov_type |
the type of standard errors based on the vcov estimate (see |
include_persistence |
whether to include the estimate of the persistence and
its calculated standard errors (calculated using the |
... |
not currently used. |
A list with summary information of class “summary.tsgarch.estimate”.
Summary method for class “tsgarch.profile”
## S3 method for class 'tsgarch.profile' summary(object, digits = 4, measure = "RMSE", ...)
## S3 method for class 'tsgarch.profile' summary(object, digits = 4, measure = "RMSE", ...)
object |
an object of class “tsgarch.profile”. |
digits |
integer, used for number formatting. Optionally, to avoid scientific notation, set ‘options(scipen=999)’. |
measure |
either one of the included measure in the summary slot of the returned object, which currently includes the relative error measures “RMSE”, “MAE”, “MAPE”, summary measures on the estimated values “MEAN”, “MEDIAN”, “P20” and “P80”, else any other user calculated measure which has been generated in the summary table post processing. |
... |
not currently used. |
A list with summary information of class “summary.tsgarch.profile”.
Convert a list of tsgarch.estimate objects to a multi_estimate object
to_multi_estimate(object, ...)
to_multi_estimate(object, ...)
object |
an list with “tsgarch.estimate” objects. |
... |
none |
This is a convenience method which provides the flexibility to manually estimate each series and then convert the list of these objects to a multi-estimation object, rather than having to use the estimate method on a multi-specification object.
a validated object of class “tsgarch.multi_estimate”.
Alexios Galanos
Generates an expanding window walk forward backtest with option for rolling the forecast by filtering (see details).
## S3 method for class 'tsgarch.spec' tsbacktest( object, start = floor(length(object$target$y_orig))/2, end = length(object$target$y_orig), h = 1, estimate_every = 1, rolling = FALSE, trace = FALSE, ... )
## S3 method for class 'tsgarch.spec' tsbacktest( object, start = floor(length(object$target$y_orig))/2, end = length(object$target$y_orig), h = 1, estimate_every = 1, rolling = FALSE, trace = FALSE, ... )
object |
an object of class “tsgarch.spec”. |
start |
numeric data index from which to start the backtest. |
end |
numeric data index on which to end the backtest. The backtest will end 1 period before that date in order to have at least 1 out of sample value to compare against. |
h |
forecast horizon. As the expanding window approaches the “end”, the horizon will automatically shrink to the number of available out of sample periods. |
estimate_every |
number of periods at which the model is re-estimated (defaults to 1). |
rolling |
this indicates whether forecasts are made only on the estimation date (FALSE) or whether to filter the data 1 period at a time and forecast from the filtered data (TRUE). |
trace |
whether to show the progress bar. The user is expected to have set up appropriate handlers for this using the “progressr” package. |
... |
not currently used. |
The rolling option allows to re-estimate the data every n periods whilst filtering the data 1-step ahead between re-estimation dates so that overlapping forecasts are generated.
A list which includes a data.table having the following columns:
estimation_date: the date at which the model was estimated.
convergence: whether both kkt1 and kkt2 were TRUE ( Kuhn Karush Tucker conditions) from the kktchk function in optimx.
filter_date: the date on which a prediction was generated. For rolling prediction this means that an estimated model was filtered for new data prior to re-predicting.
horizon: the forecast horizon of the prediction.
size: the length of the data used in estimation.
forecast_date: the date corresponding to the forecast.
mu: the conditional mean prediction.
sigma: the conditional volatility prediction.
skew: the distribution skew parameter (non-time varying hence constant across each estimation window).
shape: the distribution shape parameter (non-time varying hence constant across each estimation window).
shape: the distribution lambda parameter (non-time varying hence constant across each estimation window).
actual: the actual observation corresponding to the forecast date.
Additional slots in the list include the distribution used and other information relating to the backtest setup.
The function can use parallel functionality as long as the user has
set up a plan
using the future package.
Generates a list of model equations in LaTeX.
## S3 method for class 'tsgarch.estimate' tsequation(object, ...)
## S3 method for class 'tsgarch.estimate' tsequation(object, ...)
object |
an object of class “tsgarch.estimate”. |
... |
not currently used. |
This method is called in the summary when the format output option chosen is “flextable”.
A list of equations in LaTeX which can be used in documents. This is a list with 4 slots for the conditional distribution, the conditional volatility, the persistence and unconditional variance equations.
Filters new data based on an already estimated model or filters data based on a specification object.
## S3 method for class 'tsgarch.estimate' tsfilter(object, y = NULL, newxreg = NULL, newvreg = NULL, ...) ## S3 method for class 'tsgarch.spec' tsfilter(object, y = NULL, newxreg = NULL, newvreg = NULL, ...)
## S3 method for class 'tsgarch.estimate' tsfilter(object, y = NULL, newxreg = NULL, newvreg = NULL, ...) ## S3 method for class 'tsgarch.spec' tsfilter(object, y = NULL, newxreg = NULL, newvreg = NULL, ...)
object |
an object of class “tsgarch.estimate” or “tsgarch.spec”. |
y |
an xts vector of new values to filter. Can also be NULL in which case the |
newxreg |
not currently used, |
newvreg |
variance regressors with the same number of rows as y. This can be either a numeric or xts matrix. Only needed if the model was estimated with regressors in the variance equation. |
... |
additional arguments for future expansion. |
The method filters new data and updates the object with this new information so that it can be called recursively as new data arrives. It is also possible to use a specification object with fixed parameters, by appropriately setting the values of the “parmatrix” object in the specification slot. In this case, the returned object will also be of classs “tsgarch.estimate”. If an object of “tsgarch.spec” is used with y not NULL, then the method will first filter the values of the data in the object, generating an object of “tsgarch.estimate” and then call the method again on this new object and the new y values (and optionally any newvreg values). In this way, using either object classes will return the exact same results. The timestamp indices of y must be strictly greater than the maximum timestamp index of the data within the object (i.e. we only filter on new data).
A “tsgarch.estimate” object with updated information.
Profiles the model parameters under the assumptions of the model.
## S3 method for class 'tsgarch.spec' tsprofile( object, nsim = 100, sizes = c(800, 1000, 1500, 2000, 3000), var_init = NULL, seed = NULL, burn = 0, trace = FALSE, ... )
## S3 method for class 'tsgarch.spec' tsprofile( object, nsim = 100, sizes = c(800, 1000, 1500, 2000, 3000), var_init = NULL, seed = NULL, burn = 0, trace = FALSE, ... )
object |
an object of class “tsgarch.spec” with pre-set parameters. |
nsim |
the number of paths to generate. |
sizes |
a vector of data sizes for which to simulate and estimate. |
var_init |
the variance to use to initialize the simulation. |
seed |
an object specifying if and how the random number generator should be initialized. See the simulate documentation for more details. |
burn |
burn in samples. |
trace |
whether to show the progress bar. The user is expected to have set up appropriate handlers for this using the “progressr” package. |
... |
not currently used. |
The function profiles the parameters of a model by simulating and then estimating multiple paths from the assumed DGP. This makes it possible to obtain a better understanding of the convergence properties (RMSE) of each parameter under different data sizes.
An object of class “tsgarch.profile”.
The function can use parallel functionality as long as the user has set
up a plan
using the future package.
External regressors are not supported at this time and an error will occur
if persent in the specification.
Unconditional value of a GARCH model variance.
## S3 method for class 'tsgarch.estimate' unconditional(object, ...) ## S3 method for class 'tsgarch.spec' unconditional(object, ...)
## S3 method for class 'tsgarch.estimate' unconditional(object, ...) ## S3 method for class 'tsgarch.spec' unconditional(object, ...)
object |
an object of class “tsgarch.estimate” or “tsgarch.spec”. |
... |
not currently used. |
For some models, there is no closed form solution available for the unconditional variance of higher order model (e.g. GARCH(2,1)) in which case a simulation based approach is adopted to approximate the value.
A numeric vector of length 1 of the unconditional variance of the model.
The Covariance Matrix of the Estimated Parameters
## S3 method for class 'tsgarch.estimate' vcov(object, adjust = FALSE, type = c("H", "OP", "QMLE", "NW"), ...)
## S3 method for class 'tsgarch.estimate' vcov(object, adjust = FALSE, type = c("H", "OP", "QMLE", "NW"), ...)
object |
an object of class tsgarch.estimate. |
adjust |
logical. Should a finite sample adjustment be made? This amounts to multiplication with n/(n-k) where n is the number of observations and k the number of estimated parameters. |
type |
valid choices are “H” for using the analytic hessian for the bread, “OP” for the outer product of gradients, “QMLE” for the Quasi-ML sandwich estimator (Huber-White), and “NW” for the Newey-West adjusted sandwich estimator (a HAC estimator). |
... |
additional parameters passed to the Newey-West bandwidth function to determine the optimal lags. |
The variance-covariance matrix of the estimated parameters.