{"record":{"id":"8276d21473058628","repo":"microsoft/qlib","slug":"please-implement-the-settle-commit-method","errorCode":null,"errorMessage":"Please implement the `settle_commit` method","messagePattern":"Please implement the `settle_commit` method","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/backtest/position.py","lineNumber":222,"sourceCode":"        It will act like start and commit a transaction\n\n        Parameters\n        ----------\n        settle_type : str\n            Should we make delay the settlement in each execution (each execution will make the executor a step forward)\n            - \"cash\": make the cash settlement delayed.\n                - The cash you get can't be used in current step (e.g. you can't sell a stock to get cash to buy another\n                        stock)\n            - None: not settlement mechanism\n            - TODO: other assets will be supported in the future.\n        \"\"\"\n        raise NotImplementedError(f\"Please implement the `settle_conf` method\")\n\n    def settle_commit(self) -> None:\n        \"\"\"\n        settlement commit\n        \"\"\"\n        raise NotImplementedError(f\"Please implement the `settle_commit` method\")\n\n    def __str__(self) -> str:\n        return self.__dict__.__str__()\n\n    def __repr__(self) -> str:\n        return self.__dict__.__repr__()\n\n\nclass Position(BasePosition):\n    \"\"\"Position\n\n    current state of position\n    a typical example is :{\n      <instrument_id>: {\n        'count': <how many days the security has been hold>,\n        'amount': <the amount of the security>,\n        'price': <the close price of security in the last trading day>,\n        'weight': <the security weight of total position value>,","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/backtest/position.py#L204-L240","documentation":"BasePosition.settle_commit() is the second abstract settlement stub: it should flush pending settlement state (e.g. move cash_delay into cash) at transaction commit. If a subclass does not override it, the base implementation raises NotImplementedError. Together with settle_start it forms the transactional settlement protocol executors rely on.","triggerScenarios":"An executor finishes a nested step and calls position.settle_commit() on a position object whose class did not implement it; typically after settle_start succeeded, or when BasePosition/InfPosition-unsupported flows are used with settlement enabled.","commonSituations":"Custom position class implementing settle_start but not settle_commit (partial port of the API); upgrading qlib where executors newly call settle_commit on positions.","solutions":["Use the concrete Position class which implements settle_commit","Implement settle_commit in your subclass: fold cash_delay back into cash and reset _settle_type to ST_NO","If settlement is not needed, ensure executors are configured with settle_type None so commit is skipped"],"exampleFix":"// before\nclass MyPosition(BasePosition):\n    def settle_start(self, settle_type): ...\n    # missing settle_commit\n\n# after\nclass MyPosition(BasePosition):\n    def settle_commit(self) -> None:\n        if self._settle_type == self.ST_CASH:\n            self.position[\"cash\"] += self.position.pop(\"cash_delay\", 0.0)\n        self._settle_type = self.ST_NO","handlingStrategy":"type-guard","validationCode":"assert type(position).settle_commit is not BasePosition.settle_commit, \"settle_commit not implemented\"","typeGuard":"def supports_settlement(pos) -> bool:\n    return type(pos).settle_commit is not BasePosition.settle_commit","tryCatchPattern":"try:\n    position.settle_commit()\nexcept NotImplementedError as e:\n    raise RuntimeError(f\"position {type(position).__name__} cannot commit settlement\") from e","preventionTips":["Pair settle_start with settle_commit in custom positions","Unit-test the settle_start/settle_commit round trip on new position classes"],"tags":["qlib","backtest","abstract-method","settlement","position"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}