Download Stock Data From Yahoo Finance

  • May 19, 2017 - Free stock data can alternatively be downloaded from Quandl with a similar script, but for ETFs they want 50 bucks per month (I hope they didn't.
  • Oct 8, 2018 - The majority of people use Yahoo Finance to obtain updated quotes for traded securities all around the world. However, it can be a useful.

Hi I recently took up a project about bitcoin analysis and need to download financial data from Yahoo! Finance via Python. I tried fix_yahoo_finance and pandas datareader but there seems to be a bug on the website when downloading files. It always miss some days. So I decided to use beautiful soup, the code is as follow:

It works but the data is not complete because the website loads the data when your mouse scroll s down to the end of the page, but codes doesn't do that. How can I fix this?

Rookie0007Rookie0007

10 New Ways to Download Historical Stock Quotes for Free Here is a list of websites that provide end of day historical data for US and international stock markets. All the quotes data provided by the websites listed here can be exported to CSV or Excel format.

2 Answers

Yahoo used to have a financial api, they've terminated it since, there is a workaround though.

I've used this with success before, you might want to take a look at it.

psrcekpsrcek

Have you tries using Yahoo Financials? It's really well built and doesn;t scrap the webpages. It hashes out the data you want from the ['context']['dispatcher']['stores'] object. It's pretty fast and really well built.

$ pip install yahoofinancials

Usage Examples:

Output Example:

Download

returns

alt777alt777

Not the answer you're looking for? Browse other questions tagged pythonpandasbeautifulsoupyahoo-finance or ask your own question.

Is there a way to automatically download historical prices of stocks from yahoo finance or google finance (csv format)? Preferably in Python.

BobBob

5 Answers

Short answer: Yes. Use Python's urllib to pull the historical data pages for the stocks you want. Go with Yahoo! Finance; Google is both less reliable, has less data coverage, and is more restrictive in how you can use it once you have it. Also, I believe Google specifically prohibits you from scraping the data in their ToS.

Longer answer: This is the script I use to pull all the historical data on a particular company. It pulls the historical data page for a particular ticker symbol, then saves it to a csv file named by that symbol. You'll have to provide your own list of ticker symbols that you want to pull.

Joe C.Joe C.

When you're going to work with such time series in Python, pandas is indispensable. And here's the good news: it comes with a historical data downloader for Yahoo: pandas.io.data.DataReader.

Update for pandas >= 0.19:

The pandas.io.data module has been removed from pandas>=0.19 onwards. Instead, you should use the separate pandas-datareader package. Install with:

And then you can do this in Python:

Def_OsDef_Os

Extending @Def_Os's answer with an actual demo...

As @Def_Os has already said - using Pandas Datareader makes this task a real fun

pulling all available historical data for AAPL starting from 1980-01-01

first 5 rows

last 5 rows

save all data as CSV file

d:/temp/aapl_data.csv - 5 first rows

MaxUMaxU

There is already a library in Python called yahoo_finance so you'll need to download the library first using the following command line:

Then once you've installed the yahoo_finance library, here's a sample code that will download the data you need from Yahoo Finance:

This should do it. Let me know if it works.

UPDATE:The yahoo_finance library is no longer supported.

NaufalNaufal

Download Historical Quotes Yahoo Finance

You can check out the yahoo_fin package. It was initially created after Yahoo Finance changed their API (documentation is here: http://theautomatic.net/yahoo_fin-documentation).

atreadwatreadw

protected by CommunityAug 3 '16 at 1:39

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?

Download Data From Yahoo Finance

Not the answer you're looking for? Browse other questions tagged pandasfinanceyahoo-financegoogle-financestockquotes or ask your own question.