Commit b9e9a98e authored by Dirk Eddelbuettel's avatar Dirk Eddelbuettel

Import Upstream version 0.9.30

parent 83ec8b9d
2005-09-07 Achim Zeileis <Achim.Zeileis@R-project.org>
* DESCRIPTION (Version): New version is 0.9-30,
depends on zoo, suggests its.
* R/finance.R (get.hist.quote): can return now
"zoo", "ts" and "its" series.
* man/get.hist.quote.Rd: added retclass argument.
* man/plotOHLC.Rd: adapted to get.hist.quote().
2005-09-06 Adrian Trapletti <a.trapletti@swissonline.ch>
* README: Update contributers.
* R/finance.R (get.hist.quote):
* man/get.hist.quote.Rd:
Improved error messages and documentation.
2005-09-03 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* DESCRIPTION (Version): New version is 0.9-29.
* R/finance.R (get.hist.quote):
$ man/get.hist.quote.Rd:
* man/get.hist.quote.Rd:
New provider 'oanda' to get.hist.quote() [by A Trapletti].
2005-08-29 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
......
Package: tseries
Version: 0.9-29
Date: 2005-09-03
Version: 0.9-30
Date: 2005-09-06
Title: Time series analysis and computational finance
Author: Compiled by Adrian Trapletti <a.trapletti@swissonline.ch>
Maintainer: Kurt Hornik <Kurt.Hornik@R-project.org>
Description: Package for time series analysis and computational finance
Depends: R (>= 1.9.0), quadprog
Depends: R (>= 2.1.0), quadprog, zoo
Suggests: its
License: GPL (see file COPYING)
Packaged: Sat Sep 3 21:22:23 2005; hornik
Packaged: Thu Sep 8 12:53:12 2005; zeileis
......@@ -137,7 +137,8 @@ get.hist.quote <-
function (instrument = "^gdax", start, end,
quote = c("Open", "High", "Low", "Close"),
provider = c("yahoo", "oanda"), method = "auto",
origin = "1899-12-30", compression = "d")
origin = "1899-12-30", compression = "d",
retclass = c("zoo", "its", "ts"))
## Added new argument 'compression'.
## May be "d", "w" or "m", for daily weekly or monthly.
## Defaults to "d".
......@@ -149,6 +150,7 @@ function (instrument = "^gdax", start, end,
if(missing(end)) end <- format(Sys.Date() - 1, "%Y-%m-%d")
provider <- match.arg(provider)
retclass <- match.arg(retclass)
start <- as.Date(start)
end <- as.Date(end)
......@@ -193,7 +195,8 @@ function (instrument = "^gdax", start, end,
## cat("read.table: end =", x[1,"Date"], "\n")
unlink(destfile)
names(x) <- gsub("\\.", "", names(x))
nser <- pmatch(quote, names(x)[-1]) + 1
if(any(is.na(nser)))
stop("this quote is not available")
......@@ -206,20 +209,44 @@ function (instrument = "^gdax", start, end,
on.exit(Sys.setlocale("LC_TIME", lct))
dat <- gsub(" ", "0", as.character(x[, 1])) # Need the gsub?
dat <- as.Date(dat, "%d-%b-%y")
idx <- c(grep(".*-0.", dat), grep(".*-1.", dat))
dat[idx] <- paste(substr(dat[idx], 1, nchar(dat[idx]) - 2),
"20",
substr(dat[idx], nchar(dat[idx]) - 1, nchar(dat[idx])),
sep = "")
dat[-idx] <- paste(substr(dat[-idx], 1, nchar(dat[-idx]) - 2),
"19",
substr(dat[-idx], nchar(dat[-idx]) - 1, nchar(dat[-idx])),
sep = "")
dat <- as.Date(dat, "%d-%b-%Y")
if(dat[n] != start)
cat(format(dat[n], "time series starts %Y-%m-%d\n"))
if(dat[1] != end)
cat(format(dat[1], "time series ends %Y-%m-%d\n"))
jdat <-
unclass(julian(dat, origin = as.Date(origin)))
## We need unclass() because 1.7.0 does not allow adding a number
## to a "difftime" object.
ind <- jdat - jdat[n] + 1
y <- matrix(NA, nr = max(ind), nc = length(nser))
y[ind, ] <- as.matrix(x[, nser, drop = FALSE])
colnames(y) <- names(x)[nser]
return(ts(y, start = jdat[n], end = jdat[1]))
if(retclass == "ts") {
jdat <- unclass(julian(dat, origin = as.Date(origin)))
## We need unclass() because 1.7.0 does not allow adding a number
## to a "difftime" object.
ind <- jdat - jdat[n] + 1
y <- matrix(NA, nr = max(ind), nc = length(nser))
y[ind, ] <- as.matrix(x[, nser, drop = FALSE])
colnames(y) <- names(x)[nser]
return(ts(y, start = jdat[n], end = jdat[1]))
} else {
x <- as.matrix(x[, nser, drop = FALSE])
rownames(x) <- NULL
y <- zoo(x, dat)
if(retclass == "its") {
if("package:its" %in% search() || require("its", quietly = TRUE)) {
index(y) <- as.POSIXct(index(y))
y <- as.its(y)
} else {
warning("package its could not be loaded: zoo series returned")
}
}
return(y)
}
}
else if(provider == "oanda") {
if(!missing(quote)) {
......@@ -252,7 +279,9 @@ function (instrument = "^gdax", start, end,
unlink(destfile)
if(length(grep("Sorry", x)) > 0) {
stop("time period is too big (maximum 2000 days can be downloaded)")
msg <- unlist(strsplit(gsub("<[a-zA-Z0-9\\/]*>", "", x[grep("Sorry", x)]), split = " "))
msg <- paste(msg[msg != ""], collapse = " ")
stop("Message from Oanda: ", msg)
}
first <- which(substr(x, 1, 5) == "<PRE>")
......@@ -266,17 +295,30 @@ function (instrument = "^gdax", start, end,
x <- cbind(unlist(lapply(split, function(x) { x[1] })), unlist(lapply(split, function(x) { x[length(x)] })))
n <- nrow(x)
dat <- as.POSIXct(strptime(x[,1], "%m/%d/%Y"), tz = "GMT")
dat <- as.Date(x[,1], format = "%m/%d/%Y")
if(dat[1] != start)
cat(format(dat[1], "time series starts %Y-%m-%d\n"))
if(dat[n] != end)
cat(format(dat[n], "time series ends %Y-%m-%d\n"))
jdat <- unclass(julian(dat, origin = as.POSIXct(origin, tz = "GMT")))
ind <- jdat - jdat[1] + 1
y <- rep(NA, max(ind))
y[ind] <- as.numeric(x[,2])
return(ts(y, start = jdat[1], end = jdat[n]))
if(retclass == "ts") {
jdat <- unclass(julian(dat, origin = as.Date(origin)))
ind <- jdat - jdat[1] + 1
y <- rep(NA, max(ind))
y[ind] <- as.numeric(x[,2])
return(ts(y, start = jdat[1], end = jdat[n]))
} else {
y <- zoo(as.numeric(x[,2]), dat)
if(retclass == "its") {
if("package:its" %in% search() || require("its", quietly = TRUE)) {
index(y) <- as.POSIXct(index(y))
y <- as.its(y)
} else {
warning("package its could not be loaded: zoo series returned")
}
}
return(y)
}
}
else stop("provider not implemented")
}
......@@ -377,3 +419,4 @@ function(x, xlim = NULL, ylim = NULL, xlab = "Time", ylab,
if (frame.plot)
box(...)
}
......@@ -8,7 +8,7 @@ Authors:
In addition, the following people have contributed
code, bug reports, and documentation:
P. Buehlmann, D. Eddelbuettel, X. G. Fan, K. Hornik, W. Koller,
F. Leisch, M. Maechler, D. Murdoch, M. Parzen, A. Zeileis
F. Leisch, M. Maechler, D. Murdoch, M. Parzen, A. Shah, A. Zeileis
License: GPL
......
......@@ -9,7 +9,8 @@
get.hist.quote(instrument = "^gdax", start, end,
quote = c("Open", "High", "Low", "Close"),
provider = c("yahoo", "oanda"), method = "auto",
origin = "1899-12-30", compression = "d")
origin = "1899-12-30", compression = "d",
retclass = c("zoo", "its", "ts"))
}
\arguments{
\item{instrument}{a character string giving the name of the quote
......@@ -27,9 +28,9 @@ get.hist.quote(instrument = "^gdax", start, end,
\item{quote}{a character string or vector indicating whether to
download opening, high, low, or closing quotes, or volume. For the
default provider, this can be specified as \code{"Open"},
\code{"High"}, \code{"Low"}, \code{"Close"}, and \code{"Volume"},
respectively. For the provider \code{"oanda"}, this argument is
ignored. Abbreviations are allowed.}
\code{"High"}, \code{"Low"}, \code{"Close"}, \code{"AdjClose"}, and
\code{"Volume"}, respectively. For the provider \code{"oanda"},
this argument is ignored. Abbreviations are allowed.}
\item{provider}{a character string with the name of the data
provider. Currently, \code{"yahoo"} and \code{"oanda"} are
implemented. See \url{http://quote.yahoo.com/} and
......@@ -43,16 +44,28 @@ get.hist.quote(instrument = "^gdax", start, end,
\code{"d"} for daily, \code{"w"} for weekly or \code{"m"} for
monthly. Defaults to \code{"d"}. For the provider \code{"oanda"},
this argument is ignored.}
\item{retclass}{character specifying which class the return value
should have: can be either \code{"zoo"} (with \code{"Date"} index),
\code{"its"} (with \code{"POSIXct"} index) or \code{"ts"} (with
numeric index corresponding to days since \code{origin}).}
}
\value{
A time series containing the data in physical time, i.e., weekends,
A time series containing the data either as a \code{"zoo"} series (default),
a \code{"its"} series or \code{"ts"} series. The "zoo" series is created with
\code{\link[zoo]{zoo}} and has an index of class \code{"Date"}. For
returning an \code{"its"} series, \code{\link[its]{its}} has to be available.
\code{"its"} series always have an index of class \code{"POSIXct"}.
If a \code{"ts"} series is returned, the index is in physical time, i.e., weekends,
holidays, and missing days are filled with \code{NA}s if not
available. The time scale is given in Julian dates (days since the
\code{origin}).
}
\author{A. Trapletti}
\seealso{
\code{\link[zoo]{zoo}},
\code{\link[its]{its}},
\code{\link{ts}},
\code{\link{as.Date}},
\code{\link{as.POSIXct}},
\code{\link{download.file}};
\url{http://quote.yahoo.com/},
......@@ -68,9 +81,11 @@ if(!inherits(try(open(url("http://quote.yahoo.com")), silent = TRUE),
x <- get.hist.quote(instrument = "ibm", quote = c("Cl", "Vol"))
plot(x, main = "International Business Machines Corp")
spc <- get.hist.quote(instrument = "^gspc", start = "1998-01-01")
ibm <- get.hist.quote(instrument = "ibm", start = "1998-01-01")
x <- na.remove(ts.union(spc, ibm))
spc <- get.hist.quote(instrument = "^gspc", start = "1998-01-01",
quote = "Close")
ibm <- get.hist.quote(instrument = "ibm", start = "1998-01-01",
quote = "AdjClose")
x <- merge(spc, ibm)
plot(x, main = "IBM vs S&P 500")
x <- get.hist.quote(instrument = "EUR/USD", provider = "oanda",
......
......@@ -56,7 +56,8 @@ if(!inherits(try(open(url("http://quote.yahoo.com")), silent = TRUE),
start <- strftime(as.POSIXlt(Sys.time() - nDays*24*3600),
format="\%Y-\%m-\%d")
end <- strftime(as.POSIXlt(Sys.time()), format = "\%Y-\%m-\%d")
x <- get.hist.quote(instrument = instrument, start = start, end = end)
x <- get.hist.quote(instrument = instrument, start = start, end = end,
retclass = "ts")
plotOHLC(x, ylab = "price", main = instrument)
}
......
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