Package: yfinanceng
Yahoo! Finance-ng python3 / pandas market data downloaderEver sinceYahoo! financedecommissioned
their historical data API, many programs that relied on it to stop working.yfinancengaimes to solve this problem by offering a reliable, threaded,
and Pythonic way to download historical market data from Yahoo! finance.NOTEThe library was originally namedyfinance, but
I’ve since renamed it toyfinancengas I no longer consider it a mere “fix”, and the author is
not promptly maintaining it or merging PRs.Changelog »Quick StartThe Ticker moduleTheTickermodule, which allows you to access
ticker data in amore Pythonic way:importyfinancengasyfmsft=yf.Ticker("MSFT")# get stock infomsft.info# get historical market datahist=msft.history(period="max")# show actions (dividends, splits)msft.actions# show dividendsmsft.dividends# show splitsmsft.splits# show financialsmsft.financialsmsft.quarterly_financials# show major holdersmsft.major_holders# show institutional holdersmsft.institutional_holders# show balance heetmsft.balance_sheetmsft.quarterly_balance_sheet# show cashflowmsft.cashflowmsft.quarterly_cashflow# show earningsmsft.earningsmsft.quarterly_earnings# show sustainabilitymsft.sustainability# show analysts recommendationsmsft.recommendations# show next event (earnings, etc)msft.calendar# show ISIN code - *experimental*# ISIN = International Securities Identification Numbermsft.isin# show options expirationsmsft.options# get option chain for specific expirationopt=msft.option_chain('YYYY-MM-DD')# data available via: opt.calls, opt.putsIf you want to use a proxy server for downloading data, use:importyfinancengasyfmsft=yf.Ticker("MSFT")msft.history(...,proxy="PROXY_SERVER")msft.get_actions(proxy="PROXY_SERVER")msft.get_dividends(proxy="PROXY_SERVER")msft.get_splits(proxy="PROXY_SERVER")msft.get_balance_sheet(proxy="PROXY_SERVER")msft.get_cashflow(proxy="PROXY_SERVER")msgt.option_chain(...,proxy="PROXY_SERVER")...To initialize multipleTickerobjects, useimportyfinancengasyftickers=yf.Tickers('msft aapl goog')# ^ returns a named tuple of Ticker objects# access each ticker using (example)tickers.msft.infotickers.aapl.history(period="1mo")tickers.goog.actionsFetching data for multiple tickersimportyfinancengasyfdata=yf.download("SPY AAPL",start="2017-01-01",end="2017-04-30")I’ve also added some options to make life easier :)data=yf.download(# or pdr.get_data_yahoo(...# tickers list or string as welltickers="SPY AAPL MSFT",# use "period" instead of start/end# valid periods: 1d,5d,1mo,3mo,6mo,1y,2y,5y,10y,ytd,max# (optional, default is '1mo')period="ytd",# fetch data by interval (including intraday if period < 60 days)# valid intervals: 1m,2m,5m,15m,30m,60m,90m,1h,1d,5d,1wk,1mo,3mo# (optional, default is '1d')interval="1m",# group by ticker (to access via data['SPY'])# (optional, default is 'column')group_by='ticker',# adjust all OHLC automatically# (optional, default is False)auto_adjust=True,# download pre/post regular market hours data# (optional, default is False)prepost=True,# use threads for mass downloading? (True/False/Integer)# (optional, default is True)threads=True,# proxy URL scheme use use when downloading?# (optional, default is None)proxy=None)pandas_datareaderoverrideIf your code usespandas_datareaderand you want to download data faster,
you can “hijack”pandas_datareader.data.get_data_yahoo()method to useyfinancengwhile making sure the returned data is in the same format aspandas_datareader’sget_data_yahoo().frompandas_datareaderimportdataaspdrimportyfinancengasyfyf.pdr_override()# <== that's all it takes :-)# download dataframedata=pdr.get_data_yahoo("SPY",start="2017-01-01",end="2017-04-30")InstallationInstallyfinancengusingpip:$pipinstallyfinanceng--upgrade--no-cache-dirInstallyfinancengusingconda:$condainstall-clarroyyfinancengRequirementsPython>= 3.6+Pandas(tested to work with >=0.23.1)Numpy>= 1.11.1requests>= 2.14.2Optional (if you want to usepandas_datareader)pandas_datareader>= 0.4.0Legal Stuffyfinancengis distributed under theApache Software License. See theLICENSE.txtfile in the release for details.Based onyfinancefromRan Aroussi.