{"record":{"id":"2372664571ebf278","repo":"microsoft/qlib","slug":"infposition-doesn-t-support-add-count-all","errorCode":null,"errorMessage":"InfPosition doesn't support add_count_all","messagePattern":"InfPosition doesn't support add_count_all","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/backtest/position.py","lineNumber":556,"sourceCode":"\n    def get_stock_price(self, code: str) -> float:\n        \"\"\"the price of the inf position is meaningless\"\"\"\n        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":538,"sourceCodeEnd":566,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/backtest/position.py#L538-L566","documentation":"InfPosition.add_count_all(bar) raises NotImplementedError. add_count_all increments per-stock holding-duration counters (position[stock][f'count_{bar}']) each executor step; InfPosition has no per-stock state to count, so the API is intentionally unimplemented.","triggerScenarios":"An executor's per-bar update loop calls position.add_count_all(bar) while the account uses InfPosition; e.g. nested executor setups (time-level executors incrementing daily counts) combined with an infinite-cash position.","commonSituations":"Running randomized/order-generation backtests (which use InfPosition) through executor stacks that assume the full Position API; custom executors ported from Position flows.","solutions":["Run those executor configurations with Position instead of InfPosition","Override add_count_all as a no-op in an InfPosition subclass used purely for order generation","Disable bar-count tracking (count_{bar} keys) in the executor config if supported"],"exampleFix":"# before\nclass MyInf(InfPosition):\n    ...\n# executor calls add_count_all -> raises\n\n# after\nclass MyInf(InfPosition):\n    def add_count_all(self, bar: str) -> None:\n        pass  # counting is meaningless with infinite amounts","handlingStrategy":"fallback","validationCode":"from qlib.backtest.position import InfPosition\nif not isinstance(position, InfPosition):\n    position.add_count_all(bar)","typeGuard":"def supports_counting(pos) -> bool:\n    from qlib.backtest.position import InfPosition\n    return not isinstance(pos, InfPosition)","tryCatchPattern":"try:\n    position.add_count_all(bar)\nexcept NotImplementedError:\n    pass  # counting meaningless for InfPosition","preventionTips":["Subclass InfPosition with no-op add_count_all for order-generation runs","Gate executor update loops on position type"],"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"}