FuturesChain¶
-
class
qf_lib.containers.futures.futures_chain.
FuturesChain
(future_ticker: qf_lib.containers.futures.future_tickers.future_ticker.FutureTicker, data_provider: DataProvider, method: qf_lib.containers.futures.futures_adjustment_method.FuturesAdjustmentMethod = <FuturesAdjustmentMethod.NTH_NEAREST: (0, )>)[source]¶ Bases:
pandas.core.series.Series
Class which facilitates the futures contracts management. Its main functionality is provided by the get_price function, which returns a PricesDataFrame (PricesSeries) of prices for the given FutureTicker, automatically managing the contracts chaining.
- Parameters
future_ticker (FutureTicker) –
- The FutureTicker used to download the futures contracts, further chained and joined in order to obtain the
result of get_price function.
data_provider (DataProvider) – Reference to the data provider, necessary to download latest prices, returned by the get_price function. In case of backtests, the DataHandler wrapper should be used to avoid looking into the future.
method (FuturesAdjustmentMethod) – FuturesAdjustmentMethod corresponding to one of two available methods of chaining the futures contracts.
Methods
get_price
(fields, …)Combines consecutive specific FutureContracts data, in order to obtain a chain of prices.
-
get_price
(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, frequency: qf_lib.common.enums.frequency.Frequency = <Frequency.DAILY: 252>) → Union[qf_lib.containers.dataframe.prices_dataframe.PricesDataFrame, qf_lib.containers.series.prices_series.PricesSeries][source]¶ Combines consecutive specific FutureContracts data, in order to obtain a chain of prices.
- Parameters
fields (PriceField, Sequence[PriceField]) – Data fields, corresponding to Open, High, Low, Close prices and Volume, that should be returned by the function.
start_date (datetime) – First date for which the chain needs to be created.
end_date (datetime) – Last date for which the chain needs to be created.
frequency (Frequency) – Frequency of the returned data, by default set to daily frequency.
- Returns
- Return type