data_providers

Data Provider classes

data_provider.DataProvider

An interface for data providers (for example AbstractPriceDataProvider or GeneralPriceProvider).

abstract_price_data_provider.AbstractPriceDataProvider

An interface for data providers containing historical data of stocks, indices, futures and other asset classes.

bloomberg.bloomberg_data_provider.BloombergDataProvider

Data Provider which provides financial data from Bloomberg.

bloomberg_beap_hapi.bloomberg_beap_hapi_data_provider.BloombergBeapHapiDataProvider

Data Provider which provides financial data from Bloomberg BEAP HAPI.

preset_data_provider.PresetDataProvider

Wrapper on QFDataArray which makes it a DataProvider.

prefetching_data_provider.PrefetchingDataProvider

Optimises running of the DataProvider by pre-fetching all the data at startup and then using the cached data instead of sending over-the-network requests every time the data is requested.

general_price_provider.GeneralPriceProvider

The main class that should be used in order to access prices of financial instruments.

quandl.quandl_data_provider.QuandlDataProvider

Class providing the Quandl data.

haver.haver_data_provider.HaverDataProvider

Constructs a new HaverDataProvider instance.

portara.portara_data_provider.PortaraDataProvider

Loads Portara data for futures contracts.

csv.csv_data_provider.CSVDataProvider

Generic Data Provider that loads csv files.

Functions

chain_tickers_within_range(future_ticker, …)

Returns only these tickers belonging to the chain of a given FutureTicker, which were valid only for the given time frame.

normalize_data_array(data_array, tickers, …)

Post-processes the result of some DataProviders so that it satisfies the format of a result expected from DataProviders.

tickers_dict_to_data_array(…)

Converts a dictionary mapping tickers to DateFrame onto a QFDataArray,

qf_lib.data_providers.helpers.chain_tickers_within_range(future_ticker: qf_lib.containers.futures.future_tickers.future_ticker.FutureTicker, exp_dates: qf_lib.containers.dataframe.qf_dataframe.QFDataFrame, start_date: datetime.datetime, end_date: datetime.datetime)[source]

Returns only these tickers belonging to the chain of a given FutureTicker, which were valid only for the given time frame.

As it is possible to select the contracts to be traded for a given future ticker (e.g. for Bloomberg future tickers we could specify only to trade “M” contracts), the end date is computed as the original end date + 1 year x contract number to trade. E.g. if we specify that we only want to trade “M” contracts and we always want to trade the front M contract, we add 1 year x 1. If instead of the front M, we would like to trade the second next M contract, we add 2 years to the end date etc.

qf_lib.data_providers.helpers.normalize_data_array(data_array, tickers, fields, got_single_date, got_single_ticker, got_single_field, use_prices_types=False) → Union[qf_lib.containers.series.qf_series.QFSeries, qf_lib.containers.dataframe.qf_dataframe.QFDataFrame, qf_lib.containers.qf_data_array.QFDataArray, qf_lib.containers.series.prices_series.PricesSeries, qf_lib.containers.dataframe.prices_dataframe.PricesDataFrame][source]

Post-processes the result of some DataProviders so that it satisfies the format of a result expected from DataProviders. Expected format rules should cover the following: - proper return type (QFSeries/PricesSeries, QFDataFrame/PricesDataFrame, QFDataArray), - proper shape of the result (squeezed dimensions for which a single non-list value was provided, e.g. “OPEN”), - dimensions: TICKERS and FIELDS contain all required labels and the labels are in required order.

Parameters
  • data_array – data_array to be normalized

  • tickers – list of tickers requested by the caller

  • fields – list of fields requested by the caller

  • got_single_date – True if a single (scalar value) date was requested (start_date==end_date); False otherwise

  • got_single_ticker – True if a single (scalar value) ticker was requested (e.g. “MSFT US Equity”); False otherwise

  • got_single_field – True if a single (scalar value) field was requested (e.g. “OPEN”); False otherwise

  • use_prices_types – if True then proper return types are: PricesSeries, PricesDataFrame or QFDataArray; otherwise return types are: QFSeries, QFDataFrame or QFDataArray

Returns

Return type

QFSeries, QFDataFrame, QFDataArray, PricesSeries, PricesDataFrame

qf_lib.data_providers.helpers.tickers_dict_to_data_array(tickers_data_dict: Dict[qf_lib.common.tickers.tickers.Ticker, qf_lib.containers.dataframe.qf_dataframe.QFDataFrame], requested_tickers: Union[qf_lib.common.tickers.tickers.Ticker, Sequence[qf_lib.common.tickers.tickers.Ticker]], requested_fields: Union[Any, Sequence[Any]])qf_lib.containers.qf_data_array.QFDataArray[source]

Converts a dictionary mapping tickers to DateFrame onto a QFDataArray, by applying a filter on the tickers and fields that are needed

Parameters
  • tickers_data_dict (Dict[Ticker, QFDataFrame]) – Ticker -> QFDataFrame[dates, fields]

  • requested_tickers (Sequence[Ticker]) – Filter the data dict based on a list of tickers

  • requested_fields – Filter the data dict based on a list of fields

Returns

Return type

QFDataArray