AbstractPriceDataProvider

class qf_lib.data_providers.abstract_price_data_provider.AbstractPriceDataProvider[source]

Bases: qf_lib.data_providers.data_provider.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, …)

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

price_field_to_str_map(ticker)

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(ticker)

Inverse of price_field_to_str_map.

abstract expiration_date_field_str_map(ticker: qf_lib.common.tickers.tickers.Ticker = None) → Dict[qf_lib.common.enums.expiration_date_field.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[qf_lib.containers.futures.future_tickers.future_ticker.FutureTicker, Sequence[qf_lib.containers.futures.future_tickers.future_ticker.FutureTicker]], expiration_date_fields: Union[qf_lib.common.enums.expiration_date_field.ExpirationDateField, Sequence[qf_lib.common.enums.expiration_date_field.ExpirationDateField]]) → Dict[qf_lib.containers.futures.future_tickers.future_ticker.FutureTicker, qf_lib.containers.dataframe.qf_dataframe.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[qf_lib.common.tickers.tickers.Ticker, Sequence[qf_lib.common.tickers.tickers.Ticker]], fields: Union[qf_lib.common.enums.price_field.PriceField, Sequence[qf_lib.common.enums.price_field.PriceField]], start_date: datetime.datetime, end_date: datetime.datetime = None, frequency: qf_lib.common.enums.frequency.Frequency = <Frequency.DAILY: 252>) → Union[None, qf_lib.containers.series.prices_series.PricesSeries, qf_lib.containers.dataframe.prices_dataframe.PricesDataFrame, qf_lib.containers.qf_data_array.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(ticker: qf_lib.common.tickers.tickers.Ticker = None) → Dict[qf_lib.common.enums.price_field.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.

Parameters

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

Returns

mapping between PriceFields and corresponding strings

Return type

Dict[PriceField, str]

str_to_expiration_date_field_map(ticker: qf_lib.common.tickers.tickers.Ticker = None) → Dict[str, qf_lib.common.enums.expiration_date_field.ExpirationDateField][source]

Inverse of str_to_expiration_date_field_map.

str_to_price_field_map(ticker: qf_lib.common.tickers.tickers.Ticker = None) → Dict[str, qf_lib.common.enums.price_field.PriceField][source]

Inverse of price_field_to_str_map.