Designing and Backtesting Multi-Contract Spread Strategies
Summary
This document explains how to build a multi-contract strategy using synchronized bar data, per-leg targets, and order management. Its example computes the spread between two weighted contract prices, updates a rolling window, and uses Bollinger Bands to enter opposing positions when the spread moves beyond a band. It exits when the spread returns to the middle band. Orders are sized from the difference between target and current positions, with stale orders canceled before each signal check.
The backtesting discussion describes loading historical bars and matching limit orders against the next bar’s high, low, and open. It also outlines strategy lifecycle operations such as initialization, start, stop, editing, and removal. These are implementation examples, not performance results. The text notes that a bar-based multi-leg simulation cannot determine the sequence of fills within a bar, and that the described module only supports limit orders and lacks stop-order support; simulated fills may therefore differ from live execution.
Key ideas
- A spread can be formed from weighted prices of two contracts and tracked over time.
- The example enters when the spread exceeds a rolling band and exits near its midpoint.
- Target holdings determine the order quantity for each leg.
- The backtest matches limit orders against the next bar’s price range and open.
- Bar-based multi-leg backtests cannot resolve the sequence of fills within a bar.
Tags
From a private course collection; the original is not published.