How to use getReturns with the Yahoo finance API

与世无争的帅哥 提交于 2019-12-09 07:01:38

问题


I have problems with R package getReturns. I have encountered this error since 17th May:

Warning in file(file, "rt") : cannot open URL 'http://ichart.finance.yahoo.com/table.csv?s=AAPL&a=4&b=28&c=2014&d=4&e=27&f=2017&g=w&ignore=.csv': HTTP status was '404 Not Found'

It looks like that ichart API did not run anymore. Can anyone help me with this issue? Does someone know how to fix it? I have encountered the same issue with the quantmod R package.


回答1:


You can follow my an earlier post, which might help you.

I tried :

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

When I tried other source, it worked:

# "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)    

It seems there are issues with google and yahoo while we use quantmod pkg.

I will suggest you to use 'Quandl' instead. Plz goto Quandl website, register for free and create API key, and then copy it in below:

# 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")

For HDFC at BSE, you can use:

hdfc = Quandl("BSE/BOM500180")

for more details:

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



回答2:


I have encountered this problem as well. Yahoo! has taken down ichart and the open-source libraries that rely on it are now broken. Yahoo! also has no plans to introduce a replacement. For more information, see this post on Yahoo!'s Forums.




回答3:


I switched to eodhistoricaldata.com after Yahoo failed, several weeks ago I found good alternative with an API very similar to Yahoo Finance.

Basically, for almost all R scripts I use I just changed this:

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

to:

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

Then add an API key and it will work in the same way as before. I saved a lot of time for my R scripts on it.



来源:https://stackoverflow.com/questions/44221631/how-to-use-getreturns-with-the-yahoo-finance-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!