Solved: Errors Downloading Stock Price Data from Yahoo Finance

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 thoughts on “Solved: Errors Downloading Stock Price Data from Yahoo Finance”

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

      Reply
      • 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

        Reply
        • 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!

          Reply
  1. 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… =(

    Reply
  2. 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.

    Reply
  3. 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.

    Reply
  4. 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

    Reply
    • 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.

      Reply

Leave a Comment