Skip to content

Download stock quotes from the new Yahoo Finance API to pandas DataFrames

License

Notifications You must be signed in to change notification settings

somiandras/python-yahoo-finance-download

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Download data from Yahoo Finance API

Get quote, dividend and split history for a given ticker symbol from a specified starting date to today.

Inspired by c0redumb's yahoo_quote_download and rubenafo's YahooFetcher, but implemented using requests for fetching data, and returning Pandas dataframes.

New Yahoo API

Yahoo Finance changed how their stock data API works as of May, 2017. The data is still available on Yahoo Finance pages, but the new API uses authentication via a cookie and a 'crumb'. This module obtains these with an initial request and uses them for the subsequent requests.

For the Yahoo Finance API changes read c0redumb's description.

Class

Downloader()

from yahoo_downloader import Downloader

downloader = Downloader()

Methods

downloader.get_history(ticker, years=20)

Returns quotes, dividends and splits in single Pandas DataFrame for the given ticker and specified number of years ending today (or the latest available).

Splits are filled with 1s between split dates and dividends filled with 0s between ex-dividend dates (as in the Quandl Python API) to make further adjustments easier. No other transformations are made on Yahoo Finance data.

downloader.settings()

Return the currently set ticker and year range in (ticker, years) tuple.

Example

from yahoo_downloader import Downloader

downloader = Downloader()

# Full data:
df = downloader.get_history('MSFT', years=10)

# Check settings:
settings = downloader.settings()
print(settings)

>>> ('MSFT', 10)

print(df.info())

<class 'pandas.core.frame.DataFrame'>
Index: 2518 entries, '2007-06-08' to '2017-06-07'
Data columns (total 8 columns):
Open            2518 non-null float64
High            2518 non-null float64
Low             2518 non-null float64
Close           2518 non-null float64
Adj Close       2518 non-null float64
Volume          2518 non-null int64
Dividends       2518 non-null float64
Stock Splits    2518 non-null int64
dtypes: float64(6), int64(2)
memory usage: 177.0+ KB

About

Download stock quotes from the new Yahoo Finance API to pandas DataFrames

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages