A continuous futures series can produce a large price change even when neither contract moves. If your backtest's cash balance responds to that jump, start by checking how the system identifies the instrument behind each price.

This article was drafted using an AI writing tool. All prices and fees are synthetic. The Python example uses only the standard library.

Keep a continuous symbol out of the position ledger

A continuous symbol is convenient for pulling a history or calculating a signal. The position ledger needs the identifier of the actual contract. Your engine must be able to say which contract it held, when it changed, and which fills changed it. Some data providers preserve the raw prices of the mapped contracts, so a continuous request can contain the full price gap at the switch. Databento's continuous contract documentation

A useful data model keeps these records available:

Record Fields to retain
Signal input Continuous symbol, series convention and version, observation cutoff, active contract ID
Roll decision Old and new contract IDs, rule, input availability time, decision timestamp, target quantities
Execution Contract ID, side, timestamp, quantity, fill price, multiplier, fee, and a shared roll ID
Valuation Contract ID, mark timestamp, price, and source

Use actual fill events to update inventory. If the near-month sale fills and the next-month buy is still working, the ledger should reflect the interim exposure. If fills arrive in pieces, reconcile each piece with its own size and price. An exchange-listed spread can be modeled as a spread execution with the underlying leg information needed for the ledger. CME Group's guide to rolling with spreads

Use two independent calculations

The following fixture rolls one long position at a constant multiplier. The benchmark old and new prices are 101 and 104. The actual sell and buy fills are 100.95 and 104.10. The old position was previously marked at 100. The new position is subsequently marked at 105.

from decimal import Decimal as D def long_roll_pnl(old_mark, old_sell, new_buy, new_mark, multiplier, fees): old_pnl = (old_sell - old_mark) * multiplier new_pnl = (new_mark - new_buy) * multiplier return old_pnl, new_pnl, old_pnl + new_pnl - fees def test_flat_contracts(): multiplier = D("500") for near, far in ((D("100"), D("104")), (D("104"), D("100"))): result = long_roll_pnl(near, near, far, far, multiplier, D("0")) assert result == (D("0"), D("0"), D("0")) def test_fill_pnl_and_spread_reconciliation(): multiplier = D("500") fees = D("25") benchmark_old, benchmark_new = D("101"), D("104") actual_old, actual_new = D("100.95"), D("104.10") benchmark = long_roll_pnl( D("100"), benchmark_old, benchmark_new, D("105"), multiplier, D("0") ) actual = long_roll_pnl( D("100"), actual_old, actual_new, D("105"), multiplier, fees ) benchmark_spread = benchmark_new - benchmark_old executed_spread = actual_new - actual_old execution_shortfall = (executed_spread - benchmark_spread) * multiplier assert benchmark == (D("500"), D("500"), D("1000")) assert actual == (D("475"), D("450"), D("900")) assert execution_shortfall == D("75") assert benchmark[2] - execution_shortfall - fees == actual[2] if __name__ == "__main__": test_flat_contracts() test_fill_pnl_and_spread_reconciliation() print("All roll reconciliation assertions passed.") 

The flat-contract test runs both an upward and a downward splice. The first case gives the chart a four-point jump. The second gives it a four-point drop. Both should have zero ledger P&L.

The execution test gives you two reconciliation paths. One starts from the actual fills. The other starts from benchmark P&L and deducts execution shortfall and fees. If both paths are correct, they land at $900. The spread convention and sign in this fixture are for a one-for-one long roll. For shorts, unequal quantities, or different multipliers, compute signed P&L by leg and construct the benchmark using those same exposures.

Add a separate clock test

The fixture checks accounting. The event loop also needs an integration test for information timing. Suppose the roll trigger compares full-session volumes after a completed session becomes available at 4:10 p.m. local exchange time. Your order simulator receives an otherwise valid price at 9:30 a.m. that morning. The test should reject that price as an execution for this decision. The next eligible price must arrive after the trigger information and the order become available to the simulator.

A second timing test should stage the legs. Sell the old contract at one timestamp and buy the new contract later. Mark the portfolio between those events. Its position should agree with the fills processed so far. This catches engines that switch the entire position as soon as the signal changes even if one leg has yet to trade.

Make mismatches visible at the roll level

For a KAEL AI research implementation, link every accounting row back to a roll ID and keep benchmark attribution separate from booked P&L. That makes three failure signatures easy to trace:

  • A gain or loss with flat individual contracts points to a splice being used as a position price change.
  • An actual-fill total of $825 in the example points to the $75 execution shortfall being deducted twice.
  • A fill earlier than the data-availability timestamp points to a scheduling or information leak.

Finally, compare the sum of roll-level entries with the portfolio result around each switch. When rolls are spread over several sessions, carry the old and new positions independently and value each against its own contract. A continuous symbol can drive a signal while the trade ledger remains reproducible to the individual fill.