2017-05-27 167 views

回答

1

您可以按照我以前的post,這可能會幫助你。

我想:

library(quantmod) 
# Create an object containing the Pfizer ticker symbol 
symbol <- "PFE"  
# Use getSymbols to import the data 
getSymbols(symbol, src="yahoo", auto.assign=T) 
# because src='google' throws error, yahoo was used, and even that is down 

當我嘗試過其他來源,它的工作:

# "quantmod::oanda.currencies" contains a list of currencies provided by Oanda.com 
currency_pair <- "GBP/CAD"  
# Load British Pound to Canadian Dollar exchange rate data 
getSymbols(currency_pair, src="oanda") 
str(GBPCAD)  

,似乎有與谷歌問題和雅虎,而我們使用quantmod PKG。

我會建議你使用「Quandl」代替。 PLZ轉到Quandl網站,免費註冊和創建API密鑰,然後在下面複製:

# Install Quandl 
install.packages("Quandl") 
# or from github 
install.packages("devtools") 
library(devtools) 
install_github("quandl/quandl-r") 

# Load the Quandl package 
library(Quandl) 

# use API for full access 
Quandl.api_key("xxxxxx") 

# Download APPLE stock data 
mydata = Quandl::Quandl.datatable("ZACKS/FC", ticker="AAPL") 

對於HDFC在BSE,你可以使用:

hdfc = Quandl("BSE/BOM500180") 

瞭解更多詳情:

https://www.quandl.com/data/BSE-Bombay-Stock-Exchange?keyword=HDFC 
0

雅虎失敗後,我切換到eodhistoricaldata.com,幾個星期前我發現了一個很好的替代方案(https://eodhistoricaldata.com/),其API與Yahoo Finance非常相似。

基本上,幾乎所有的R腳本,我用我只是改變了這一點:

URL <- paste0("ichart.finance.yahoo.com/table.csv?s=", symbols[i]) 

到:

URL <- paste0("eodhistoricaldata.com/api/table.csv?s=", symbols[i]) 

然後加入一個API密鑰,它會以同樣的方式工作如前。我爲它節省了大量的R腳本。