QuantConnect/Lean · error · NotImplementedError
AssertStrategyPositionGroup method is not implemented
Error message
AssertStrategyPositionGroup method is not implemented
What it means
assert_strategy_position_group is the abstract verification hook on OptionStrategyFactoryMethodsBaseAlgorithm. After the strategy is invested, on_data calls it so the subclass can assert the position group contains exactly the expected legs (symbols, quantities, right/strike/expiry). The base raises NotImplementedError because the expected legs depend on the concrete strategy; a subclass must define them.
Source
Thrown at Algorithm.Python/OptionStrategyFactoryMethodsBaseAlgorithm.py:72
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 assert_strategy_position_group in the subclass to check group positions match the strategy legs.
- Run a concrete subclass instead of the base.
- Decorate with @abstractmethod to surface the omission earlier.
Example fix
# before: base raises NotImplementedError
# after
def assert_strategy_position_group(self, position_group, option_symbol):
positions = list(position_group.positions)
assert len(positions) == 2, 'Expected 2 legs in the group' Defensive patterns
Strategy: validation
Validate before calling
if self.assert_strategy_position_group.__func__ is OptionStrategyFactoryMethodsBaseAlgorithm.assert_strategy_position_group:
raise NotImplementedError('Subclass must override assert_strategy_position_group()') Prevention
- Decorate abstract template methods with @abstractmethod.
- Implement every hook when subclassing the base.
- Run concrete subclasses only.
When it happens
Trigger: on_data reaches the post-investment verification branch and calls self.assert_strategy_position_group(position_group, self._option_symbol) on an instance whose class did not override the method.
Common situations: Running the base class; a new subclass missing the override; refactoring the base signature without updating overrides.
Related errors
- ExpectedOrdersCount method is not implemented
- TradeStrategy method is not implemented
- LiquidateStrategy method is not implemented
- Expected position group buying power model type: OptionStrat
- Expected {self.expected_orders_count()} orders to have been
AI-assisted analysis of QuantConnect/Lean@d2c3659f87 (2026-08-13).
Data as JSON: /api/errors/4ef1992f160e3c1d.
Report an issue: GitHub.