Commit f32e7572 authored by Dirk Eddelbuettel's avatar Dirk Eddelbuettel

Import Upstream version 0.10-14

parent 24df1c59
2008-02-26 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.10-14.
2008-02-09 Achim Zeileis <Achim.Zeileis@R-project.org>
* R/garch.R: changed handling of control arguments for
garch(), new garch.control() function,
added new vcov() method.
* src/garch.c: de-coupled single eps tolerance into
four different tolerance parameters.
* man/garch.Rd: all control arguments now collected in
garch.control(), re-named (similar to optim arguments),
de-coupled tolerance parameters, return value has
vcov instead of asy.se.coef.
* man/garch-methods.Rd: new vcov method.
* R/arma.R: new vcov() method
* man/arma.Rd: return value has vcov instead of asy.se.coef.
* man/arma-methods.Rd: new vcov method.
* NAMESPACE: new vcov() methods
2007-12-13 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.10-13.
......
Package: tseries
Version: 0.10-13
Date: 2007-12-13
Version: 0.10-14
Date: 2008-02-22
Title: Time series analysis and computational finance
Author: Compiled by Adrian Trapletti <a.trapletti@swissonline.ch>
Maintainer: Kurt Hornik <Kurt.Hornik@R-project.org>
......@@ -9,4 +9,4 @@ Depends: R (>= 2.4.0), quadprog, stats, zoo
Suggests: its
Imports: graphics, stats, utils
License: GPL-2
Packaged: Thu Dec 13 09:21:20 2007; hornik
Packaged: Tue Feb 26 12:12:16 2008; hornik
......@@ -5,7 +5,8 @@ import("graphics", "stats", "utils")
export("adf.test", "approx.irts", "arma", "as.irts",
"bds.test",
"daysecond",
"garch", "get.hist.quote",
"garch", "garch.control",
"get.hist.quote",
"irts", "is.businessday", "is.irts", "is.weekend",
"jarque.bera.test",
"kpss.test",
......@@ -52,5 +53,7 @@ S3method("terasvirta.test", "default")
S3method("terasvirta.test", "ts")
S3method("time", "irts")
S3method("value", "irts")
S3method("vcov", "arma")
S3method("vcov", "garch")
S3method("white.test", "default")
S3method("white.test", "ts")
......@@ -125,14 +125,12 @@ function(x, order = c(1, 1), lag = NULL, coef = NULL,
coef <- md$par
rank <- qr(md$hessian, qr.tol)$rank
if(rank != ncoef) {
se <- rep.int(NA, ncoef)
vc <- matrix(NA, nrow = ncoef, ncol = ncoef)
warning("singular Hessian")
}
else {
di <- diag(2*md$value/n*solve(md$hessian))
if(any(di < 0))
warning("Hessian negative-semidefinite")
se <- sqrt(di)
vc <- 2*md$value/n*solve(md$hessian)
if(any(diag(vc) < 0)) warning("Hessian negative-semidefinite")
}
e <- resid(coef)
e[seqN(max.order)] <- NA
......@@ -154,7 +152,7 @@ function(x, order = c(1, 1), lag = NULL, coef = NULL,
nam.int <- if(include.intercept) "intercept" else NULL
nam.coef <- c(nam.ar, nam.ma, nam.int)
names(coef) <- nam.coef
names(se) <- nam.coef
colnames(vc) <- rownames(vc) <- nam.coef
arma <- list(coef = coef,
css = md$value,
n.used = n,
......@@ -163,7 +161,7 @@ function(x, order = c(1, 1), lag = NULL, coef = NULL,
series = series,
frequency = xfreq,
call = match.call(),
asy.se.coef = se,
vcov = vc,
lag = lag,
convergence = md$convergence,
include.intercept = include.intercept)
......@@ -179,6 +177,14 @@ function(object, ...)
return(object$coef)
}
vcov.arma <-
function(object, ...)
{
if(!inherits(object, "arma"))
stop("method is only for arma objects")
return(object$vcov)
}
residuals.arma <-
function(object, ...)
{
......@@ -215,8 +221,8 @@ function(object, ...)
stop("method is only for arma objects")
ans <- NULL
ans$residuals <- na.remove(object$residuals)
tval <- object$coef / object$asy.se.coef
ans$coef <- cbind(object$coef, object$asy.se.coef, tval,
tval <- object$coef / sqrt(diag(object$vcov))
ans$coef <- cbind(object$coef, sqrt(diag(object$vcov)), tval,
2 * (1-pnorm(abs(tval))))
dimnames(ans$coef) <-
list(names(object$coef),
......
......@@ -20,15 +20,12 @@
##
garch <-
function (x, order = c(1, 1), coef = NULL, itmax = 200, eps = NULL,
grad = c("analytical","numerical"), series = NULL,
trace = TRUE, ...)
function (x, order = c(1, 1), series = NULL, control = garch.control(...), ...)
{
if(NCOL(x) > 1)
stop("x is not a vector or univariate time series")
if(!is.vector(order)) stop("order is not a vector")
grad <- match.arg(grad)
switch(grad,
switch(control$grad,
analytical = (agrad <- TRUE),
numerical = (agrad <- FALSE))
if(is.null(series)) series <- deparse(substitute(x))
......@@ -43,11 +40,11 @@ function (x, order = c(1, 1), coef = NULL, itmax = 200, eps = NULL,
ncoef <- order[1]+order[2]+1
hess <- matrix(0.0, ncoef, ncoef)
small <- 0.05
coef <- control$start
if(is.null(coef))
coef <- c(var(x)*(1.0-small*(ncoef-1)),rep.int(small,ncoef-1))
if(!is.vector(coef)) stop("coef is not a vector")
if(ncoef != length(coef)) stop("incorrect length of coef")
if(is.null(eps)) eps <- .Machine$double.eps
nlikeli <- 1.0e+10
fit <- .C("fit_garch",
as.vector(x, mode = "double"),
......@@ -55,11 +52,14 @@ function (x, order = c(1, 1), coef = NULL, itmax = 200, eps = NULL,
coef = as.vector(coef, mode = "double"),
as.integer(order[1]),
as.integer(order[2]),
as.integer(itmax),
as.double(eps),
as.integer(control$maxiter),
as.double(control$abstol),
as.double(control$reltol),
as.double(control$xtol),
as.double(control$falsetol),
nlikeli = as.double(nlikeli),
as.integer(agrad),
as.integer(trace),
as.integer(control$trace),
PACKAGE="tseries")
pred <- .C("pred_garch",
as.vector(x, mode = "double"),
......@@ -78,13 +78,13 @@ function (x, order = c(1, 1), coef = NULL, itmax = 200, eps = NULL,
as.integer(order[1]),
as.integer(order[2]),
PACKAGE="tseries")
rank <- qr(com.hess$hess, ...)$rank
rank <- do.call("qr", c(list(x = com.hess$hess), control$qr))$rank
if(rank != ncoef) {
se.garch <- rep.int(NA, ncoef)
vc <- matrix(NA, nrow = ncoef, ncol = ncoef)
warning("singular information")
}
else
se.garch <- sqrt(diag(solve(com.hess$hess)))
vc <- solve(com.hess$hess)
sigt <- sqrt(pred$e)
sigt[1:max(order[1],order[2])] <- rep.int(NA, max(order[1],order[2]))
f <- cbind(sigt,-sigt)
......@@ -102,7 +102,7 @@ function (x, order = c(1, 1), coef = NULL, itmax = 200, eps = NULL,
if(order[1] > 0)
nam.coef <- c(nam.coef, paste("b", seq(order[1]), sep = ""))
names(coef) <- nam.coef
names(se.garch) <- nam.coef
colnames(vc) <- rownames(vc) <- nam.coef
garch <- list(order = order,
coef = coef,
n.likeli = fit$nlikeli,
......@@ -112,11 +112,24 @@ function (x, order = c(1, 1), coef = NULL, itmax = 200, eps = NULL,
series = series,
frequency = xfreq,
call = match.call(),
asy.se.coef = se.garch)
vcov = vc)
class(garch) <- "garch"
return(garch)
}
garch.control <-
function(maxiter = 200, trace = TRUE, start = NULL, grad = c("analytical","numerical"),
abstol = max(1e-20, .Machine$double.eps^2),
reltol = max(1e-10, .Machine$double.eps^(2/3)),
xtol = sqrt(.Machine$double.eps),
falsetol = 1e2 * .Machine$double.eps, ...)
{
rval <- list(maxiter = maxiter, trace = trace, start = start, grad = match.arg(grad),
abstol = abstol, reltol = reltol, xtol = xtol, falsetol = falsetol)
rval$qr <- list(...)
rval
}
coef.garch <-
function(object, ...)
{
......@@ -125,6 +138,14 @@ function(object, ...)
return(object$coef)
}
vcov.garch <-
function(object, ...)
{
if(!inherits(object, "garch"))
stop("method is only for garch objects")
return(object$vcov)
}
residuals.garch <-
function(object, ...)
{
......@@ -161,8 +182,8 @@ function(object, ...)
stop("method is only for garch objects")
ans <- NULL
ans$residuals <- na.remove(object$residuals)
tval <- object$coef / object$asy.se.coef
ans$coef <- cbind(object$coef, object$asy.se.coef, tval,
tval <- object$coef / sqrt(diag(object$vcov))
ans$coef <- cbind(object$coef, sqrt(diag(object$vcov)), tval,
2*(1-pnorm(abs(tval))))
dimnames(ans$coef) <-
list(names(object$coef),
......@@ -276,4 +297,3 @@ function(object, ...)
class(val) <- "logLik"
return(val)
}
......@@ -10,7 +10,7 @@ Authors:
P. Buehlmann, D. Eddelbuettel, X. G. Fan, K. Hornik, W. Koller,
F. Leisch, M. Maechler, D. Murdoch, M. Parzen, A. Shah, A. Zeileis
License: GPL
License: GPL-2
Depends on the following R packages:
stats (included in the R distribution),
......
\name{arma-methods}
\alias{arma-methods}
\alias{coef.arma}
\alias{vcov.arma}
\alias{residuals.arma}
\alias{fitted.arma}
\alias{print.arma}
......@@ -11,6 +12,7 @@
}
\usage{
\method{coef}{arma}(object, \dots)
\method{vcov}{arma}(object, \dots)
\method{residuals}{arma}(object, \dots)
\method{fitted}{arma}(object, \dots)
\method{print}{arma}(x, digits = max(3, getOption("digits") - 3), \dots)
......@@ -25,7 +27,7 @@
\item{\dots}{further arguments passed to or from other methods.}
}
\value{
For \code{coef}, a numeric vector;
For \code{coef}, a numeric vector; for \code{vcov}, a numeric matrix;
for \code{residuals} and \code{fitted} a univariate time series;
for \code{plot} and \code{print}, the fitted ARMA model object.
}
......
......@@ -59,7 +59,7 @@ arma(x, order = c(1, 1), lag = NULL, coef = NULL,
\item{series}{the name of the series \code{x}.}
\item{frequency}{the frequency of the series \code{x}.}
\item{call}{the call of the \code{arma} function.}
\item{asy.se.coef}{the asymptotic-theory standard errors of the
\item{vcov}{estimate of the asymptotic-theory covariance matrix for the
coefficient estimates.}
\item{convergence}{The \code{convergence} integer code from
\code{\link{optim}}.}
......
......@@ -2,6 +2,7 @@
\alias{garch-methods}
\alias{predict.garch}
\alias{coef.garch}
\alias{vcov.garch}
\alias{residuals.garch}
\alias{fitted.garch}
\alias{print.garch}
......@@ -14,6 +15,7 @@
\usage{
\method{predict}{garch}(object, newdata, genuine = FALSE, \dots)
\method{coef}{garch}(object, \dots)
\method{vcov}{garch}(object, \dots)
\method{residuals}{garch}(object, \dots)
\method{fitted}{garch}(object, \dots)
\method{print}{garch}(x, digits = max(3, getOption("digits") - 3), \dots)
......@@ -39,6 +41,8 @@
\code{coef} returns the coefficient estimates.
\code{vcov} the associated covariance matrix estimate (outer product of gradients estimator).
\code{residuals} returns the GARCH residuals, i.e., the time series
used to fit the model divided by the computed conditional standard
deviation predictions for this series. Under the assumption of
......
\name{garch}
\alias{garch}
\alias{garch.control}
\title{Fit GARCH Models to Time Series}
\description{
Fit a Generalized Autoregressive Conditional Heteroscedastic GARCH(p,
......@@ -7,36 +8,38 @@
estimates of the conditionally normal model.
}
\usage{
garch(x, order = c(1, 1), coef = NULL, itmax = 200, eps = NULL,
grad = c("analytical","numerical"), series = NULL,
trace = TRUE, \dots)
garch(x, order = c(1, 1), series = NULL, control = garch.control(\dots), \dots)
garch.control(maxiter = 200, trace = TRUE, start = NULL,
grad = c("analytical","numerical"), abstol = max(1e-20, .Machine$double.eps^2),
reltol = max(1e-10, .Machine$double.eps^(2/3)), xtol = sqrt(.Machine$double.eps),
falsetol = 1e2 * .Machine$double.eps, \dots)
}
\arguments{
\item{x}{a numeric vector or time series.}
\item{order}{a two dimensional integer vector giving the orders of the
model to fit. \code{order[2]} corresponds to the ARCH part and
\code{order[1]} to the GARCH part.}
\item{coef}{If given this numeric vector is used as the initial estimate
\item{series}{name for the series. Defaults to
\code{deparse(substitute(x))}.}
\item{control}{a list of control parameters as set up by \code{garch.control}.}
\item{maxiter}{gives the maximum number of log-likelihood function
evaluations \code{maxiter} and the maximum number of iterations
\code{2*maxiter} the optimizer is allowed to compute.}
\item{trace}{logical. Trace optimizer output?}
\item{start}{If given this numeric vector is used as the initial estimate
of the GARCH coefficients. Default initialization is to set the
GARCH parameters to slightly positive values and to initialize the
intercept such that the unconditional variance of the initial GARCH
is equal to the variance of \code{x}.}
\item{itmax}{gives the maximum number of log-likelihood function
evaluations \code{itmax} and the maximum number of iterations
\code{2*itmax} the optimizer is allowed to compute.}
\item{eps}{defines the absolute (\code{max(1e-20, eps^2)}) and
relative function convergence tolerance
(\code{max(1e-10, eps^(2/3))}), the coefficient-convergence
tolerance (\code{sqrt(eps)}), and the false convergence tolerance
(\code{1e2*eps}). Default value is the machine epsilon, see
\code{\link{Machine}}.}
\item{grad}{indicates if the analytical gradient or a numerical
\item{grad}{character indicating whether analytical gradients or a numerical
approximation is used for the optimization.}
\item{series}{name for the series. Defaults to
\code{deparse(substitute(x))}.}
\item{trace}{trace optimizer output?}
\item{abstol}{absolute function convergence tolerance.}
\item{reltol}{relative function convergence tolerance.}
\item{xtol}{coefficient-convergence tolerance.}
\item{falsetol}{false convergence tolerance.}
\item{\dots}{additional arguments for \code{\link{qr}} when computing
the asymptotic standard errors of \code{coef}.}
the asymptotic covariance matrix.}
}
\details{
\code{garch} uses a Quasi-Newton optimizer to find the maximum
......@@ -61,8 +64,8 @@ garch(x, order = c(1, 1), coef = NULL, itmax = 200, eps = NULL,
\item{series}{the name of the series \code{x}.}
\item{frequency}{the frequency of the series \code{x}.}
\item{call}{the call of the \code{garch} function.}
\item{asy.se.coef}{the asymptotic-theory standard errors of the
coefficient estimates.}
\item{vcov}{outer product of gradient estimate of the asymptotic-theory
covariance matrix for the coefficient estimates.}
}
\references{
A. K. Bera and M. L. Higgins (1993):
......
......@@ -132,7 +132,8 @@ static void F77_SUB(ufparm) ()
void fit_garch (double *y, int *n, double *par, int *p, int *q, int *itmax,
double *eps, double *fret, int *agrad, int *trace)
double *afctol, double *rfctol, double *xctol, double *xftol,
double *fret, int *agrad, int *trace)
/* fit a GARCH (p, q) model
Input:
......@@ -141,7 +142,10 @@ void fit_garch (double *y, int *n, double *par, int *p, int *q, int *itmax,
par[0..p+q] initial parameter estimates
p, q model orders
itmax maximum number of iterations
eps precision
afctol absolute function convergence tolerance
rfctol relative function convergence tolerance
xctol x-convergence tolerance
xftol false convergence tolerance
agrad estimation with analytical/numerical gradient
trace output yes/no
......@@ -176,10 +180,10 @@ void fit_garch (double *y, int *n, double *par, int *p, int *q, int *itmax,
iv[20] = 6;
else
iv[20] = 0;
v[30] = DMAX(1.0e-20, DSQR((*eps)));
v[31] = DMAX(1.0e-10, pow((*eps),2.0/3.0));
v[32] = sqrt((*eps));
v[33] = 100.0*(*eps);
v[30] = (*afctol);
v[31] = (*rfctol);
v[32] = (*xctol);
v[33] = (*xftol);
/* set handler values */
garch_h.p = (*p); garch_h.q = (*q); garch_h.n = (*n); garch_h.y = y;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment