Commit c59a78b9 authored by Dirk Eddelbuettel's avatar Dirk Eddelbuettel

Import Upstream version 0.10-42

parent 19944898
2017-06-21 Kurt Hornik <Kurt.Hornik@wu.ac.at>
* DESCRIPTION: New version is 0.10-42.
* R/finance.R (get.hist.quote): Fix problem spotted by
Thomas A Severini <severini@northwestern.edu>.
2017-05-29 Kurt Hornik <Kurt.Hornik@wu.ac.at>
* DESCRIPTION: New version is 0.10-41.
* R/finance.R:
* NAMESPACE:
Re-write get.hist.quote() as a wrapper for
quantmod::getSymbols().
2017-04-19 Kurt Hornik <Kurt.Hornik@wu.ac.at>
* R/finance.R (get.hist.quote):
* DESCRIPTION: New version is 0.10-40.
* R/finance.R (get.hist.quote):
* man/get.hist.quote.Rd:
* man/plotOHLC.Rd:
* man/plotOHLC.Rd:
http://quote.yahoo.com now redirects to https.
2017-04-18 Kurt Hornik <Kurt.Hornik@wu.ac.at>
......@@ -656,7 +674,7 @@
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()'.
......@@ -664,24 +682,24 @@
* man/maxdrawdown.Rd:
* R/finance.R:
* src/tsutils.c:
Simpler and more informative implementation of max drawdown
Simpler and more informative implementation of max drawdown
statistic.
* man/plotOHLC.Rd:
* R/finance.R:
* 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.
* R/tsutils.R: Call .C with 'mode = "double"' everywhere.
* man/maxdrawdown.Rd:
* R/finance.R:
......@@ -692,13 +710,13 @@
* DESCRIPTION (Version): New version is 0.7-6.
* src/arma.c: Correct nasty bug concerning accessing the
parameter intercept.
* 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
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>
......@@ -728,8 +746,8 @@
* DESCRIPTION (Version): New version is 0.7-4.
* R/test.R:
* man/terasvirta.test.Rd:
* R/test.R:
* man/terasvirta.test.Rd:
* man/white.test.Rd:
Use 'Chisq' instead of 'chisq' for argument 'type'.
......
Package: tseries
Version: 0.10-40
Version: 0.10-42
Title: Time Series Analysis and Computational Finance
Authors@R: c(person("Adrian", "Trapletti", role = "aut",
email = "adrian@trapletti.org"),
......@@ -9,13 +9,13 @@ Authors@R: c(person("Adrian", "Trapletti", role = "aut",
comment = "BDS test code"))
Description: Time series analysis and computational finance.
Depends: R (>= 2.10.0)
Imports: graphics, stats, utils, quadprog, zoo
Imports: graphics, stats, utils, quadprog, zoo, quantmod (>= 0.4.9)
License: GPL-2
NeedsCompilation: yes
Packaged: 2017-04-19 07:58:47 UTC; hornik
Packaged: 2017-06-21 18:26:43 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-04-19 08:29:57 UTC
Date/Publication: 2017-06-22 05:37:54 UTC
350b26da285cf21c7a0f63096a9d5de0 *ChangeLog
5fed6f8a7fe3df4a669b5c0eedd468f5 *DESCRIPTION
5f5a43a566e6cdf8f6f13199c78b399a *NAMESPACE
8c6070246896fe27b735d54281dd1639 *ChangeLog
2449dff30bf57f9a6dbef8f40550ffd7 *DESCRIPTION
cdc8894457c6efd2f1e49cfa79272d7b *NAMESPACE
c5a452ce3d1b330e8f92670ac8f0de83 *R/arma.R
85884205bb0d37fbcd9e74ff661d2afc *R/finance.R
0d02a6e601f51ccf3b1f0d21f9ca0df2 *R/finance.R
72ee630e802dbee4b151d9d1efd31ca3 *R/garch.R
decf4a3134c069cf9d2dbc79b1b60706 *R/irts.R
0ce6494a5006b2e8c4cc5e87e00993f7 *R/test.R
......@@ -24,12 +24,12 @@ a3fd00105442c79dbe9d8097b5877f40 *man/USeconomic.Rd
f5b98a0cc9d1fc856692cf6f169c1ab5 *man/arma-methods.Rd
51bcd384cff3224af080545728dbf1cf *man/arma.Rd
af95a59d763942cc81ad5d3f60a8394c *man/bds.test.Rd
13d25052f8297ba99eaf53a620d5020a *man/bev.Rd
89173da2154e0d28b27bd2e9d00c983b *man/camp.Rd
af544e3ec3d8abaab6402a886d5429cf *man/bev.Rd
96eca9b4b82e7bf3e6f743ce21a5d9d8 *man/camp.Rd
35c28a6707e4e01f789be2117c646664 *man/garch-methods.Rd
6e9e94d717f01d4208a8fa29e0ea28d2 *man/garch.Rd
8259b9b4397915ab701374d8b3373428 *man/get.hist.quote.Rd
d78ea694dcc885f7a4df3e89efff2788 *man/ice.river.Rd
973d2524c38ae728a98b4a00c753a4d8 *man/get.hist.quote.Rd
dad4d5b3dc8d236fa5455b0abbd294b2 *man/ice.river.Rd
d1b8f7e9d68bae68eea050d9efedb11b *man/irts-functions.Rd
82628e1b908072d5572db16d8d4fd2fa *man/irts-methods.Rd
98a04ff66d5647b616d4957e316b0011 *man/irts.Rd
......
......@@ -3,6 +3,7 @@ useDynLib("tseries", .registration = TRUE)
import("graphics", "stats", "utils")
importFrom("quadprog", "solve.QP")
importFrom("zoo", "zoo", "index", "index<-")
importFrom("quantmod", "getSymbols")
export("adf.test", "approx.irts", "arma", "as.irts",
"bds.test",
......
......@@ -132,200 +132,58 @@ 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"), method = NULL,
origin = "1899-12-30", compression = "d",
retclass = c("zoo", "ts"),
quiet = FALSE, drop = FALSE)
## Added new argument 'compression'.
## May be "d", "w" or "m", for daily weekly or monthly.
## Defaults to "d".
## John Bollinger, 2004-10-27, www.BollingerBands.com, bbands@yahoo.com
##
## Changed POSIXct class to Date class, 2005-03-31
## Added drop= arg, 2006-06-04
function(instrument = "^gdax", start, end,
quote = c("Open", "High", "Low", "Close"),
provider = c("yahoo"), method = NULL,
origin = "1899-12-30", compression = "d",
retclass = c("zoo", "ts"),
quiet = FALSE, drop = FALSE)
{
if(missing(start)) start <- "1991-01-02"
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)
if(is.null(method)) {
method <- getOption("download.file.method")
if(is.null(method))
method <- "auto"
}
periodicity <- match.arg(compression,
c("daily", "weekly", "monthly"))
if(provider == "yahoo") {
url <-
paste("https://ichart.finance.yahoo.com/table.csv?s=",
instrument,
format(start,
paste("&a=",
as.character(as.numeric(format(start, "%m"))-1),
"&b=%d&c=%Y",
sep = "")),
format(end,
paste("&d=",
as.character(as.numeric(format(end, "%m"))-1),
"&e=%d&f=%Y",
sep = "")),
"&g=", compression,
"&q=q&y=0&z=", instrument,
"&x=.csv",
sep = "")
destfile <- tempfile()
## Be nice.
ind <- pmatch(quote, "AdjClose", nomatch = 0L)
quote[ind] <- "Adjusted"
## Try downloading several times.
## Could make this controllable ...
i <- 1L
repeat {
status <- tryCatch(download.file(url, destfile,
method = method,
quiet = quiet),
error = identity)
if(!inherits(status, "error") && (status == 0))
break
unlink(destfile)
if(i >= 5L) {
if(inherits(status, "error"))
stop(conditionMessage(status))
else
stop(sprintf("download error, status %d", status))
}
message("download error, retrying ...")
i <- i + 1L
}
nlines <- length(count.fields(destfile, sep = "\n"))
if(nlines == 1) {
unlink(destfile)
stop(paste("no data available for", instrument))
}
## Yahoo includes rows concerning dividends,
## hence need fill = TRUE and na.omit
x <- read.table(destfile, header = TRUE, sep = ",", as.is = TRUE, fill = TRUE)
x <- na.omit(x)
start <- as.Date(start)
end <- as.Date(end)
## As of 2012-07-07,
## get.hist.quote("ibm", start = "2012-07-06", end = "2012-07-06")
## gives two entries for 2012-07-06 ...
## Fix (hopefully only needed temporarily?) suggested by AZ.
if(nrow(x) >= 2L && x[1L, 1L] == x[2L, 1L]) {
warning("first date duplicated, first instance omitted")
x <- x[-1L, , drop = FALSE]
}
## Debug
## cat("read.table: start =", x[NROW(x),"Date"], "\n")
## 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")
n <- nrow(x)
x <- getSymbols(instrument, src = "yahoo",
from = start, to = end, return.class = "zoo",
periodicity = periodicity, auto.assign = FALSE)
colnames(x) <- sub(".*\\.", "", colnames(x))
nser <- pmatch(quote, colnames(x))
if(any(is.na(nser)))
stop("this quote is not available")
n <- nrow(x)
## Yahoo now seems to format dates as %Y-%m-%d.
dat <- as.Date(as.character(x[, 1]), "%Y-%m-%d")
if(!quiet && (dat[n] != start))
cat(format(dat[n], "time series starts %Y-%m-%d\n"))
if(!quiet && (dat[1] != end))
cat(format(dat[1], "time series ends %Y-%m-%d\n"))
dat <- index(x)
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"))
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, nrow = max(ind), ncol = length(nser))
y[ind, ] <- as.matrix(x[, nser, drop = FALSE])
colnames(y) <- names(x)[nser]
y <- y[, seq_along(nser), drop = drop]
return(ts(y, start = jdat[n], end = jdat[1]))
} else {
x <- as.matrix(x[, nser, drop = FALSE])
rownames(x) <- NULL
y <- zoo(x, dat)
y <- y[, seq_along(nser), drop = drop]
return(y)
}
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[1] + 1
y <- matrix(NA, nrow = max(ind), ncol = length(nser))
y[ind, ] <- as.matrix(x[, nser, drop = FALSE])
colnames(y) <- colnames(x)[nser]
y <- y[, seq_along(nser), drop = drop]
return(ts(y, start = jdat[1], end = jdat[n]))
} else {
x[ , nser, drop = drop]
}
## <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")
}
maxdrawdown <-
......
......@@ -22,7 +22,7 @@ data(bev)
}
\source{
Time Series Data Library:
\url{http://www-personal.buseco.monash.edu.au/~hyndman/TSDL/}
\url{https://robjhyndman.com/TSDL/}
}
\references{
R. T. Baillie (1996):
......
......@@ -23,6 +23,6 @@ data(camp)
}
\source{
Time Series Data Library:
\url{http://www-personal.buseco.monash.edu.au/~hyndman/TSDL/}
\url{https://robjhyndman.com/TSDL/}
}
\keyword{datasets}
......@@ -28,16 +28,14 @@ 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"}, \code{"AdjClose"}, and
\code{"Volume"}, respectively. For the provider \code{"oanda"},
this argument is ignored. Abbreviations are allowed.}
\code{"High"}, \code{"Low"}, \code{"Close"}, \code{"Adjusted"}, and
\code{"Volume"}, respectively. Abbreviations are allowed.}
\item{provider}{a character string with the name of the data
provider. Currently, \code{"yahoo"} is implemented, see
\url{https://finance.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.}
provider. Currently, only \code{"yahoo"} is supported via
\code{\link[quantmod:getSymbols.yahoo]{getSymbols}} from package
\pkg{quantmod} for the Yahoo Finance source.
Provider \code{"oanda"} is no longer available.}
\item{method}{No longer used.}
\item{origin}{an R object specifying the origin of the Julian dates, see
above. Defaults to 1899-12-30 (Popular spreadsheet programs
internally also use Julian dates with this origin).}
......@@ -64,12 +62,12 @@ get.hist.quote(instrument = "^gdax", start, end,
}
\author{A. Trapletti}
\seealso{
\code{\link[quantmod]{getSymbols}} for downloads from various
providers;
\code{\link[zoo]{zoo}},
\code{\link{ts}},
\code{\link{as.Date}},
\code{\link{as.POSIXct}},
\code{\link{download.file}};
\url{https://finance.yahoo.com/}
}
\examples{
con <- url("https://finance.yahoo.com")
......@@ -85,7 +83,7 @@ if(!inherits(try(open(con), silent = TRUE), "try-error")) {
spc <- get.hist.quote(instrument = "^gspc", start = "1998-01-01",
quote = "Close")
ibm <- get.hist.quote(instrument = "ibm", start = "1998-01-01",
quote = "AdjClose")
quote = "Adj")
require("zoo") # For merge() method.
x <- merge(spc, ibm)
plot(x, main = "IBM vs S&P 500")
......
......@@ -31,7 +31,7 @@ data(ice.river)
}
\source{
Time Series Data Library:
\url{http://www-personal.buseco.monash.edu.au/~hyndman/TSDL/}
\url{https://robjhyndman.com/TSDL/}
}
\references{
H. Tong (1990):
......
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