DataProvider

class qf_lib.data_providers.data_provider.DataProvider(timer: Optional[Timer] = None)[source]

Bases: object

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

Methods:

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

Gets historical attributes (fields) of different securities (tickers).

supported_ticker_types()

Returns classes of tickers which are supported by this DataProvider.

abstract get_history(tickers: Union[Ticker, Sequence[Ticker]], fields: Union[None, str, Sequence[str]], start_date: datetime, end_date: Optional[datetime] = None, frequency: Optional[Frequency] = None, look_ahead_bias: bool = False, **kwargs) Union[QFSeries, QFDataFrame, QFDataArray][source]

Gets historical attributes (fields) of different securities (tickers).

All the duplicate fields and tickers will be removed (the first occurrence will remain). This is crucial for having the expected behavior with using label-based indices. E.g. let’s assume there is a duplicate ticker ‘SPX Index’ in tickers list and the result data frame has two columns ‘SPX Index’. Then when someone runs result.loc[:, ‘SPX Index’], he expects to get a series of ‘SPX Index’ values. However he’ll get a data frame with two columns, both named ‘SPX Index’. If someone insists on keeping duplicate values in index/columns, then it’s possible to reindex the result (e.g. result.reindex(columns=tickers)).

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

  • fields (None, str, Sequence[str]) – fields of securities which should be retrieved. If None, all available fields will be returned (only supported by few DataProviders)

  • 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

  • look_ahead_bias (bool) – if set to False, the look-ahead bias will be taken care of to make sure no future data is returned

  • kwargs – kwargs should not be used on the level of AbstractDataProvider. They are here to provide a common interface for all data providers since some of the specific data providers accept additional arguments

Returns:

If possible the result will be squeezed, so that instead of returning QFDataArray, data of lower dimensionality will be returned. The results will be either an QFDataArray (with 3 dimensions: date, ticker, field), a QFDataFrame (with 2 dimensions: date, ticker or field; it is also possible to get 2 dimensions ticker and field if single date was provided) or QFSeries (with 1 dimensions: date). If no data is available in the database or an non existing ticker was provided an empty structure (QFSeries, QFDataFrame or QFDataArray) will be returned.

Return type:

QFSeries, QFDataFrame, QFDataArray

abstract supported_ticker_types() Set[Type[Ticker]][source]

Returns classes of tickers which are supported by this DataProvider.