Type: | Package |
Title: | Flexible and Robust GARCH-X Modelling |
Version: | 1.6 |
Date: | 2025-07-09 |
Author: | Genaro Sucarrat |
Maintainer: | Genaro Sucarrat <gsucarrat@gmail.com> |
Description: | Flexible and robust estimation and inference of Generalised Autoregressive Conditional Heteroscedasticity (GARCH) models with covariates ('X') based on the results by Francq and Thieu (2019) <doi:10.1017/S0266466617000512>. Coefficients can straightforwardly be set to zero by omission, and quasi maximum likelihood methods ensure estimates are generally consistent and inference valid, even when the standardised innovations are non-normal and/or dependent over time. See <doi:10.32614/RJ-2021-057> for an overview of the package. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
Depends: | R (≥ 3.4.0), methods, zoo |
Suggests: | tvgarch, lgarch |
BugReports: | https://github.com/gsucarrat/garchx/issues |
URL: | https://www.sucarrat.net/ |
NeedsCompilation: | yes |
Packaged: | 2025-07-09 15:38:12 UTC; sucarrat |
Repository: | CRAN |
Date/Publication: | 2025-07-09 18:00:02 UTC |
Flexible and Robust GARCH-X Modelling
Description
Flexible and robust estimation and inference of GARCH(q,p,r)-X models, where q is the GARCH order, p is the ARCH order, r is the asymmetry or leverage order, and 'X' indicates that covariates can be included. Suitable subsets of the coefficients can be restriced to zero by omission, and Quasi Maximum Likelihood (QML) methods ensure estimates are generally consistent, even when the standardised innovations are non-normal and/or dependent.
Details
Package: | garchx |
Type: | Package |
Version: | 1.6 |
Date: | 2025-07-09 |
License: | GPL-2 |
Author(s)
Genaro Sucarrat, https://www.sucarrat.net/
Maintainer: Genaro Sucarrat
See Also
garchxSim
, coef
, fitted
, logLik
, print
, residuals
, vcov
Examples
##simulate from a garch(1,1):
set.seed(123)
y <- garchxSim(1000)
##estimate garch(1,1) model:
mymod <- garchx(y)
mymod
Extraction functions for 'garchx' objects
Description
Extraction functions for objects of class 'garchx'
Usage
## S3 method for class 'garchx'
coef(object, ...)
## S3 method for class 'garchx'
confint(object, parm, level = 0.95, ...)
## S3 method for class 'garchx'
fitted(object, as.zoo = TRUE, ...)
## S3 method for class 'garchx'
logLik(object, ...)
## S3 method for class 'garchx'
nobs(object, ...)
## S3 method for class 'garchx'
predict(object, n.ahead = 10, newxreg = NULL,
newindex = NULL, n.sim = NULL, verbose = FALSE, ...)
## S3 method for class 'garchx'
print(x, ...)
## S3 method for class 'garchx'
quantile(x, probs=0.025, names = TRUE, type = 7, as.zoo = TRUE, ...)
## S3 method for class 'garchx'
residuals(object, as.zoo = TRUE, ...)
## S3 method for class 'garchx'
toLatex(object, digits = 4, ...)
## S3 method for class 'garchx'
vcov(object, vcov.type = NULL, ...)
Arguments
object |
an object of class 'garchx' |
x |
an object of class 'garchx' |
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 |
|
as.zoo |
logical. If |
n.ahead |
|
newxreg |
|
newindex |
|
n.sim |
|
verbose |
|
probs |
|
names |
|
type |
|
digits |
|
vcov.type |
|
... |
additional arguments |
Value
coef: |
numeric vector containing parameter estimates |
confint: |
A matrix lower and upper confidence limits for each parameter |
fitted: |
fitted conditional variance |
logLik: |
log-likelihood (normal density) |
nobs: |
the number of observations used in the estimation |
predict: |
a |
print: |
print of the estimation results |
quantile: |
the fitted quantiles, i.e. the conditional standard deviation times the empirical quantile of the standardised innovations |
residuals: |
standardised residuals |
vcov: |
coefficient variance-covariance matrix |
Author(s)
Genaro Sucarrat, https://www.sucarrat.net/
References
Christian Francq and Le Quien Thieu (2019): 'QML inference for volatility models with covariates', Econometric Theory 35, pp. 37-72, doi:10.1017/S0266466617000512 Robert M. de Jong and James Davidson (2000): 'Consistency of Kernel Estimators of Heteroscedastic and Autocorrelated Covariance Matrices', Econometrica 68, pp. 407-423
See Also
Examples
##simulate from a garch(1,1):
set.seed(123)
y <- garchxSim(1000)
##estimate garch(1,1) model:
mymod <- garchx(y)
##print estimation results:
print(mymod)
##extract coefficients:
coef(mymod)
##extract and store conditional variances:
sigma2hat <- fitted(mymod)
##extract log-likelihood:
logLik(mymod)
##extract and store standardised residuals:
etahat <- residuals(mymod)
##extract coefficient variance-covariance matrix:
vcov(mymod)
##generate predictions:
predict(mymod)
Estimate a GARCH-X model
Description
Quasi Maximum Likelihood (ML) estimation of a GARCH(q,p,r)-X model, where q is the GARCH order, p is the ARCH order, r is the asymmetry (or leverage) order and 'X' indicates that covariates can be included. Note that the underlying estimation theory assumes the covariates are stochastic. The estimation procedure will, in general, provide consistent estimates when the standardised innovations are not normal or independent (or both), see Francq and Thieu (2018).
Usage
garchx(y, order = c(1,1), arch = NULL, garch = NULL, asym = NULL,
xreg = NULL, vcov.type = c("ordinary", "robust", "hac"),
initial.values = NULL, backcast.values = NULL, lower = 0,
upper = +Inf, control = list(), hessian.control = list(),
solve.tol = .Machine$double.eps, estimate = TRUE, c.code = TRUE,
penalty.value = NULL, sigma2.min = .Machine$double.eps,
objective.fun = 1, turbo = FALSE)
Arguments
y |
numeric vector, time-series or |
order |
integer vector of length 1, 2 or 3, for example |
arch |
|
garch |
|
asym |
|
xreg |
numeric vector, time-series or |
vcov.type |
|
initial.values |
|
backcast.values |
|
lower |
numeric vector, either of length 1 or the number of parameters to be estimated, see |
upper |
numeric vector, either of length 1 or the number of parameters to be estimated, see |
control |
|
hessian.control |
|
solve.tol |
numeric value passed on to the |
estimate |
logical, if |
c.code |
logical, if |
penalty.value |
|
sigma2.min |
numeric with default |
objective.fun |
numeric, either 1 or 0 |
turbo |
logical. If |
Value
A list of class 'garchx'
Author(s)
Genaro Sucarrat, https://www.sucarrat.net/
References
Christian Francq and Le Quien Thieu (2019): 'QML inference for volatility models with covariates', Econometric Theory 35, pp. 37-72, doi:10.1017/S0266466617000512 Christian Francq and Jean-Michel Zakoian (2019): 'GARCH Models', 2nd Edition, Wiley Robert M. de Jong and James Davidson (2000): 'Consistency of Kernel Estimators of Heteroscedastic and Autocorrelated Covariance Matrices', Econometrica 68, pp. 407-423
See Also
garchxSim
, nlminb
, optimHess
, coef.garchx
Examples
##simulate from a garch(1,1):
set.seed(123)
y <- garchxSim(1000)
##estimate garch(1,1) model:
mymod <- garchx(y)
##print estimation results:
print(mymod)
##extract coefficients:
coef(mymod)
##extract and store conditional variances:
sigma2hat <- fitted(mymod)
##extract log-likelihood:
logLik(mymod)
##extract and store standardised residuals:
etahat <- residuals(mymod)
##extract variance-covariance matrix:
vcov(mymod)
##generate predictions:
predict(mymod)
Asymptotic Coefficient Covariance
Description
Compute the asymptotic coefficient-covariance of a GARCH(q,p,r)-X model by simulation. Note that the principles of how to use the arch
, garch
, asym
and xreg
arguments are the same as those of garchx
Usage
garchxAvar(pars, arch = NULL, garch = NULL, asym = NULL,
xreg = NULL, vcov.type = c("ordinary", "robust", "hac"),
innovations = NULL, Eeta4 = NULL, n = 1e+06, objective.fun = 1,
seed = NULL)
Arguments
pars |
|
arch |
|
garch |
|
asym |
|
xreg |
|
vcov.type |
|
innovations |
|
Eeta4 |
|
n |
integer, the number of observations to use in the simulations |
objective.fun |
integer equal to 1 or 0 that determines the type of objective function to use, see the code of |
seed |
|
Value
A matrix
Author(s)
Genaro Sucarrat, https://www.sucarrat.net/
References
Christian Francq and Le Quien Thieu (2018): 'QML inference for volatility models with covariates', Econometric Theory, doi:10.1017/S0266466617000512 Christian Francq and Jean-Michel Zakoian (2019): 'GARCH Models', 2nd Edition, Wiley
See Also
garchx
, garchxSim
, vcov.garchx
Examples
##asymptotic coefficient-covariance of a garch(1,1)
##note: the estimate is rough, since n is small
intercept <- 0.2
alpha <- 0.1
beta <- 0.8
pars <- c(intercept, alpha, beta)
seed <- 123 #for reproducibility
garchxAvar(pars, arch=1, garch=1, n=10000, seed=seed)
Auxiliary functions
Description
Auxiliary functions used in estimation. Not intended for the average user
Usage
garchxObjective(pars, aux)
garchxRecursion(pars, aux)
Arguments
pars |
numeric vector of parameters |
aux |
Value
garchxObjective: |
value of the objective function |
garchxRecursion: |
fitted conditional variance |
Author(s)
Genaro Sucarrat, https://www.sucarrat.net/
See Also
garchx
, fitted.garchx
, residuals.garchx
Simulate from a GARCH-X model
Description
Simulate from a GARCH(q,p,r)-X model. Optionally, if verbose=TRUE
, the conditional variance and innovations are also returned.
Usage
garchxSim(n, intercept = 0.2, arch = 0.1, garch = 0.8, asym = NULL, xreg = NULL,
innovations = NULL, backcast.values = list(), verbose = FALSE, as.zoo = TRUE,
c.code = TRUE)
Arguments
n |
integer |
intercept |
numeric |
arch |
|
garch |
|
asym |
|
xreg |
|
innovations |
|
backcast.values |
|
verbose |
|
as.zoo |
|
c.code |
|
Value
a numeric vector or matrix with the simulated values.
Author(s)
Genaro Sucarrat, https://www.sucarrat.net/
See Also
Examples
##simulate from a garch(1,1):
y <- garchxSim(1000)
##simulate from a garch(1,1) with asymmetry/leverage:
yy <- garchxSim(1000, asym=0.1)
##simulate from a garch(1,1) w/user-provided backcast values:
yyy <- garchxSim(1000, backcast.values=list(z2=1, sigma2=0.5))
Difference a vector or a matrix, with special treatment of zoo
objects
Description
Similar to the diff
function from the base package, but gdiff
enables padding (e.g. NA
s or 0s) of the lost entries. Contrary to the diff
function in the base package, however, the default in gdiff
is to pad (with NA
s). The gdiff
function is particularly suited for zoo
objects, since their indexing is retained
Usage
gdiff(x, lag = 1, pad = TRUE, pad.value = NA)
Arguments
x |
a numeric vector or matrix |
lag |
integer equal to the difference-length (the default is 1) |
pad |
logical. If |
pad.value |
numeric, the pad-value |
Value
A vector or matrix with the differenced values
Note
Empty
Author(s)
Genaro Sucarrat, https://www.sucarrat.net/
See Also
Examples
##1st difference of a series:
x <- rnorm(5)
gdiff(x)
##1st difference with no padding:
gdiff(x, pad=FALSE)
##1st difference retaining the original zoo-index ordering:
gdiff(as.zoo(x))
##1st difference of a matrix:
y <- matrix(rnorm(8),4,2)
gdiff(y)
##2nd difference of the same matrix:
gdiff(y, lag=2)
Lag a vector or a matrix, with special treatment of zoo
objects
Description
Similar to the lag
function from the stats
package, but glag
enables padding (e.g. NA
s or 0s) of the lost entries. Contrary to the lag
function in the stats package, however, the default in glag
is to pad (with NA
s). The glag
is particularly suited for zoo
objects, since their indexing is retained
Usage
glag(x, k = 1, pad = TRUE, pad.value = NA)
Arguments
x |
a numeric vector or matrix |
k |
integer equal to the lag (the default is 1) |
pad |
logical. If TRUE (default), then the lost entries are padded with pad.value. If FALSE, then no padding is undertaken |
pad.value |
the pad-value |
Value
A vector or matrix with the lagged values
Note
Empty
Author(s)
Genaro Sucarrat, https://www.sucarrat.net/
See Also
Examples
##lag series with NA for the missing entries:
x <- rnorm(5)
glag(x)
##lag series with no padding:
x <- rnorm(5)
glag(x, pad=FALSE)
##lag series and retain the original zoo-index ordering:
x <- as.zoo(rnorm(5))
glag(x)
##lag two periods:
glag(x, k=2)
Refit a model to new data
Description
Refit a model to new data, typically for cross-validation purposes. Re-estimation (reestimate
) is optional (the default is FALSE
).
Usage
##generic:
refit(object, ...)
##S3 method for 'garchx' objects:
## S3 method for class 'garchx'
refit(object, newy = NULL, newxreg = NULL,
backcast.value = NULL, reestimate = FALSE, ...)
Arguments
object |
an object of class |
newy |
vector, the new 'y' data, see |
newxreg |
the new 'xreg' data, if any, see |
backcast.value |
|
reestimate |
logical. If |
... |
further arguments passed to or from other methods |
Details
refit.garchx
is a convenience function to facilitate cross-validation and related analyses.
Value
A list of class 'garchx'
Author(s)
Genaro Sucarrat, https://www.sucarrat.net/
See Also
Examples
##simulate from a garch(1,1):
set.seed(123)
y <- garchxSim(1000)
##estimate garch(1,1) model:
mymod <- garchx(y)
##new data (e.g. 'out-of-sample' or 'test' data):
yy <- garchxSim(100)
##apply the estimates of 'mymod' on yy data:
refit(mymod, newy=yy)
Random number generation from the multivariate normal distribution
Description
This function is a speed-optimised version of the rmnorm
function from the mnormt package of Adelchi Azzalini (2013).
Usage
rmnorm(n, mean = NULL, vcov = 1)
Arguments
n |
integer, the number of observations to generate |
mean |
numeric vector, i.e. the mean values |
vcov |
numeric matrix, i.e. the variance-covariance matrix |
Value
A matrix of n rows
Author(s)
Genaro Sucarrat, https://www.sucarrat.net/
References
Adelchi Azzalini (2013): 'mnormt: The multivariate normal and t distributions', R package version 1.4-7, https://CRAN.R-project.org/package=mnormt
Examples
##generate from univariate standardised normal:
z1 <- rmnorm(100)
##generate from bivariate, independent standardised normal:
z2 <- rmnorm(100, vcov=diag(c(1,1)))
##generate from bivariate, dependent standardised normal:
z3 <- rmnorm(100, vcov=cbind(c(1,0.3),c(0.3,1)))
T-tests and Wald-tests under nullity
Description
The permissible parameter-space of GARCH-models is bounded from below by 0. This means non-standard inference is required when one or more parameters are 0 under the null hypothesis, a frequent situation in empirical applications. The functions ttest0
and waldtest0
perform t-tests and Wald-tests when one or more parameters is 0. In the latter test, the Wald-test, the critical values are obtained by simulation, see Francq and Thieu (2018).
Usage
ttest0(x, k = NULL)
waldtest0(x, r = 0, R = NULL, level = c(0.1,0.05,0.01),
vcov.type = NULL, quantile.type = 7, n = 20000)
Arguments
x |
an object of class 'garchx' |
k |
|
r |
|
R |
|
level |
|
vcov.type |
|
quantile.type |
integer, the algorithm used to compute the quantile, see |
n |
|
Details
The ttest0
function performs a t-test of coefficient k
with 0 as null. Under this null the parameter is on the boundary of the admissible parameter space, and so the distribution is non-standard under the null. The function ttest0
returns the result(s) of these non-standard t-test(s), see Francq and Thieu (2018). If k=NULL
, the default, then a test for each coefficient apart from the intercept is undertaken.
The waldtest0
function performs a Wald-test of the restrictions in r
, when one or more of its elements are 0, see Francq and Thieu (2018).
Value
ttest0: |
a |
waldtest0: |
a |
Author(s)
Genaro Sucarrat, https://www.sucarrat.net/
References
Christian Francq and Le Quien Thieu (2018): 'QML inference for volatility models with covariates', Econometric Theory, doi:10.1017/S0266466617000512
See Also
garchx
, quantile
, vcov.garchx
, rmnorm
Examples
##simulate and estimate a garch(1,1):
set.seed(123)
y <- garchxSim(1000)
mymod <- garchx(y)
##t-tests:
ttest0(mymod)
##wald-test:
waldtest0(mymod)