QuantConnect/Lean · error · AssertionError
Expected to liquidate option {order_event.symbol} at {self.e
Error message
Expected to liquidate option {order_event.symbol} at {self.expected_liquidation_time}, instead liquidated at {self.time} What it means
Liquidation-timing assertion for FUTURE_OPTION sell/fill events. When an order event for a SecurityType.FUTURE_OPTION completes, the test requires self.time == expected_liquidation_time (2020-06-20). A mismatch indicates the option was liquidated/exercised on the wrong bar.
Source
Thrown at Algorithm.Python/FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm.py:86
if not self.invested and \
(self.es_future in data.bars or self.es_future in data.quote_bars) and \
(self.es_future_option in data.bars or self.es_future_option in data.quote_bars):
self.invested = True
self.market_order(self.es_future, 1)
self.market_order(self.es_future_option, 1)
def on_order_event(self, order_event: OrderEvent):
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
- Print self.time and self.expected_liquidation_time to locate the offset.
- Verify the FOP data file's expiry/exercise timestamp.
- Update expected_liquidation_time if exercise timing intentionally changed.
- Confirm self.time tz matches the naive datetime assumption.
Defensive patterns
Strategy: validation
Validate before calling
# Validate FOP liquidation time before raising
if order_event.symbol.security_type == SecurityType.FUTURE_OPTION:
if self.expected_liquidation_time != self.time:
self.debug(f"FOP liquidation at {self.time} != expected {self.expected_liquidation_time}") Type guard
def fop_liquidated_on_time(order_event, algo_time: datetime, expected: datetime) -> bool:
return (order_event.symbol.security_type == SecurityType.FUTURE_OPTION
and algo_time == expected) Prevention
- Keep expected_liquidation_time synced with FOP exercise timing.
- Confirm self.time tz matches the naive expected datetime.
- Log order_event details when debugging.
- Re-baseline after engine exercise-scheduling changes.
When it happens
Trigger: FOP exercise or auto-liquidation firing a bar earlier or later than the expiry day; timezone skew between order_event processing time and the expected datetime; data changes shifting exercise timing.
Common situations: Engine changes to FOP exercise scheduling; data refreshes with different expiry timestamps; algorithm time timezone differing from expected_liquidation_time's naive datetime.
Related errors
- Expiry warning with time {delisting.time} but is expected to
- Delisting occurred at unexpected time: {delisting.time} - ex
- Expected to liquidate future {order_event.symbol} at {self.e
- Expected 3 liquidation events, found {self.liquidated}
- [{UtcTime}] We hold a delisted securities: {string.Join(",",
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/09bc9fb9693ca6c7.
Report an issue: GitHub.