𝗦𝗰𝗮𝗿𝗮𝗯 𝗗𝗶𝗮𝗴𝗻𝗼𝘀𝘁𝗶𝗰 𝗙𝗶𝗲𝗹𝗱 𝗧𝗲𝘀𝘁 #𝟬𝟯𝟭
QuantConnect Lean needed better control over continuous futures rolls.
Users faced two main problems:
- They could not set roll timing before expiry.
- They could not select specific contract-month cycles.
This is not a simple bug. It is a mapping policy issue.
If you try to fix this by creating a new roll calendar, you break the engine. If you duplicate mapping data, you create errors. A bad patch can cause drift between what a strategy wants and what the engine does.
The goal was to find a surgical repair lane.
The solution stays inside the existing mapping boundary. We do not rewrite the futures engine. Instead, we extend how Lean handles continuous futures mapping.
What changed in the PR:
- Added a TradingDaysBeforeExpiry mapping mode.
- This lets users set roll timing as a tradeable-day offset.
- The roll offset now flows through subscription, history, universe, and mapping-event paths.
- Added optional contract-month-cycle walking.
- This supports specific holding cycles instead of a generic sequence.
- Reused existing LastTradingDay map rows to keep the data source single and true.
By keeping the repair inside the mapping policy, we ensure all engine parts agree on which contract is active.
The result: A bounded repair that adds new capabilities without inventing new systems. Local build validation passed with zero errors. The PR is now ready for upstream review.
Optional learning community: https://t.me/GyaanSetuAi