Single Futures Roll


Working with futures contracts has the unique problem that a given contract has an expiration date. To ensure the adequacy of the data, we need to account for the “switching” between the contracts that expire and the ones that take their place.

Simply performing an auto-roll and stitching the contracts together doesn’t account for the price difference between the old contract and the new one when the expiry date actually comes. Often this difference is quite small, however, for some contracts, it can be quite substantial (especially if the underlying asset has high carry costs).

Ignoring the price difference may lead to false spikes/pitfalls around the expiry data that, in their turn, may falsely signify a trading opportunity where actually there is none.

The answer to the problem is the “ETF trick” from the Advances in Financial Machine Learning by professor Marcos Lopez de Prado.


“The ETF trick can handle the rolls of a single futures contract, as a particular case of a 1-legged spread. However, when dealing with a single futures contract, an equivalent and more direct approach is to form a time series of cumulative roll gaps, and detract that gaps series from the price series.”


On further expirations the adjustment factor need to be accounted for as follows:

  • Absolute returns: adjustment_factor = previous_adjustment_factor + new_roll_gap.

  • Relative returns: adjustment_factor = previous_adjustment_factor * new_roll_gap.

To generate the correct continuous contract, a 3-step procedure needs to be performed:

  1. Get absolute and relative roll gaps.

  2. Filter out rows with price info of the nearest contract only.

  3. Apply the roll gaps on the copy of the first contract.


Code implementation demo


Code example demo

Research Notebook

The following research notebooks can be used to better understand the Futures Roll.

Notebook demo