Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 创建循环,通过quantmod包从Oanda下载10年数据_R_Loops_Quantmod_Forex - Fatal编程技术网

R 创建循环,通过quantmod包从Oanda下载10年数据

R 创建循环,通过quantmod包从Oanda下载10年数据,r,loops,quantmod,forex,R,Loops,Quantmod,Forex,我正在尝试使用quantmod::getSymbols下载批量Oanda外汇数据。帮助文件指出,每个请求只能下载500天的数据,而我从warnings()中得到了一条关于5年数据上限的警告。尽管如此,我还是尝试创建一个循环来下载1997年至今的数据。这是我的代码: library(xts) library(quantmod) date_from = c("1996-01-01", "2001-01-02", "2005-01-03", "2009-01-03", "2013-01-04") d

我正在尝试使用
quantmod::getSymbols
下载批量Oanda外汇数据。帮助文件指出,每个请求只能下载500天的数据,而我从
warnings()
中得到了一条关于5年数据上限的警告。尽管如此,我还是尝试创建一个循环来下载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))
}

您可以通过在相隔500天的日期向量上循环来实现这一点。注意,我包装了
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)
}))
require(quantmod)

数据你可以通过循环一个相隔500天的日期向量来实现这一点。注意,我包装了
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)
}))
require(quantmod)

警告数据不正确。限制已经有500天的历史了,谢谢你的评论。警告是不正确的。限制已经有500天的历史了,谢谢你的评论。