PresetDataProvider¶
-
class
qf_lib.data_providers.preset_data_provider.
PresetDataProvider
(data: qf_lib.containers.qf_data_array.QFDataArray, start_date: datetime.datetime, end_date: datetime.datetime, frequency: qf_lib.common.enums.frequency.Frequency, exp_dates: Dict[qf_lib.containers.futures.future_tickers.future_ticker.FutureTicker, qf_lib.containers.dataframe.qf_dataframe.QFDataFrame] = None)[source]¶ Bases:
qf_lib.data_providers.data_provider.DataProvider
Wrapper on QFDataArray which makes it a DataProvider.
- Parameters
data – data to be wrapped, indexed by date, (specific) tickers and fields
start_date – beginning of the cached period (not necessarily the first date in the data)
end_date – end of the cached period (not necessarily the last date in the data)
frequency – frequency of the data
exp_dates – dictionary mapping FutureTickers to QFDataFrame of contracts expiration dates, belonging to the certain future ticker family
Methods
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_history
(tickers, …)Gets historical attributes (fields) of different securities (tickers).
get_price
(tickers, …)Gets adjusted historical Prices (Open, High, Low, Close) and Volume
Returns classes of tickers which are supported by this DataProvider.
-
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, Union[qf_lib.containers.series.qf_series.QFSeries, 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
tickers (FutureTicker, Sequence[FutureTicker]) – tickers for which should the future chain tickers be retrieved
expiration_date_fields (ExpirationDateField, Sequence[ExpirationDateField]) – field that should be downloaded as the expiration date field, by default last tradeable date
- 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_history
(tickers: Union[qf_lib.common.tickers.tickers.Ticker, Sequence[qf_lib.common.tickers.tickers.Ticker]], fields: Union[str, Sequence[str]], start_date: datetime.datetime, end_date: datetime.datetime = None, frequency: qf_lib.common.enums.frequency.Frequency = <Frequency.DAILY: 252>, **kwargs) → Union[qf_lib.containers.series.qf_series.QFSeries, qf_lib.containers.dataframe.qf_dataframe.QFDataFrame, qf_lib.containers.qf_data_array.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
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 returned.
- Return type
-
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
-
supported_ticker_types
() → Set[Type[qf_lib.common.tickers.tickers.Ticker]][source]¶ Returns classes of tickers which are supported by this DataProvider.