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

Import Upstream version 0.10-39

parent 600dc930
2017-04-18 Kurt Hornik <Kurt.Hornik@wu.ac.at>
* DESCRIPTION: New version is 0.10-39.
* R/finance.R (get.hist.quote):
* man/get.hist.quote.Rd:
Drop provider 'oanda' which now requires registration.
2017-02-20 Kurt Hornik <Kurt.Hornik@wu.ac.at>
* DESCRIPTION: New version is 0.10-38.
......
Package: tseries
Version: 0.10-38
Version: 0.10-39
Title: Time Series Analysis and Computational Finance
Authors@R: c(person("Adrian", "Trapletti", role = "aut",
email = "adrian@trapletti.org"),
......@@ -12,10 +12,10 @@ Depends: R (>= 2.10.0)
Imports: graphics, stats, utils, quadprog, zoo
License: GPL-2
NeedsCompilation: yes
Packaged: 2017-02-20 18:48:56 UTC; hornik
Packaged: 2017-04-18 10:57:09 UTC; hornik
Author: Adrian Trapletti [aut],
Kurt Hornik [aut, cre],
Blake LeBaron [ctb] (BDS test code)
Maintainer: Kurt Hornik <Kurt.Hornik@R-project.org>
Repository: CRAN
Date/Publication: 2017-02-20 20:21:26
Date/Publication: 2017-04-18 11:22:27 UTC
b61c9f16b78d5dcb66e11efc9c4c99f3 *ChangeLog
58dd4327ab75e179d28e247adc9b0b52 *DESCRIPTION
75ec489f3ade18ce825fe8e6b2f7be5d *ChangeLog
5bedaa6d98dcf6861d2ef686ad8f21d3 *DESCRIPTION
5f5a43a566e6cdf8f6f13199c78b399a *NAMESPACE
c5a452ce3d1b330e8f92670ac8f0de83 *R/arma.R
4d47ac4e99712ced9371bedab34386ac *R/finance.R
1355a604f955d083efb33d1751cc19d4 *R/finance.R
72ee630e802dbee4b151d9d1efd31ca3 *R/garch.R
decf4a3134c069cf9d2dbc79b1b60706 *R/irts.R
0ce6494a5006b2e8c4cc5e87e00993f7 *R/test.R
9db11950b82d51c34320a7baea82bd52 *R/tsutils.R
6474314852bc0951b0cc3848febd98dc *R/zzz.R
e311649f01da4c522be8ff61cb4776a2 *README
1b0dd6b7b4405d1674d36ebb260a0e88 *data/NelPlo.rda
de15c4a0f35b7203b0e588423672ae5d *data/USeconomic.rda
35e6ab5de4981702953c510b9722173d *data/bev.rda
05a82fb1ece652decf2bf91e0400d454 *data/camp.rda
af6623975e787d0ece10ecd835c6385d *data/ice.river.rda
cbfda34e2f3b41607f706059d83ab8d4 *data/nino.rda
2c0770251879a828e2c73ad3a2fd081a *data/tcm.rda
ee43fc05e3b28b067798d02d83632ea2 *data/tcmd.rda
7f6ad0ff2e50b54d2e7504273fc3cd30 *data/NelPlo.rda
8309f230b4b6bf1a2f8b07d91d392dc0 *data/USeconomic.rda
b7b5a733d5754caad200e1793d2a9da8 *data/bev.rda
16aac91060dbd981c6cd3805adb0abac *data/camp.rda
e5b9e27f480baaff643ea35a1aedc6ee *data/ice.river.rda
b7cf8e327fadbfed4e0b9fc38e703f21 *data/nino.rda
d34d786954b4a2a1572ad831126afa1c *data/tcm.rda
8ec8d004687dd2976895782bbff9c17d *data/tcmd.rda
ce27980f11ae3cdfe19a1da71b3db73e *inst/CITATION
39c832867f0093af08dba56ed7c89504 *man/NelPlo.Rd
a3fd00105442c79dbe9d8097b5877f40 *man/USeconomic.Rd
......@@ -28,7 +28,7 @@ af95a59d763942cc81ad5d3f60a8394c *man/bds.test.Rd
89173da2154e0d28b27bd2e9d00c983b *man/camp.Rd
35c28a6707e4e01f789be2117c646664 *man/garch-methods.Rd
6e9e94d717f01d4208a8fa29e0ea28d2 *man/garch.Rd
ea26557ba6f36c4501e684433ee51a64 *man/get.hist.quote.Rd
efb2aed4190d74738049b0c4194808fa *man/get.hist.quote.Rd
d78ea694dcc885f7a4df3e89efff2788 *man/ice.river.Rd
d1b8f7e9d68bae68eea050d9efedb11b *man/irts-functions.Rd
82628e1b908072d5572db16d8d4fd2fa *man/irts-methods.Rd
......
......@@ -134,7 +134,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 = c("yahoo", "oanda"), method = NULL,
provider = c("yahoo"), method = NULL,
origin = "1899-12-30", compression = "d",
retclass = c("zoo", "ts"),
quiet = FALSE, drop = FALSE)
......@@ -259,67 +259,72 @@ function (instrument = "^gdax", start, end,
return(y)
}
}
else if(provider == "oanda") {
if(!missing(quote)) {
warning("argument 'quote' ignored for provider 'oanda'")
}
if(!missing(compression)) {
warning("argument 'compression' ignored for provider 'oanda'")
}
currencies <- unlist(strsplit(instrument, split = "/"))
ranges <- c("d7", "d30", "d60", "d90", "d180", "y1", "y2", "y5")
range <- ranges[c(7, 30, 60, 90, 180, 364, 728, 1820) >=
difftime(end, start, units="days")][1]
url <- paste0("https://www.oanda.com/currency/historical-rates/download?",
"quote_currency=", currencies[1],
"&end_date=", end,
"&start_date=", start,
"&period=daily",
"&display=absolute",
"&rate=0",
"&data_range=", range,
"&price=mid",
"&view=table",
"&base_currency_0=", currencies[2],
"&base_currency_1=",
"&base_currency_2=",
"&base_currency_3=",
"&base_currency_4=",
"&download=csv")
destfile <- tempfile()
status <- download.file(url, destfile, method = method, quiet = quiet)
if(status != 0) {
unlink(destfile)
stop(paste("download error, status", status))
}
x <- read.csv(destfile, skip = 4, as.is = TRUE, header = TRUE)
unlink(destfile)
x <- head(x, -3)
dat <- rev(as.Date(x[[1]]))
n <- length(dat)
if(!quiet && (dat[1] != start))
cat(format(dat[1], "time series starts %Y-%m-%d\n"))
if(!quiet && (dat[n] != end))
cat(format(dat[n], "time series ends %Y-%m-%d\n"))
val <- rev(x[[2]])
if(is.character(val))
val <- as.numeric(sub(",", "", val, fixed = TRUE))
if(retclass == "ts") {
jdat <- unclass(julian(dat, origin = as.Date(origin)))
ind <- jdat - jdat[1] + 1
y <- rep.int(NA, max(ind))
y[ind] <- val
return(ts(y, start = jdat[1], end = jdat[n]))
} else {
y <- zoo(val, dat)
return(y)
}
}
## <NOTE>
## As of 2017-04, OANDA more or less requires registration.
## (Apparently, one can still get <= 180 days of historical data via
## JSON but not CSV, for the time being ...)
## </NOTE>
## else if(provider == "oanda") {
## if(!missing(quote)) {
## warning("argument 'quote' ignored for provider 'oanda'")
## }
## if(!missing(compression)) {
## warning("argument 'compression' ignored for provider 'oanda'")
## }
##
## currencies <- unlist(strsplit(instrument, split = "/"))
## ranges <- c("d7", "d30", "d60", "d90", "d180", "y1", "y2", "y5")
## range <- ranges[c(7, 30, 60, 90, 180, 364, 728, 1820) >=
## difftime(end, start, units="days")][1]
## url <- paste0("https://www.oanda.com/currency/historical-rates/download?",
## "quote_currency=", currencies[1],
## "&end_date=", end,
## "&start_date=", start,
## "&period=daily",
## "&display=absolute",
## "&rate=0",
## "&data_range=", range,
## "&price=mid",
## "&view=table",
## "&base_currency_0=", currencies[2],
## "&base_currency_1=",
## "&base_currency_2=",
## "&base_currency_3=",
## "&base_currency_4=",
## "&download=csv")
## destfile <- tempfile()
##
## status <- download.file(url, destfile, method = method, quiet = quiet)
## if(status != 0) {
## unlink(destfile)
## stop(paste("download error, status", status))
## }
##
## x <- read.csv(destfile, skip = 4, as.is = TRUE, header = TRUE)
## unlink(destfile)
## x <- head(x, -3)
##
## dat <- rev(as.Date(x[[1]]))
## n <- length(dat)
## if(!quiet && (dat[1] != start))
## cat(format(dat[1], "time series starts %Y-%m-%d\n"))
## if(!quiet && (dat[n] != end))
## cat(format(dat[n], "time series ends %Y-%m-%d\n"))
## val <- rev(x[[2]])
## if(is.character(val))
## val <- as.numeric(sub(",", "", val, fixed = TRUE))
##
## if(retclass == "ts") {
## jdat <- unclass(julian(dat, origin = as.Date(origin)))
## ind <- jdat - jdat[1] + 1
## y <- rep.int(NA, max(ind))
## y[ind] <- val
## return(ts(y, start = jdat[1], end = jdat[n]))
## } else {
## y <- zoo(val, dat)
## return(y)
## }
## }
else stop("provider not implemented")
}
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -8,7 +8,7 @@
\usage{
get.hist.quote(instrument = "^gdax", start, end,
quote = c("Open", "High", "Low", "Close"),
provider = c("yahoo", "oanda"), method = NULL,
provider = c("yahoo"), method = NULL,
origin = "1899-12-30", compression = "d",
retclass = c("zoo", "ts"), quiet = FALSE, drop = FALSE)
}
......@@ -32,9 +32,9 @@ get.hist.quote(instrument = "^gdax", start, end,
\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
\url{https://www.oanda.com/} for more information.}
provider. Currently, \code{"yahoo"} is implemented, see
\url{http://quote.yahoo.com/} for more information. Provider
\code{"oanda"} is no longer available.}
\item{method}{tool to be used for downloading the data. See
\code{\link{download.file}} for the available download methods and
the default settings.}
......@@ -69,8 +69,7 @@ get.hist.quote(instrument = "^gdax", start, end,
\code{\link{as.Date}},
\code{\link{as.POSIXct}},
\code{\link{download.file}};
\url{http://quote.yahoo.com/},
\url{https://www.oanda.com/}
\url{http://quote.yahoo.com/}
}
\examples{
con <- url("http://quote.yahoo.com")
......@@ -91,13 +90,5 @@ if(!inherits(try(open(con), silent = TRUE), "try-error")) {
x <- merge(spc, ibm)
plot(x, main = "IBM vs S&P 500")
}
con <- url("https://www.oanda.com")
if(!inherits(try(open(con), silent = TRUE), "try-error")) {
close(con)
x <- get.hist.quote(instrument = "EUR/USD", provider = "oanda",
start = Sys.Date() - 500)
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