quantdata.yahoo.client#

Yahoo finance

class quantdata.yahoo.client.YFConnectionConfig(max_retries=5, timeout=1.0)[source]#

Bases: object

Configuration for managing yfinance/yaoo connectivity

max_retries: int = 5#
timeout: float = 1.0#
exception quantdata.yahoo.client.DataError[source]#

Bases: Exception

Exception raised when data retrieved from yahoo is inconsistent or insufficient.

class quantdata.yahoo.client.YFClient[source]#

Bases: object

Yahoo Finance Client

validate_status()[source]#

Check that I am not in test mode

NO_EARNINGS_TYPES = {'CRYPTOCURRENCY', 'CURRENCY', 'ETF', 'FUTURE', 'INDEX', 'MUTUALFUND', 'OPTION'}#

Instrument types which do not have earnings

SCHEMA_HAS_EARNINGS = {'date': Date, 'is_earnings': Boolean}#

Schema for the pandas.DataFrame returned by has_earnings()

has_earnings(ticker, start, end)[source]#

Use yfinance to get earnings dates and ex-dividend dates for a ticker.

PRICE_FIELDS = {'Close', 'Dividends', 'High', 'Low', 'Open', 'Stock Splits', 'Volume'}#

Fields returned by prices() and expected to be present in the data frame returned by yahoo.

prices(ticker, start, end, *, yfconnection_config=YFConnectionConfig(max_retries=5, timeout=1.0))[source]#

Downloads one ticker from yahoo using yfinance and applies some basic consistency checks.

The function returns a pandas data frame with the fields Close, High, Low, Open, Volume, Dividends and Stock Splits, see also PRICE_FIELDS. The index of the data frame are the historic dates. All rows with NaNs are removed.

Checks performed:

  • All required fields are present.

  • Close, Low, High, Open are positive

  • High > Low (please note yahoo data does not include Open/Close in Low/High)

Parameters:
  • ticker (str) – Ticker such as AAPL.

  • start (date) – Start of the period.

  • end (date) – End of the period.

  • yfconnection_config (YFConnectionConfig) – Configuration for managing yfinance/yaoo connectivity, such as timeouts and retry counts.

Returns:

Result – Non-empty dataframe with the data from yahoo. Its index are the historic dates.

Return type:

pandas.DataFrame

:raises Inconsistent data returned : AttributeError: Raised if the data returned from yahoo did not contain the expected column headers. :raises Timeout : TimeoutError: Raised if yf.download

timed out.

Raises:

Data error – DataError: Raised if data validation fails.