0

Yahoo Finance recently changed its historical data URLs from http to https. For example, here is the URL to obtain the maximum history for IBM (as of today, 2017-05-29):

https://query1.finance.yahoo.com/v7/finance/download/IBM?period1=-252345600&period2=1496041200&interval=1d&events=history&crumb=jIIyoewBT2o

When I try to read this resource from within R I get the following:

> url = 'https://query1.finance.yahoo.com/v7/finance/download/IBM?period1=-252345600&period2=1496041200&interval=1d&events=history&crumb=jIIyoewBT2o'
> read.csv(url)
Error in file(file, "rt") : 
  (converted from warning) cannot open URL 'https://query1.finance.yahoo.com/v7/finance/download/IBM?period1=-252345600&period2=1496041200&interval=1d&events=history&crumb=jIIyoewBT2o': HTTP status was '401 Unauthorized'

The download works fine when invoked manually through the browser, so it's not like Yahoo Finance is trying to prevent access to the data. Evidently, the browser is sending some secret sauce to the Yahoo server. Can I send the same secret sauce through an R script?

Argent
  • 885
  • 2
  • 9
  • 18
  • Check [this](https://stackoverflow.com/questions/44083891/started-to-get-error-while-downloading-data-from-yahoo-finance-using-r/). – Eldioo May 29 '17 at 17:45
  • See this link: https://stackoverflow.com/questions/44015838/cant-download-data-from-yahoo-finance-using-quantmod-in-r?noredirect=1&lq=1 – Dave2e May 30 '17 at 00:40

2 Answers2

0

I think Yahoo did away with its API a few months ago. If you want an Excel solution, you can download a sample file from the link titled "Get Excel Spreadsheet to Download Bulk Historical Stock Data from Google Finance"

http://investexcel.net/multiple-stock-quote-downloader-for-excel/

enter image description here

For R, do something like this.

library(BatchGetSymbols)

first.date <- Sys.Date()-365
last.date <- Sys.Date()

df.SP500 <- GetSP500Stocks()
tickers <- df.SP500$tickers

l.out <- BatchGetSymbols(tickers = tickers,
                         first.date = first.date,
                         last.date = last.date)

print(l.out$df.control)
print(l.out$df.tickers)
ASH
  • 20,759
  • 19
  • 87
  • 200
0

Current version of "free" Deriscope downloads both historical data and live feeds from YF.

Yannis
  • 125
  • 1
  • 5