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.
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.
Downloader()
from yahoo_downloader import Downloader
downloader = Downloader()
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.
Return the currently set ticker and year range in (ticker, years)
tuple.
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