FuturesChain

class qf_lib.containers.futures.futures_chain.FuturesChain(future_ticker: FutureTicker, data_provider: DataProvider, method: FuturesAdjustmentMethod = FuturesAdjustmentMethod.NTH_NEAREST)[source]

Bases: 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.

  • method (FuturesAdjustmentMethod) – FuturesAdjustmentMethod corresponding to one of two available methods of chaining the futures contracts.

Methods:

get_price(fields, start_date, end_date[, ...])

Combines consecutive specific FutureContracts data, in order to obtain a chain of prices.

get_price(fields: Union[PriceField, Sequence[PriceField]], start_date: datetime, end_date: datetime, frequency: Frequency = Frequency.DAILY) Union[PricesDataFrame, 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.

Return type:

PricesDataFrame, PricesSeries