{"record":{"id":"1361be0e9e36538d","repo":"microsoft/qlib","slug":"pred-price-trend-method-is-not-implemented","errorCode":null,"errorMessage":"pred_price_trend method is not implemented!","messagePattern":"pred_price_trend method is not implemented!","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/contrib/strategy/rule_strategy.py","lineNumber":155,"sourceCode":"    # 3. Supporting checking the availability of trade decision\n\n    def reset(self, outer_trade_decision: BaseTradeDecision = None, **kwargs):\n        \"\"\"\n        Parameters\n        ----------\n        outer_trade_decision : BaseTradeDecision, optional\n        \"\"\"\n        super(SBBStrategyBase, self).reset(outer_trade_decision=outer_trade_decision, **kwargs)\n        if outer_trade_decision is not None:\n            self.trade_trend = {}\n            self.trade_amount = {}\n            # init the trade amount of order and  predicted trade trend\n            for order in outer_trade_decision.get_decision():\n                self.trade_trend[order.stock_id] = self.TREND_MID\n                self.trade_amount[order.stock_id] = order.amount\n\n    def _pred_price_trend(self, stock_id, pred_start_time=None, pred_end_time=None):\n        raise NotImplementedError(\"pred_price_trend method is not implemented!\")\n\n    def generate_trade_decision(self, execute_result=None):\n        # get the number of trading step finished, trade_step can be [0, 1, 2, ..., trade_len - 1]\n        trade_step = self.trade_calendar.get_trade_step()\n        # get the total count of trading step\n        trade_len = self.trade_calendar.get_trade_len()\n\n        # update the order amount\n        if execute_result is not None:\n            for order, _, _, _ in execute_result:\n                self.trade_amount[order.stock_id] -= order.deal_amount\n\n        trade_start_time, trade_end_time = self.trade_calendar.get_step_time(trade_step)\n        pred_start_time, pred_end_time = self.trade_calendar.get_step_time(trade_step, shift=1)\n        order_list = []\n        # for each order in in self.outer_trade_decision\n        for order in self.outer_trade_decision.get_decision():\n            # get the price trend","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/contrib/strategy/rule_strategy.py#L137-L173","documentation":"SBBStrategyBase._pred_price_trend (qlib/contrib/strategy/rule_strategy.py) is an abstract prediction hook: subclasses like TWAPStrategy/SBBStrategyEMA must implement the trend prediction (up/down/mid) used by generate_trade_decision. The base raises NotImplementedError('pred_price_trend method is not implemented!') so a missing implementation fails loudly the first time a decision is generated.","triggerScenarios":"Running a backtest with a strategy that inherits SBBStrategyBase without overriding _pred_price_trend; the error surfaces when the executor calls generate_trade_decision on the first trading step.","commonSituations":"Writing a custom SBB-style strategy and only overriding reset/generate_trade_decision but not the prediction hook; renaming the method so the base implementation is invoked.","solutions":["Implement _pred_price_trend(self, stock_id, pred_start_time=None, pred_end_time=None) returning one of the TREND_* constants (UP/DOWN/MID)","If you did implement it, verify the exact method name and that it is defined on the class actually instantiated","Reference SBBStrategyEMA (in the same module) for a concrete implementation pattern"],"exampleFix":"class MySBBStrategy(SBBStrategyBase):\n    def _pred_price_trend(self, stock_id, pred_start_time=None, pred_end_time=None):\n        # your model logic here\n        return self.TREND_UP if score > 0 else self.TREND_DOWN","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"def strategy_implements_trend_pred(strategy) -> bool:\n    return type(strategy)._pred_price_trend is not SBBStrategyBase._pred_price_trend","tryCatchPattern":"try:\n    strategy.generate_trade_decision()\nexcept NotImplementedError as e:\n    if 'pred_price_trend' in str(e):\n        raise TypeError(f'{type(strategy).__name__} must implement _pred_price_trend')\n    raise","preventionTips":["When subclassing SBBStrategyBase, implement _pred_price_trend returning TREND_UP/TREND_DOWN/TREND_MID","Copy the method list from SBBStrategyEMA as your subclassing checklist"],"tags":["qlib","backtest","strategy","abstract-method"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}