AbstractPriceDataProvider

class qf_lib.data_providers.abstract_price_data_provider.AbstractPriceDataProvider[source]

Bases: DataProvider

An interface for data providers containing historical data of stocks, indices, futures and other asset classes. This is a base class of any simple data provider (a data provider that is associated with single data base, for example: Quandl, Bloomberg, Yahoo.)

Methods:

expiration_date_field_str_map([ticker])

Method has to be implemented in each data provider in order to be able to use get_futures_chain_tickers.

get_futures_chain_tickers(tickers, ...)

Returns tickers of futures contracts, which belong to the same futures contract chain as the provided ticker (tickers), along with their expiration dates in form of a QFSeries or QFDataFrame.

get_price(tickers, fields, start_date[, ...])

Gets adjusted historical Prices (Open, High, Low, Close) and Volume

price_field_to_str_map()

Method has to be implemented in each data provider in order to be able to use get_price.

str_to_expiration_date_field_map([ticker])

Inverse of str_to_expiration_date_field_map.

str_to_price_field_map()

Inverse of price_field_to_str_map.

abstract expiration_date_field_str_map(ticker: Optional[Ticker] = None) Dict[ExpirationDateField, str][source]

Method has to be implemented in each data provider in order to be able to use get_futures_chain_tickers. Returns dictionary containing mapping between ExpirationDateField and corresponding string that has to be used by get_futures_chain_tickers method.

Parameters:

ticker (None, Ticker) – ticker is optional and might be uses by particular data providers to create appropriate dictionary

Returns:

mapping between ExpirationDateField and corresponding strings

Return type:

Dict[ExpirationDateField, str]

get_futures_chain_tickers(tickers: Union[FutureTicker, Sequence[FutureTicker]], expiration_date_fields: Union[ExpirationDateField, Sequence[ExpirationDateField]]) Dict[FutureTicker, QFDataFrame][source]

Returns tickers of futures contracts, which belong to the same futures contract chain as the provided ticker (tickers), along with their expiration dates in form of a QFSeries or QFDataFrame.

Parameters:
Returns:

Returns a dictionary, which maps Tickers to QFSeries, consisting of the expiration dates of Future Contracts: Dict[FutureTicker, Union[QFSeries, QFDataFrame]]]. The QFSeries’ / QFDataFrames contain the specific Tickers, which belong to the corresponding futures family, same as the FutureTicker, and are indexed by the expiration dates of the specific future contracts.

Return type:

Dict[FutureTicker, Union[QFSeries, QFDataFrame]]

get_price(tickers: Union[Ticker, Sequence[Ticker]], fields: Union[PriceField, Sequence[PriceField]], start_date: datetime, end_date: Optional[datetime] = None, frequency: Frequency = Frequency.DAILY, **kwargs) Union[None, PricesSeries, PricesDataFrame, QFDataArray][source]

Gets adjusted historical Prices (Open, High, Low, Close) and Volume

Parameters:
  • tickers (Ticker, Sequence[Ticker]) – tickers for securities which should be retrieved

  • fields (PriceField, Sequence[PriceField]) – fields of securities which should be retrieved

  • start_date (datetime) – date representing the beginning of historical period from which data should be retrieved

  • end_date (datetime) – date representing the end of historical period from which data should be retrieved; if no end_date was provided, by default the current date will be used

  • frequency (Frequency) – frequency of the data

Returns:

If possible the result will be squeezed so that instead of returning QFDataArray (3-D structure), data of lower dimensionality will be returned. The results will be either an QFDataArray (with 3 dimensions: dates, tickers, fields), PricesDataFrame (with 2 dimensions: dates, tickers or fields. It is also possible to get 2 dimensions ticker and field if single date was provided), or PricesSeries with 1 dimension: dates. All the containers will be indexed with PriceField whenever possible (for example: instead of ‘Close’ column in the PricesDataFrame there will be PriceField.Close)

Return type:

None, PricesSeries, PricesDataFrame, QFDataArray

abstract price_field_to_str_map() Dict[PriceField, str][source]

Method has to be implemented in each data provider in order to be able to use get_price. Returns dictionary containing mapping between PriceField and corresponding string that has to be used by get_history method to get appropriate type of price series.

Returns:

mapping between PriceFields and corresponding strings

Return type:

Dict[PriceField, str]

str_to_expiration_date_field_map(ticker: Optional[Ticker] = None) Dict[str, ExpirationDateField][source]

Inverse of str_to_expiration_date_field_map.

str_to_price_field_map() Dict[str, PriceField][source]

Inverse of price_field_to_str_map.