YahooFinanceAPI
YahooFinanceAPI is a small wrapper that is meant solely to retrieve historical data from Yahoo Finance.
Installation
pip install YahooFinanceAPI
Functions
The function declarations for the limited functionality are listed below with
comments.
set_interval(interval)
get_ticker_data(ticker, start_date, end_date)
get_data_for_tickers(tickers, start_date, end_date)
Usage
Acceptable intervals are 1d (default), 1wk, and 1mo. The API only offers the
ability to retrieve data for a ticker or a list of tickers. The results are returned
as a Pandas dataframe and include the following columns:
Date
Open
High
Low
Close
Adj Close
Volume
Example usage, as seen in example.py:
from yfapi import YahooFinanceAPI, Interval
dh = YahooFinanceAPI(Interval.WEEKLY)
now = datetime.datetime(2020, 6, 28)
then = datetime.datetime(2020, 1, 1)
df = dh.get_ticker_data("msft", then, now)
dh.set_interval(Interval.MONTHLY)
data_dict = dh.get_data_for_tickers(['msft', 'aapl', 'amzn'], then, now)