Solved: Errors Downloading Stock Price Data from Yahoo Finance

Posted on May 21, 2017 by Kris Longmore
16 comments
6,083 Views

Recently, Yahoo Finance – a popular source of free end-of-day price data – made some changes to their server which wreaked a little havoc on anyone relying on it for their algos or simulations. Specifically, Yahoo Finance switched from HTTP to HTTPS and changed the data download URLs. No doubt this is a huge source of frustration, as many backtesting and trading scripts that relied on such data will no longer work.
Users of the excellent R package quantmod  however are in luck! The package’s author, Joshua Ulrich, has already addressed the change in a development version of quantmod. You can update your quantmod  package to the development version that addresses this issue using this command in R:
devtools::install_github(“joshuaulrich/quantmod”, ref=”157_yahoo_502″)
Of course, you need the devtools  package installed, so do install.packages(“devtools”)  first if you don’t already have it installed.
Once the package updates, quantmod::getSymbols(src = “yahoo”)  should work just as it did prior to the updates on the Yahoo Finance server. I can verify that this worked for me.
Of course, if you don’t want to update quantmod to a version that lives on a Git branch, you can wait until the changes are merged into master and do
devtools::install_github(“joshuaulrich/quantmod”)
I don’t know when that will happen, but I have been using the branch version for a few days now, and all appears to be working as expected.
Update: A user suggested making use of the quantmod::adjustOHLC() function as the adjusted close of Yahoo data is currently incomplete, and doesn’t account for dividends. Example usage:

adjustOHLC(x,
    adjust = c(“split”,”dividend”),
    use.Adjusted = FALSE,
    ratio = NULL,
    symbol.name=deparse(substitute(x)))

 


First time here? Check out our posts on machine learning in finance and our recent review of dual momentum as an investment strategy. Enjoy!

(16) Comments

[…] Solved: Errors Downloading Stock Price Data from Yahoo Finance [Robot Wealth] […]

Jeff
May 21, 2017 at 5:44 pm

Hey Kris, thanks very much for this! Been struggling massively with this for a while now.

May 21, 2017 at 5:47 pm

My pleasure, Jeff. I’m only the messenger here though, all credit to Josh Ulrich, the quantmod package developer.

May 31, 2017 at 6:11 am

Hi Kris,
when running the install_github function I got the following error:
> install_github(“joshuaulrich/quantmod”, ref=”157_yahoo_502″)
Installation failed: Couldn’t connect to server
Any advice? was the Git branch deactivated?
Thanks!
Tom

May 31, 2017 at 11:10 pm

Hey Tom, I just had a look at the Github repo. It looks like the updates have been merged into the master branch. You can install the master branch direct from the repo by doing devtools::install_github("joshuaulrich/quantmod")
Obviously make sure you do install.packages('devtools') first if you don’t already have it installed.
Some users have reported having to restart R Studio if using that platform as your IDE.
Hope that helps!

May 22, 2017 at 9:11 am

Thanks for the method – it works.
Unfortunately, old good Yahoo is not that good anymore – dividend adjustments absent for some tickers, so backtests of all my systems got worse due to that. Need to find new better data source… =(

Peter Jacobson
May 22, 2017 at 9:27 am

Hi Kris,
Thank you for posting this.  My R code that used quantmod and getSymbols no longer worked, so a solution would be welcome.
I use RStudio.  I updated devtools, and then executed the R command you suggested:
devtools::install_github(“joshuaulrich/quantmod”, ref=“157_yahoo_502”), which ran without error.

However here is the result:
library(quantmod)
getSymbols(‘F’)
Error in curl::curl_download(paste0(yahoo.URL, Symbols.name, “?period1=”, :
HTTP error 401.
I am an R novice, so surely I did something wrong.  Any clues?
Thank you.

May 22, 2017 at 11:03 pm

I couldn’t reproduce this error. quantmod::getSymbols('F') worked fine for me.
Try restarting R Studio after updating quantmod.

Peter Jacobson
May 23, 2017 at 1:07 am

Thank you Kris! It worked after restarting R studio.

Minjae Lee
May 22, 2017 at 1:52 pm

But it reflects only splits, not dividend as Google..

May 22, 2017 at 11:09 pm

Indeed for me too I can confirm that for some assets we have splits but no dividends.

May 24, 2017 at 9:49 pm

One user suggested using quantmod::adjustOHCL() to get adjustments for dividends and splits, which seems now to be missing for yahoo data. Example usage as follows;
adjustOHLC(x,
adjust = c(“split”,”dividend”),
use.Adjusted = FALSE,
ratio = NULL,
symbol.name=deparse(substitute(x)))
I haven’t tested this.

August 16, 2017 at 11:43 pm

[…] Errors Downloading Yahoo Finance Stock Price Data … – Recently, Yahoo Finance switched from HTTP to HTTPS and changed the data download URLs. You can update your quantmod package to addresses this issue in R. […]

Caryl
December 13, 2017 at 9:57 pm

Hi Kris,
thank you for your help, I am still struggling with this issue. I am getting this error. Can you help please ?
options(“getSymbols.yahoo.warning”=FALSE).
Error in curl::curl_download(cu, tmp, handle = h) :
Failed to connect to finance.yahoo.com port 443: Timed out

January 10, 2018 at 11:05 am

Hi Caryl, sorry for the slow response! This should be solved from version 0.4-9 of quantmod. The current version on CRAN should work, so maybe try updating to the latest version and retesting.

[…] useful tidbits of algo trading practicalities, here’s an elegant solution that resolves Yahoo’s unceremonious exit from the free financial data space. Regular readers would know that I use various tools in my algo trading stack, but the one I keep […]

Leave a Comment