Title: | Flexible and Robust GARCH-X Modelling |
---|---|
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 (2018) <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 <https://journal.r-project.org/archive/2021/RJ-2021-057/RJ-2021-057.pdf> for an overview of the package. |
Authors: | Genaro Sucarrat [aut, cre] |
Maintainer: | Genaro Sucarrat <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.5 |
Built: | 2024-12-24 03:12:16 UTC |
Source: | https://github.com/gsucarrat/garchx |
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.
Package: | garchx |
Type: | Package |
Version: | 1.5 |
Date: | 2022-09-13 |
License: | GPL-2 |
Genaro Sucarrat, http://www.sucarrat.net/
Maintainer: Genaro Sucarrat
garchxSim
, coef
, fitted
, logLik
, print
, residuals
, vcov
##simulate from a garch(1,1): set.seed(123) y <- garchxSim(1000) ##estimate garch(1,1) model: mymod <- garchx(y) mymod
##simulate from a garch(1,1): set.seed(123) y <- garchxSim(1000) ##estimate garch(1,1) model: mymod <- garchx(y) mymod
Extraction functions for objects of class 'garchx'
## S3 method for class 'garchx' coef(object, ...) ## 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, ...)
## S3 method for class 'garchx' coef(object, ...) ## 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, ...)
object |
an object of class 'garchx' |
x |
an object of class 'garchx' |
as.zoo |
logical. If |
n.ahead |
|
newxreg |
|
newindex |
|
n.sim |
|
verbose |
|
probs |
|
names |
|
type |
|
digits |
|
vcov.type |
|
... |
additional arguments |
coef: |
numeric vector containing parameter estimates |
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 |
Genaro Sucarrat, http://www.sucarrat.net/
Christian Francq and Le Quien Thieu (2018): 'QML inference for volatility models with covariates', Econometric Theory, doi:10.1017/S0266466617000512
##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)
##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)
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).
garchx(y, order = c(1,1), arch = NULL, garch = NULL, asym = NULL, xreg = NULL, vcov.type = c("ordinary", "robust"), 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)
garchx(y, order = c(1,1), arch = NULL, garch = NULL, asym = NULL, xreg = NULL, vcov.type = c("ordinary", "robust"), 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)
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 |
A list of class 'garchx'
Genaro Sucarrat, http://www.sucarrat.net/
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
garchxSim
, nlminb
, optimHess
, coef.garchx
##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)
##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)
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
garchxAvar(pars, arch = NULL, garch = NULL, asym = NULL, xreg = NULL, vcov.type = c("ordinary", "robust"), innovations = NULL, Eeta4 = NULL, n = 1e+06, objective.fun = 1, seed = NULL)
garchxAvar(pars, arch = NULL, garch = NULL, asym = NULL, xreg = NULL, vcov.type = c("ordinary", "robust"), innovations = NULL, Eeta4 = NULL, n = 1e+06, objective.fun = 1, seed = NULL)
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 |
|
A matrix
Genaro Sucarrat, http://www.sucarrat.net/
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
garchx
, garchxSim
, vcov.garchx
##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)
##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 used in estimation. Not intended for the average user
garchxObjective(pars, aux) garchxRecursion(pars, aux)
garchxObjective(pars, aux) garchxRecursion(pars, aux)
pars |
numeric vector of parameters |
aux |
garchxObjective: |
value of the objective function |
garchxRecursion: |
fitted conditional variance |
Genaro Sucarrat, http://www.sucarrat.net/
garchx
, fitted.garchx
, residuals.garchx
Simulate from a GARCH(q,p,r)-X model. Optionally, if verbose=TRUE
, the conditional variance and innovations are also returned.
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)
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)
n |
integer |
intercept |
numeric |
arch |
|
garch |
|
asym |
|
xreg |
|
innovations |
|
backcast.values |
|
verbose |
|
as.zoo |
|
c.code |
|
a numeric vector or matrix with the simulated values.
Genaro Sucarrat, http://www.sucarrat.net/
##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))
##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))
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
gdiff(x, lag = 1, pad = TRUE, pad.value = NA)
gdiff(x, lag = 1, pad = TRUE, pad.value = NA)
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 |
A vector or matrix with the differenced values
Empty
Genaro Sucarrat, http://www.sucarrat.net/
##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)
##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)
zoo
objectsSimilar to the lag
function from the stats
package, but glag
enables padding (e.g. NAs 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
glag(x, k = 1, pad = TRUE, pad.value = NA)
glag(x, k = 1, pad = TRUE, pad.value = NA)
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 |
A vector or matrix with the lagged values
Empty
Genaro Sucarrat, http://www.sucarrat.net/
##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)
##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, typically for cross-validation purposes. Re-estimation (reestimate
) is optional (the default is FALSE
).
##generic: refit(object, ...) ##S3 method for 'garchx' objects: ## S3 method for class 'garchx' refit(object, newy = NULL, newxreg = NULL, backcast.value = NULL, reestimate = FALSE, ...)
##generic: refit(object, ...) ##S3 method for 'garchx' objects: ## S3 method for class 'garchx' refit(object, newy = NULL, newxreg = NULL, backcast.value = NULL, reestimate = FALSE, ...)
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 |
refit.garchx
is a convenience function to facilitate cross-validation and related analyses.
A list of class 'garchx'
Genaro Sucarrat, http://www.sucarrat.net/
##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)
##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)
This function is a speed-optimised version of the rmnorm
function from the mnormt package of Adelchi Azzalini (2013).
rmnorm(n, mean = NULL, vcov = 1)
rmnorm(n, mean = NULL, vcov = 1)
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 |
A matrix of n rows
Genaro Sucarrat, http://www.sucarrat.net/
Adelchi Azzalini (2013): 'mnormt: The multivariate normal and t distributions', R package version 1.4-7, https://CRAN.R-project.org/package=mnormt
##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)))
##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)))
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).
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)
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)
x |
an object of class 'garchx' |
k |
|
r |
|
R |
|
level |
|
vcov.type |
|
quantile.type |
integer, the algorithm used to compute the quantile, see |
n |
|
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).
ttest0: |
a |
waldtest0: |
a |
Genaro Sucarrat, http://www.sucarrat.net/
Christian Francq and Le Quien Thieu (2018): 'QML inference for volatility models with covariates', Econometric Theory, doi:10.1017/S0266466617000512
garchx
, quantile
, vcov.garchx
, rmnorm
##simulate and estimate a garch(1,1): set.seed(123) y <- garchxSim(1000) mymod <- garchx(y) ##t-tests: ttest0(mymod) ##wald-test: waldtest0(mymod)
##simulate and estimate a garch(1,1): set.seed(123) y <- garchxSim(1000) mymod <- garchx(y) ##t-tests: ttest0(mymod) ##wald-test: waldtest0(mymod)