QuantConnect/Lean · error · NotImplementedError
TradeStrategy method is not implemented
Error message
TradeStrategy method is not implemented
What it means
trade_strategy(chain, option_symbol) is the abstract entry point on OptionStrategyFactoryMethodsBaseAlgorithm that on_data calls to actually build and submit the option strategy orders. The base raises NotImplementedError because it has no concrete strategy to trade; a subclass must supply the OptionStrategies combo and the Buy call. Hitting it means the algorithm tried to trade through the unimplemented base method.
Source
Thrown at Algorithm.Python/OptionStrategyFactoryMethodsBaseAlgorithm.py:69
self.liquidate_strategy()
# We can quit now, no more testing required
self.quit()
def on_end_of_algorithm(self):
if self.portfolio.invested:
raise AssertionError("Expected no holdings at end of algorithm")
orders_count = len(list(self.transactions.get_orders(lambda order: order.status == OrderStatus.FILLED)))
if orders_count != self.expected_orders_count():
raise AssertionError(f"Expected {self.expected_orders_count()} orders to have been submitted and filled, "
f"half for buying the strategy and the other half for the liquidation. Actual {orders_count}")
def expected_orders_count(self) -> int:
raise NotImplementedError("ExpectedOrdersCount method is not implemented")
def trade_strategy(self, chain: OptionChain, option_symbol: Symbol) -> None:
raise NotImplementedError("TradeStrategy method is not implemented")
def assert_strategy_position_group(self, position_group: IPositionGroup, option_symbol: Symbol) -> None:
raise NotImplementedError("AssertStrategyPositionGroup method is not implemented")
def liquidate_strategy(self) -> None:
raise NotImplementedError("LiquidateStrategy method is not implemented")
View on GitHub (pinned to d2c3659f87)
Solutions
- Implement trade_strategy in your subclass: build the strategy via OptionStrategies and call self.buy(strategy, quantity).
- Run a concrete subclass, not the base.
- Use @abstractmethod so missing overrides fail at construction.
Example fix
# before: base raises NotImplementedError
# after
def trade_strategy(self, chain, option_symbol):
strategy = OptionStrategies.CoveredCall(option_symbol)
self.buy(strategy, 1) Defensive patterns
Strategy: validation
Validate before calling
# Detect an unoverridden template method before trading
if self.trade_strategy.__func__ is OptionStrategyFactoryMethodsBaseAlgorithm.trade_strategy:
raise NotImplementedError('Subclass must override trade_strategy()') Prevention
- Use @abstractmethod to surface missing overrides at instantiation.
- Always implement trade_strategy in subclasses.
- Run a concrete subclass, not the base.
When it happens
Trigger: on_data receives a non-None option chain while self.portfolio.invested is False and calls self.trade_strategy(...) on an instance whose class did not override trade_strategy. Happens when the base class is run or a subclass omits the override.
Common situations: Running the base class directly; creating a new subclass and forgetting to implement trade_strategy; renaming the base method without updating subclasses.
Related errors
- ExpectedOrdersCount method is not implemented
- AssertStrategyPositionGroup method is not implemented
- LiquidateStrategy method is not implemented
- Expected {self.expected_orders_count()} orders to have been
- Unexpected order event symbol!
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/bbb303d84563006c.
Report an issue: GitHub.