1

我正在尝试使用quantmod::getSymbols. 帮助文件指出,每个请求您只能下载 500 天的数据,而我从warnings(). 尽管如此,我还是尝试创建一个循环来下载从 1997 年至今的数据。这是我的代码:

library(xts)
library(quantmod)

date_from = c("1996-01-01", "2001-01-02", "2005-01-03", "2009-01-03", "2013-01-04")
date_to = c("2001-01-01", "2005-01-02", "2009-01-03", "2013-01-03", "2016-01-04")
for (i in 1:5) {
  getSymbols("EUR/AUD", src="oanda", from = dates_from[i], to = date_to[i])
  forex = for (i=1) EURAUD else NULL
  final_Dataset<- rbind(c(forex, EURAUD))
}

我应该实施哪些改变?


编辑 1 我让它工作了,但它写得很草率。任何提议的更改将不胜感激。

date_from = c("1996-01-01", "2001-01-02", "2005-01-03", "2009-01-03", "2013-01-04")
date_to = c("2001-01-01", "2005-01-02", "2009-01-03", "2013-01-03", "2016-01-04")
forex = vector(mode = 'list', length = 5)
for (i in 1:5) {
  getSymbols("EUR/AUD", src="oanda", from = dates_from[i], to = date_to[i])
  forex[[i]] = EURAUD
}
EUR_AUD = Reduce(rbind,forex)
4

1 回答 1

0

您可以通过循环一个相隔 500 天的日期向量来做到这一点。请注意,由于前 2 个开始日期不起作用,所以我将getSymbols电话包裹起来。try我不确定为什么。

require(quantmod)
Data <- do.call(rbind, lapply(dates, function(d) {
  sym <- "EUR/AUD"
  x <- try(getSymbols(sym, src="oanda", from=d, to=d+499, auto.assign=FALSE))
  if (inherits(x, "try-error"))
    return(NULL)
  else
    return(x)
}))
于 2016-08-20T00:41:04.673 回答