无法从谷歌下载R数据
我正在使用两个文件。第一个文件是实际的代码和第二个文件是参考文件无法从谷歌下载R数据
##########################################
## Daily prices from Yahoo
## [email protected] - Nov. 2015
##########################################
library(quantmod)
startDate = "2014-01-01"
thePath = "D:\\daily\\data\\"
cattest <- file("D:\\daily\\error\\error.csv", open = "w")
source(paste("D:\\Reference\\","listOfInstruments.r",sep=""))
cattest <- file("D:\\daily\\error\\error.csv", open = "a")
for (ii in theInstruments)
tryCatch(
{
print(ii)
data = getSymbols(Symbols = ii,
src = "google",
from = startDate,
auto.assign = TRUE,verbose = TRUE)
colnames(data) = c("Date","Open","High","Low","Close","Volume")
write.zoo(data,paste(thePath,ii,".csv",sep=""),sep=",",row.names=FALSE)
}
,error=function(e){cat(ii, "\n", file=cattest)})
close(cattest)
我试图下载使用下面的代码来自谷歌的数据,但它不下载任何东西什么我做错了这里
Reference file
##########################################
## List of securities (Yahoo tickers)
## [email protected] - Nov. 2015
##########################################
theInstruments = c("^GSPC",
"SPY",
"QQQ",
"DDM",
"EFA",
"EEM",
"EWJ")
错误似乎是
done.
Warning messages:
1: In fname %in% c("break", "next") :
closing unused connection 3 (D:\daily\error\error.csv)
2: In download.file(paste(google.URL, "q=", Symbols.name, "&startdate=", :
cannot open URL 'http://finance.google.com/finance/historical?q=^GSPC&startdate=Jan+01,+2014&enddate=Jun+16,+2017&output=csv': HTTP status was '404 Not Found'
显然,你无法从谷歌下载S &普500指数数据。所以要么使用Yahoo Finance,要么从工具列表中排除^GSPC
。
theInstruments = c("SPY",
"QQQ",
"DDM",
"EFA",
"EEM",
"EWJ")
startDate = "2014-01-01"
getSymbols(theInstruments, src = "google",
from = startDate)
新代码:
startDate = "2000-01-01"
thePath = "D:\\daily\\data\\"
source(paste(thePath,"code\\listOfInstruments.r",sep=""))
for (ii in theInstruments){
print(ii)
data = getSymbols(Symbols = ii,
src = "yahoo",
from = startDate,
auto.assign = FALSE)
colnames(data) = c("open","high","low","close","volume","adj.")
write.zoo(data,paste(thePath,ii,".csv",sep=""),sep=",",row.names=FALSE)
}
我确实排除了它仍然不下载 – NewtoPython
没有错误可以修改我的代码以保存到Windows上的文件plss – NewtoPython
我还是不工作############# ############################# ##证券清单(雅虎代码) ## [email protected] - 11月。 2015 ########################################## theInstruments = c(“ DDM“, ”EFA“, ”EEM“, ”EWJ“) – NewtoPython
你得到什么样的错误/消息的? – AK88
@ AK88更新问题 – NewtoPython