{"record":{"id":"3431487ade4b3ab8","repo":"microsoft/qlib","slug":"infposition-doesn-t-support-update-weight-all","errorCode":null,"errorMessage":"InfPosition doesn't support update_weight_all","messagePattern":"InfPosition doesn't support update_weight_all","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/backtest/position.py","lineNumber":559,"sourceCode":"        return np.nan\n\n    def get_stock_amount(self, code: str) -> float:\n        return np.inf\n\n    def get_cash(self, include_settle: bool = False) -> float:\n        return np.inf\n\n    def get_stock_amount_dict(self) -> dict:\n        raise NotImplementedError(f\"InfPosition doesn't support get_stock_amount_dict\")\n\n    def get_stock_weight_dict(self, only_stock: bool = False) -> dict:\n        raise NotImplementedError(f\"InfPosition doesn't support get_stock_weight_dict\")\n\n    def add_count_all(self, bar: str) -> None:\n        raise NotImplementedError(f\"InfPosition doesn't support add_count_all\")\n\n    def update_weight_all(self) -> None:\n        raise NotImplementedError(f\"InfPosition doesn't support update_weight_all\")\n\n    def settle_start(self, settle_type: str) -> None:\n        pass\n\n    def settle_commit(self) -> None:\n        pass\n","sourceCodeStart":541,"sourceCodeEnd":566,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/backtest/position.py#L541-L566","documentation":"InfPosition.update_weight_all() raises NotImplementedError. This method recomputes each holding's weight = stock_value / total_value after trades; with infinite amounts and value the weights are undefined, so qlib refuses rather than producing inf/inf NaNs. Only finite Position instances support it.","triggerScenarios":"Executor/report code calls position.update_weight_all() after processing orders while the account holds an InfPosition; the base-class docstring even notes weight state is awkward around order handling, and InfPosition opts out entirely.","commonSituations":"Infinite-cash order-generation runs passed through code paths that refresh weights for reporting; custom strategies calling update_weight_all before get_stock_weight_dict.","solutions":["Use Position whenever weight bookkeeping is required","Guard with isinstance(position, InfPosition) and skip the refresh","In custom executors, only call update_weight_all when the position is a finite Position"],"exampleFix":"# before\nposition.update_weight_all()\n\n# after\nif not isinstance(position, InfPosition):\n    position.update_weight_all()","handlingStrategy":"type-guard","validationCode":"from qlib.backtest.position import InfPosition\nif not isinstance(position, InfPosition):\n    position.update_weight_all()","typeGuard":"def supports_weight_update(pos) -> bool:\n    from qlib.backtest.position import InfPosition\n    return not isinstance(pos, InfPosition)","tryCatchPattern":"try:\n    position.update_weight_all()\nexcept NotImplementedError:\n    pass  # InfPosition: weights undefined","preventionTips":["Only refresh weights on finite Position instances","Skip weight bookkeeping in random-order generation flows"],"tags":["qlib","backtest","position","inf-position","not-implemented"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}