Commit 83ec8b9d authored by Dirk Eddelbuettel's avatar Dirk Eddelbuettel

Import Upstream version 0.9.29

parent 95b010fe
2005-09-03 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
* R/finance.R (get.hist.quote):
$ 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>
* DESCRIPTION (Version): New version is 0.9-28.
......
Package: tseries
Version: 0.9-28
Date: 2005-08-19
Version: 0.9-29
Date: 2005-09-03
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
License: GPL (see file COPYING)
Packaged: Mon Aug 29 23:28:52 2005; hornik
Packaged: Sat Sep 3 21:22:23 2005; hornik
......@@ -136,7 +136,7 @@ function(x, pm = mean(x), riskless = FALSE, shorts = FALSE,
get.hist.quote <-
function (instrument = "^gdax", start, end,
quote = c("Open", "High", "Low", "Close"),
provider = "yahoo", method = "auto",
provider = c("yahoo", "oanda"), method = "auto",
origin = "1899-12-30", compression = "d")
## Added new argument 'compression'.
## May be "d", "w" or "m", for daily weekly or monthly.
......@@ -180,7 +180,7 @@ function (instrument = "^gdax", start, end,
nlines <- length(count.fields(destfile, sep = "\n"))
if(nlines == 1) {
unlink(destfile)
stop(paste("No data available for", instrument))
stop(paste("no data available for", instrument))
}
## Yahoo includes rows concerning dividends,
......@@ -196,7 +196,7 @@ function (instrument = "^gdax", start, end,
nser <- pmatch(quote, names(x)[-1]) + 1
if(any(is.na(nser)))
stop("This quote is not available")
stop("this quote is not available")
n <- nrow(x)
## Yahoo currently formats dates as '26-Jun-01', hence need C
......@@ -221,6 +221,63 @@ function (instrument = "^gdax", start, end,
colnames(y) <- names(x)[nser]
return(ts(y, start = jdat[n], end = jdat[1]))
}
else if(provider == "oanda") {
if(!missing(quote)) {
warning("argument 'quote' ignored for provider 'oanda'")
}
if(!missing(compression)) {
warning("argument 'compression' ignored for provider 'oanda'")
}
url <-
paste("http://www.oanda.com/convert/fxhistory?lang=en&date1=",
format(start, "%m"), "%2F", format(start, "%d"), "%2F", format(start, "%Y"),
"&date=",
format(end, "%m"), "%2F", format(end, "%d"), "%2F", format(end, "%Y"),
"&date_fmt=us&exch=",
unlist(strsplit(instrument, split = "/"))[1],
"&exch2=&expr=",
unlist(strsplit(instrument, split = "/"))[2],
"&expr2=&margin_fixed=0&&SUBMIT=Get+Table&format=ASCII&redirected=1",
sep="")
destfile <- tempfile()
status <- download.file(url, destfile, method = method)
if(status != 0) {
unlink(destfile)
stop(paste("download error, status", status))
}
x <- readLines(destfile)
unlink(destfile)
if(length(grep("Sorry", x)) > 0) {
stop("time period is too big (maximum 2000 days can be downloaded)")
}
first <- which(substr(x, 1, 5) == "<PRE>")
last <- which(x == "</PRE>") - 1
if((length(first) == 0) || (length(last) == 0)) {
stop(paste("no data available for", instrument))
}
x[first] <- substr(x[first], 6, nchar(x[first]))
split <- strsplit(x[first:last], split = " ")
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")
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]))
}
else stop("provider not implemented")
}
......
......@@ -8,7 +8,7 @@
\usage{
get.hist.quote(instrument = "^gdax", start, end,
quote = c("Open", "High", "Low", "Close"),
provider = "yahoo", method = "auto",
provider = c("yahoo", "oanda"), method = "auto",
origin = "1899-12-30", compression = "d")
}
\arguments{
......@@ -28,10 +28,12 @@ get.hist.quote(instrument = "^gdax", start, end,
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. Abbreviations are allowed.}
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, only \code{"yahoo"} is implemented. See
\url{http://quote.yahoo.com/} for more information.}
provider. Currently, \code{"yahoo"} and \code{"oanda"} are
implemented. See \url{http://quote.yahoo.com/} and
\url{http://www.oanda.com/} for more information.}
\item{method}{tool to be used for downloading the data. See
\code{\link{download.file}} for the available download methods.}
\item{origin}{an R object specifying the origin of the Julian dates, see
......@@ -39,19 +41,22 @@ get.hist.quote(instrument = "^gdax", start, end,
internally also use Julian dates with this origin).}
\item{compression}{Governs the granularity of the retrieved data;
\code{"d"} for daily, \code{"w"} for weekly or \code{"m"} for
monthly. Defaults to \code{"d"}.}
monthly. Defaults to \code{"d"}. For the provider \code{"oanda"},
this argument is ignored.}
}
\value{
A time series containing the data in physical time, i.e., weekends,
holidays, and missing days are filled with \code{NA}s. The time scale
is given in Julian dates (days since the \code{origin}).
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{ts}},
\code{\link{as.POSIXct}},
\code{\link{download.file}};
\url{http://quote.yahoo.com/}
\url{http://quote.yahoo.com/},
\url{http://www.oanda.com/}
}
\examples{
if(!inherits(try(open(url("http://quote.yahoo.com")), silent = TRUE),
......@@ -67,6 +72,10 @@ if(!inherits(try(open(url("http://quote.yahoo.com")), silent = TRUE),
ibm <- get.hist.quote(instrument = "ibm", start = "1998-01-01")
x <- na.remove(ts.union(spc, ibm))
plot(x, main = "IBM vs S&P 500")
x <- get.hist.quote(instrument = "EUR/USD", provider = "oanda",
start = "2004-01-01")
plot(x, main = "EUR/USD")
}
}
\keyword{ts}
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