无法从 R 中的 google 下载数据

unable to download data from google in R

我正在使用两个文件。第一个文件是实际代码,第二个文件是参考文件

##########################################
## Daily prices from Yahoo 
## thertrader@gmail.com - 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)

我正在尝试使用 google 中的以下代码下载数据,但它没有下载任何东西我在这里做错了什么

Reference file

##########################################
## List of securities (Yahoo tickers) 
## thertrader@gmail.com - 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'

显然,您无法从 Google 下载标准普尔 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)
}