How to use getReturns with Yahoo's Finance API
I'm having problems with the R package getReturns
. I ran into this error since May 17th:
Warning in file ("rt" file): Unable to 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 the API ichart
is not starting anymore. Can anyone help me with this question? Does anyone know how to fix this? I faced the same problem with quantmod
R.
source to share
You can follow my previous post which may 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 another 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)
There seems to be problems with google and yahoo while we are using quantmod pkg.
I suggest you use "Quandl" instead. Plz goto Quandl, sign up for free and create an API key then copy it 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 on BSE you can use:
hdfc = Quandl("BSE/BOM500180")
for more details:
https://www.quandl.com/data/BSE-Bombay-Stock-Exchange?keyword=HDFC
source to share
I switched to eodhistoricaldata.com after Yahoo's failure, a few weeks ago I found a 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 the API key and it will work the same as before. I saved a lot of time for my R scripts on it.
source to share