{"record":{"id":"d16bf0b5d2fd872b","repo":"QuantConnect/Lean","slug":"never-invested-in-es-futures-and-fops","errorCode":null,"errorMessage":"Never invested in ES futures and FOPs","messagePattern":"Never invested in ES futures and FOPs","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"Algorithm.Python/FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm.py","lineNumber":96,"sourceCode":"        if order_event.direction != OrderDirection.SELL or order_event.status != OrderStatus.FILLED:\n            return\n\n        # * Future Liquidation\n        # * Future Option Exercise\n        # * We expect NO Underlying Future Liquidation because we already hold a Long future position so the FOP Put selling leaves us breakeven\n        self.liquidated += 1\n        if order_event.symbol.security_type == SecurityType.FUTURE_OPTION and self.expected_liquidation_time != self.time:\n            raise AssertionError(f\"Expected to liquidate option {order_event.symbol} at {self.expected_liquidation_time}, instead liquidated at {self.time}\")\n\n        if order_event.symbol.security_type == SecurityType.FUTURE and \\\n            (self.expected_liquidation_time - timedelta(minutes=1)) != self.time and \\\n            self.expected_liquidation_time != self.time:\n\n            raise AssertionError(f\"Expected to liquidate future {order_event.symbol} at {self.expected_liquidation_time} (+1 minute), instead liquidated at {self.time}\")\n\n    def on_end_of_algorithm(self):\n        if not self.invested:\n            raise AssertionError(\"Never invested in ES futures and FOPs\")\n\n        if self.delistings_received != 4:\n            raise AssertionError(f\"Expected 4 delisting events received, found: {self.delistings_received}\")\n\n        if self.liquidated != 2:\n            raise AssertionError(f\"Expected 3 liquidation events, found {self.liquidated}\")\n","sourceCodeStart":78,"sourceCodeEnd":103,"githubUrl":"https://github.com/QuantConnect/Lean/blob/d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892/Algorithm.Python/FuturesAndFuturesOptionsExpiryTimeAndLiquidationRegressionAlgorithm.py#L78-L103","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Verify both instruments have data before investing\nfuture_ready = self.es_future in data.bars or self.es_future in data.quote_bars\noption_ready = self.es_future_option in data.bars or self.es_future_option in data.quote_bars\nif not (future_ready and option_ready):\n    self.debug(f\"Awaiting data: future_ready={future_ready} option_ready={option_ready}\")","typeGuard":"def both_instruments_ready(data, future_sym, option_sym) -> bool:\n    fr = future_sym in data.bars or future_sym in data.quote_bars\n    or_ = option_sym in data.bars or option_sym in data.quote_bars\n    return fr and or_","tryCatchPattern":null,"preventionTips":["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."],"tags":["quantconnect","futures","future-options","data-availability","regression-test"],"backgroundTag":null,"analyzedSha":"d2c3659f877bfc2b5d9dc0fc89a9c7566f45e892","analyzedAt":"2026-08-13T13:52:21.013Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}