Commit c3758f6c authored by Dirk Eddelbuettel's avatar Dirk Eddelbuettel

Import Upstream version 0.9.24

parents
This diff is collapsed.
2004-11-12 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.9-24.
* R/finance.R (get.hist.quote):
* man/get.hist.quote.Rd:
Add argument 'compression' to get.hist.quote(), provided by BBands
<BBands@bollingerbands.com>.
2004-08-05 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.9-23.
* data/*.R:
Remove explicit calls to require() for package stats, and instead
use stats::ts() to ensure that stats gets attached.
2004-07-20 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.9-22.
* man/get.hist.quote.Rd:
* man/plotOHLC.Rd:
Change symbol for S&P 500 from ^spc to ^gspc, argh.
Try wrapping examples inside a suitable test for connectivity to
quote.yahoo.com rather than \dontrun{}, so that we can figure out
when examples fail more easily.
2004-03-23 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.9-20.
* R/finance.R (portfolio.optim.default):
* R/test.R (white.test.default, white.test.ts):
* R/zzz.R (.First.lib):
Adjust for changes in R 1.9.0.
2004-01-31 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.9-19.
* INDEX: Removed.
2003-12-15 Dirk Eddelbuettel <edd@debian.org>
* DESCRIPTION (Version): New version is 0.9-18.
* R/finance.R (plotOHLC): Use segments() with vector arguments.
2003-11-06 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.9-17.
* man/summary.garch.Rd:
* man/summary.arma.Rd:
Fix codoc default value problem/typo.
2003-10-10 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.9-16.
* R/arma.R (print.summary.arma):
* R/garch.R (print.summary.garch):
* man/arma-methods.Rd:
* man/garch-methods.Rd:
* man/summary.arma.Rd:
* man/summary.garch.Rd:
print.coefmat() is deprecated and replaced by printCoefmat() in R
1.8.
2003-08-27 Adrian Trapletti <a.trapletti@bluewin.ch>
* DESCRIPTION (Version): New version is 0.9-15.
* README: Cosmetic change.
* R/finance.R (get.hist.quote): Treat the case when the
submitted data from Yahoo contains information concerning
dividends (problem and solution reported by Achmim Zeileis
<zeileis@ci.tuwien.ac.at>).
2003-07-09 Adrian Trapletti <a.trapletti@bluewin.ch>
* DESCRIPTION (Version): New version is 0.9-14.
* R/finance.R (plotOHLC): Correct bug when setting the ylim
argument (reported by Dirk Eddelbuettel).
* R/irts.R:
* man/irts-functions.Rd: rename function interpolate to
approx.irts.
2003-07-08 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.9-13.
* man/arma-methods.Rd:
* man/garch-methods.Rd:
Remove over-documented argument 'signif.stars' from \arguments.
2003-06-06 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.9-12.
* R/finance.R (get.hist.quote): Work around addressed in 0.9-11
was not good enough.
2003-04-22 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.9-11.
* R/finance.R (get.hist.quote): Work around a problem in 1.7.0
(PR#2815 and also reported by Lars W. Hansen <lwhansen@usa.net>).
2003-03-04 Adrian Trapletti <a.trapletti@bluewin.ch>
* DESCRIPTION (Version): New version is 0.9-10.
* R/finance.R: change check for the case of an unknown quote.
* man/arma-methods.Rd
* man/garch-methods.Rd
* man/plotOHLC.Rd
* man/portfolio.optim.Rd
* man/read.ts.Rd
* man/seqplot.ts.Rd
* man/surrogate.Rd
* man/terasvirta.test.Rd
* man/white.test.Rd: cosmetic changes.
* R/irts.R:
* man/irts-functions.Rd:
* man/irts-methods.Rd:
* man/irts.Rd: add new class for irregularly spaced
time-series.
2003-02-19 Adrian Trapletti <a.trapletti@bluewin.ch>
* DESCRIPTION (Version): New version is 0.9-9.
* README: update.
* R/finance.R:
* man/plotOHLC.Rd: add new argument origin such that
it works smoothly together with get.hist.quote() (problem
spotted by Michael Parzen <fmparzen@gsb.uchicago.edu>).
2003-02-05 Adrian Trapletti <a.trapletti@bluewin.ch>
* DESCRIPTION (Version): New version is 0.9-8.
* README: cleanup.
* R/finance.R
* man/get.hist.quote.Rd: add new argument origin and change
YAHOO query (it seems that YAHOO has slightly changed the query
syntax to access historical data).
* R/garch.R
* man/garch-methods.Rd: add new method logLik.garch.
* man/garch.Rd: cosmetic change.
2003-01-22 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.9-7.
* R/tsutils.R (print.resample.statistic): Call print with named
'digits' argument [S4 method dispatch].
2002-11-22 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.9-6.
* R/garch.R (garch): Also had .C("pred_garch") without 'genuine'.
Guess to use FALSE here.
2002-11-21 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.9-5.
* R/garch.R (predict.garch): .C("pred_garch") needs to pass
'genuine' as well (spotted by Fan <xiao.gang.fan1@libertysurf.fr>
and Duncan Murdoch <dmurdoch@pair.com>).
2002-09-09 Adrian Trapletti <a.trapletti@bluewin.ch>
* DESCRIPTION (Version): New version is 0.9-3.
* INDEX:
* README: cleanup and update.
* man/garch.Rd
* man/bds.test.Rd: correct bugs in documentation.
* man/tsbootstrap.Rd: improve documentation.
* man/runs.test.Rd:
* R/test.R: new implementation of runs.test which was wrong
for versions <= 0.9-2.
2002-06-28 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION: New version is 0.9-2.
* R/garch.R (garch): Replace Machine() by .Machine as the former
is deprecated in R 1.6.
2002-06-19 Adrian Trapletti <a.trapletti@bluewin.ch>
* DESCRIPTION (Version): New version is 0.9-1.
* INDEX:
* TITLE:
* R/zzz.R: Cleanup and cosmetic changes.
* man/maxdrawdown.Rd:
* man/sharpe.Rd:
* man/sterling.Rd:
* R/finance.R: Improved version of maxdrawdown
and new functions sharpe and sterling.
2002-04-26 Adrian Trapletti <a.trapletti@bluewin.ch>
* DESCRIPTION (Version): New version is 0.9-0.
* man/amif.Rd:
* man/plot.amif.Rd:
* R/cor.R:
* misc/README:
* misc/mutinfo-1.21b.tar.gz
* src/tsutils.c: Removed non-GPL code.
* man/bootstrap.Rd:
* man/surrogate.Rd:
* man/tsbootstrap.Rd:
* R/tsutils.R: Improved version of time series
bootstrap which allows a block of blocks bootstrap.
The function bootstrap is renamed to tsbootstrap.
* DESCRIPTION:
* README: Cleanup.
* man/arma.Rd: Cosmetic change.
2001-11-30 Adrian Trapletti <a.trapletti@bluewin.ch>
* DESCRIPTION (Version): New version is 0.8-4.
* man/plotOHLC.Rd: Improve documentation.
* R/zzz.R: Cosmetic change.
2001-11-08 Adrian Trapletti <a.trapletti@bluewin.ch>
* DESCRIPTION (Version): New version is 0.8-3.
* man/bootstrap.Rd:
* R/tsutils.R:
* src/boot.c:
Improve documentation, error messages, and code.
2001-10-29 Adrian Trapletti <a.trapletti@bluewin.ch>
* DESCRIPTION (Version): New version is 0.8-2.
* man/get.hist.quote.Rd:
* R/finance.R:
Change default value for argument `quote' of `get.hist.quote()'.
* man/maxdrawdown.Rd:
* R/finance.R:
* src/tsutils.c:
Simpler and more informative implementation of max drawdown
statistic.
* man/plotOHLC.Rd:
* R/finance.R:
New function which plots open-high-low-close bar charts.
2001-10-18 Adrian Trapletti <a.trapletti@bluewin.ch>
* DESCRIPTION: Cleanup. New version is 0.8-1.
* README: Cleanup.
2001-10-12 Adrian Trapletti <a.trapletti@bluewin.ch>
* DESCRIPTION (Version): New version is 0.8-0.
* R/tsutils.R: Call .C with `mode = "double"' everywhere.
* man/maxdrawdown.Rd:
* R/finance.R:
* src/tsutils.c:
Fast implementation of max drawdown statistic.
2001-08-27 Adrian Trapletti <a.trapletti@bluewin.ch>
* DESCRIPTION (Version): New version is 0.7-6.
* src/arma.c: Correct nasty bug concerning accessing the
parameter intercept.
* man/portfolio.optim.Rd:
* R/finance.R:
Integration of a patch of Dirk Eddelbuettel for `portfolio.optim()'
that allows inequality restrictions on the portfolio weights and
a specification of the covariance matrix.
2001-08-20 Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
* DESCRIPTION (Version): New version is 0.7-5.
* man/tseries.internal.Rd: Renamed to tseries-internal.Rd.
* man/arma-methods.Rd:
* man/garch-methods.Rd:
* man/plot.amif.Rd:
* man/summary.arma.Rd:
* man/summary.garch.Rd:
New files.
* R/*.R:
* man/*.Rd:
Fix generic/method inconsistencies.
2001-08-19 Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
* man/tseries.internal.Rd: Change keyword `misc' to `internal'.
* R/tsutils.R: TnF fix.
2001-07-15 Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
* DESCRIPTION (Version): New version is 0.7-4.
* R/test.R:
* man/terasvirta.test.Rd:
* man/white.test.Rd:
Use `Chisq' instead of `chisq' for argument `type'.
2001-07-06 Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
* DESCRIPTION (Depends): No longer depends on chron.
* R/finance.R: Rewrite get.hist.quote() to use R internal POSIX
date/time classes and allow for retrieval of several quotes and
volume at once.
* man/get.hist.quote.Rd: Changed accordingly.
2001-06-18 Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
* DESCRIPTION (Version): New version is 0.7-2.
(Depends): Redo according to R-exts. Detailed info now in
`README'.
* man/na.remove.Rd: Sync code and documented usage.
* ChangeLog: finally started.
Package: tseries
Version: 0.9-24
Date: 2004-11-11
Title: Time series analysis and computational finance
Author: Compiled by Adrian Trapletti <a.trapletti@bluewin.ch>
Maintainer: Kurt Hornik <Kurt.Hornik@R-project.org>
Description: Package for time series analysis and computational finance
Depends: R (>= 1.9.0), quadprog
License: GPL (see file COPYING)
Packaged: Fri Nov 12 08:49:11 2004; hornik
## Copyright (C) 1997-2000 Adrian Trapletti
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## A copy of the GNU General Public License is available via WWW at
## http://www.gnu.org/copyleft/gpl.html. You can also obtain it by
## writing to the Free Software Foundation, Inc., 59 Temple Place,
## Suite 330, Boston, MA 02111-1307 USA.
##
## ARMA class
##
arma <-
function(x, order = c(1, 1), lag = NULL, coef = NULL,
include.intercept = TRUE, series = NULL, qr.tol = 1e-07, ...)
{
seqN <- function(N) {
if(0==length(N)) NULL else if(N<=0) NULL else seq(N)
}
err <- function(coef) {
u <- double(n)
u[seqN(max.order)] <- 0
u <- .C("arma",
as.vector(x, mode = "double"),
u = as.vector(u),
as.vector(coef, mode = "double"),
as.integer(lag$ar),
as.integer(lag$ma),
as.integer(ar.l),
as.integer(ma.l),
as.integer(max.order),
as.integer(n),
as.integer(include.intercept),
PACKAGE="tseries")$u
return(sum(u^2))
}
resid <- function(coef) {
u <- double(n)
u[seqN(max.order)] <- 0
u <- .C("arma",
as.vector(x, mode = "double"),
u = as.vector(u),
as.vector(coef, mode = "double"),
as.integer(lag$ar),
as.integer(lag$ma),
as.integer(ar.l),
as.integer(ma.l),
as.integer(max.order),
as.integer(n),
as.integer(include.intercept),
PACKAGE="tseries")$u
return(u)
}
arma.init <- function() {
k <- round(1.1*log(n))
e <- na.omit(drop(ar.ols(x, order.max = k, aic = FALSE,
demean = FALSE,
intercept = include.intercept)$resid))
ee <- embed(e, max.order+1)
xx <- embed(x[-(1:k)], max.order+1)
if(include.intercept == TRUE) {
if(is.null(lag$ar))
coef <- lm(xx[,1]~ee[,lag$ma+1])$coef
else if(is.null(lag$ma))
coef <- lm(xx[,1]~xx[,lag$ar+1])$coef
else
coef <- lm(xx[,1]~xx[,lag$ar+1]+ee[,lag$ma+1])$coef
coef <- c(coef[-1], coef[1])
}
else {
if(is.null(lag$ar))
coef <- lm(xx[,1]~ee[,lag$ma+1]-1)$coef
else if(is.null(lag$ma))
coef <- lm(xx[,1]~xx[,lag$ar+1]-1)$coef
else
coef <- lm(xx[,1]~xx[,lag$ar+1]+ee[,lag$ma+1]-1)$coef
}
return(coef)
}
if(!is.null(order) & !is.null(lag))
warning("order is ignored")
if(is.null(order) & is.null(lag))
stop("order or lag must be given")
if(is.null(lag) & !is.null(order))
lag <- list(ar=seqN(order[1]), ma=seqN(order[2]))
lag$ar <- unique(lag$ar)
lag$ma <- unique(lag$ma)
max.order <- max(unlist(lag),0)
ar.l <- length(lag$ar)
ma.l <- length(lag$ma)
if(NCOL(x) > 1)
stop("x is not a vector or univariate time series")
if(is.null(series)) series <- deparse(substitute(x))
ists <- is.ts(x)
x <- as.ts(x)
xfreq <- frequency(x)
if(any(is.na(x))) stop("NAs in x")
if(ists) xtsp <- tsp(x)
n <- length(x)
if(!is.null(unlist(lag)))
if(min(unlist(lag)) < 1 | max(unlist(lag)) > (n-1))
stop("invalid lag")
ncoef <- length(unlist(lag))+as.numeric(include.intercept)
if(is.null(coef)) {
if(!is.null(unlist(lag)))
coef <- arma.init()
else
coef <- 0
}
if(length(coef) != ncoef) stop("invalid coef")
md <- optim(coef, err, gr=NULL, hessian=TRUE, ...)
coef <- md$par
rank <- qr(md$hessian, qr.tol)$rank
if(rank != ncoef) {
se <- rep(NA, ncoef)
cat("Warning: singular Hessian\n")
}
else {
di <- diag(2*md$value/n*solve(md$hessian))
if(any(di < 0))
cat("Warning: Hessian negative-semidefinite\n")
se <- sqrt(di)
}
e <- resid(coef)
e[seqN(max.order)] <- NA
f <- x-e
if(ists) {
attr(e, "tsp") <- xtsp
attr(e, "class") <- "ts"
attr(f, "tsp") <- xtsp
attr(f, "class") <- "ts"
}
nam.ar <- if(!is.null(lag$ar))
paste("ar", lag$ar, sep = "")
else
NULL
nam.ma <- if(!is.null(lag$ma))
paste("ma", lag$ma, sep = "")
else
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
arma <- list(coef = coef,
css = md$value,
n.used = n,
residuals = e,
fitted.values = f,
series = series,
frequency = xfreq,
call = match.call(),
asy.se.coef = se,
lag = lag,
convergence = md$convergence,
include.intercept = include.intercept)
class(arma) <- "arma"
return(arma)
}
coef.arma <-
function(object, ...)
{
if(!inherits(object, "arma"))
stop("method is only for arma objects")
return(object$coef)
}
residuals.arma <-
function(object, ...)
{
if(!inherits(object, "arma"))
stop("method is only for arma objects")
return(object$residuals)
}
fitted.arma <-
function(object, ...)
{
if(!inherits(object, "arma"))
stop("method is only for arma objects")
return(object$fitted.values)
}
print.arma <-
function(x, digits = max(3, getOption("digits") - 3), ...)
{
if(!inherits(x, "arma"))
stop("method is only for arma objects")
cat("\nCall:\n", deparse(x$call), "\n\n", sep = "")
cat("Coefficient(s):\n")
print.default(format(coef(x), digits = digits),
print.gap = 2, quote = FALSE)
cat("\n")
invisible(x)
}
summary.arma <-
function(object, ...)
{
if(!inherits(object, "arma"))
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,
2 * (1-pnorm(abs(tval))))
dimnames(ans$coef) <-
list(names(object$coef),
c(" Estimate"," Std. Error"," t value","Pr(>|t|)"))
ans$call <- object$call
ans$nn <- object$nn
ans$css <- object$css
ans$var <- var(ans$residuals)
ans$aic <- (object$n.used * (1+log(2*pi)) + object$n.used *
log(ans$var) + 2 * length(object$coef))
ans$p <- max(object$lag$ar, 0)
ans$q <- max(object$lag$ma, 0)
class(ans) <- "summary.arma"
return(ans)
}
print.summary.arma <-
function(x, digits = max(3, getOption("digits") - 3),
signif.stars = getOption("show.signif.stars"), ...)
{
if(!inherits(x, "summary.arma"))
stop("method is only for summary.arma objects")
cat("\nCall:\n", deparse(x$call), "\n", sep = "")
cat("\nModel:\nARMA(",x$p,",",x$q,")\n", sep = "")
cat("\nResiduals:\n")
rq <- structure(quantile(x$residuals),
names = c("Min","1Q","Median","3Q","Max"))
print(rq, digits = digits, ...)
cat("\nCoefficient(s):\n")
printCoefmat(x$coef, digits = digits,
signif.stars = signif.stars, ...)
cat("\nFit:\n")
cat("sigma^2 estimated as ", format(x$var, digits = digits),
", Conditional Sum-of-Squares = ", format(round(x$css, 2)),
", AIC = ", format(round(x$aic, 2)), "\n", sep = "")
cat("\n")
invisible(x)
}
plot.arma <-
function(x, ask = interactive(), ...)
{
if(!inherits(x, "arma"))
stop("method is only for arma objects")
op <- par()
par(ask = ask, mfrow = c(2, 1))
data <- eval.parent(parse(text = x$series))
if(any(is.na(data))) stop(paste("NAs in", x$series))
plot(data, main = x$series, ylab = "Series")
plot(x$residuals, main = "Residuals", ylab = "Series")
acf(data, main = paste("ACF of", x$series))
acf(x$residuals, main = "ACF of Residuals",
na.action = na.remove)
pacf(data, main = paste("PACF of", x$series))
pacf(x$residuals, main = "PACF of Residuals",
na.action = na.remove)
par(ask = op$ask, mfrow = op$mfrow)
invisible(x)
}
This diff is collapsed.
## Copyright (C) 1997-1999 Adrian Trapletti
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## A copy of the GNU General Public License is available via WWW at
## http://www.gnu.org/copyleft/gpl.html. You can also obtain it by
## writing to the Free Software Foundation, Inc., 59 Temple Place,
## Suite 330, Boston, MA 02111-1307 USA.
##
## GARCH class
##
garch <-
function (x, order = c(1, 1), coef = NULL, itmax = 200, eps = NULL,
grad = c("analytical","numerical"), series = NULL,
trace = TRUE, ...)
{
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,
analytical = (agrad <- TRUE),
numerical = (agrad <- FALSE))
if(is.null(series)) series <- deparse(substitute(x))
ists <- is.ts(x)
x <- as.ts(x)
xfreq <- frequency(x)
if(any(is.na(x))) stop("NAs in x")
if(ists) xtsp <- tsp(x)
x <- as.matrix(x)
n <- nrow(x)
e <- double(n)
ncoef <- order[1]+order[2]+1
hess <- matrix(0.0, ncoef, ncoef)
small <- 0.05
if(is.null(coef))
coef <- c(var(x)*(1.0-small*(ncoef-1)),rep(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"),
as.integer(n),
coef = as.vector(coef, mode = "double"),
as.integer(order[1]),
as.integer(order[2]),
as.integer(itmax),
as.double(eps),
nlikeli = as.double(nlikeli),
as.integer(agrad),
as.integer(trace),
PACKAGE="tseries")
pred <- .C("pred_garch",
as.vector(x, mode = "double"),
e = as.vector(e, mode = "double"),
as.integer(n),
as.vector(fit$coef, mode = "double"),
as.integer(order[1]),
as.integer(order[2]),