QuantConnect/Lean · error · AssertionError
Never invested in ES futures and FOPs
Error message
Never invested in ES futures and FOPs
What it means
End-of-algorithm guard: self.invested must be True. The flag is only set in on_data once both the ES future and ES FOP have a bar/quote_bar and the market orders are placed. Failing means the algorithm never saw simultaneous data for both instruments and never entered a position.
Source
Thrown at Algorithm.Python/FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm.py:96
if order_event.direction != OrderDirection.SELL or order_event.status != OrderStatus.FILLED:
return
# * Future Liquidation
# * Future Option Exercise
# * We expect NO Underlying Future Liquidation because we already hold a Long future position so the FOP Put selling leaves us breakeven
self.liquidated += 1
if order_event.symbol.security_type == SecurityType.FUTURE_OPTION and self.expected_liquidation_time != self.time:
raise AssertionError(f"Expected to liquidate option {order_event.symbol} at {self.expected_liquidation_time}, instead liquidated at {self.time}")
if order_event.symbol.security_type == SecurityType.FUTURE and \
(self.expected_liquidation_time - timedelta(minutes=1)) != self.time and \
self.expected_liquidation_time != self.time:
raise AssertionError(f"Expected to liquidate future {order_event.symbol} at {self.expected_liquidation_time} (+1 minute), instead liquidated at {self.time}")
def on_end_of_algorithm(self):
if not self.invested:
raise AssertionError("Never invested in ES futures and FOPs")
if self.delistings_received != 4:
raise AssertionError(f"Expected 4 delisting events received, found: {self.delistings_received}")
if self.liquidated != 2:
raise AssertionError(f"Expected 3 liquidation events, found {self.liquidated}")
View on GitHub (pinned to d2c3659f87)
Solutions
- Confirm data files exist for both es_future and es_future_option in the backtest window.
- Log which instrument is missing from each slice (data.bars / data.quote_bars).
- Widen the date range so a bar co-exists for both.
- Check fill_forward / resolution settings are identical for both add_*_contract calls.
Defensive patterns
Strategy: validation
Validate before calling
# Verify both instruments have data before investing
future_ready = self.es_future in data.bars or self.es_future in data.quote_bars
option_ready = self.es_future_option in data.bars or self.es_future_option in data.quote_bars
if not (future_ready and option_ready):
self.debug(f"Awaiting data: future_ready={future_ready} option_ready={option_ready}") Type guard
def both_instruments_ready(data, future_sym, option_sym) -> bool:
fr = future_sym in data.bars or future_sym in data.quote_bars
or_ = option_sym in data.bars or option_sym in data.quote_bars
return fr and or_ Prevention
- Confirm data files exist for both contracts in the window.
- Use identical resolution/fill_forward for both add_*_contract calls.
- Log which instrument is missing per slice.
- Widen the date range so a co-bar exists.
When it happens
Trigger: One of the two contracts never produced a bar in the backtest window; data missing for either ES or the ES option; the invested block's data-presence conditions never both true on the same slice.
Common situations: Data drop missing the FOP or future file; date range not covering a day when both trade; resolution/fill-forward differences so quote_bars/bars never line up; symbol mapping mismatch.
Related errors
- [{UtcTime}] We hold a delisted securities: {string.Join(",",
- Expected at least two future contracts with option chains, b
- Expiry warning with time {delisting.time} but is expected to
- Delisting warning received at an unexpected date: {self.time
- Delisting occurred at unexpected time: {delisting.time} - ex
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/d16bf0b5d2fd872b.
Report an issue: GitHub.