{"record":{"id":"52cd10facb0b82f4","repo":"microsoft/qlib","slug":"infposition-doesn-t-support-stock-list-position","errorCode":null,"errorMessage":"InfPosition doesn't support stock list position","messagePattern":"InfPosition doesn't support stock list position","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/backtest/position.py","lineNumber":537,"sourceCode":"        pass\n\n    def update_stock_price(self, stock_id: str, price: float) -> None:\n        pass\n\n    def calculate_stock_value(self) -> float:\n        \"\"\"\n        Returns\n        -------\n        float:\n            infinity stock value\n        \"\"\"\n        return np.inf\n\n    def calculate_value(self) -> float:\n        raise NotImplementedError(f\"InfPosition doesn't support calculating value\")\n\n    def get_stock_list(self) -> List[str]:\n        raise NotImplementedError(f\"InfPosition doesn't support stock list position\")\n\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:","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/backtest/position.py#L519-L555","documentation":"InfPosition tracks no per-instrument holdings (amounts are all infinite), so there is no meaningful stock list to enumerate; get_stock_list() raises NotImplementedError by design. Code that iterates holdings (weight computation, count updates, per-stock reporting) is incompatible with InfPosition.","triggerScenarios":"Calling get_stock_list() on an InfPosition: update_weight_all-like loops, reporters enumerating self.position keys, or strategies that iterate position.get_stock_list() to build rebalance decisions while the account was configured with InfPosition.","commonSituations":"Sharing one position object between an order-generating exchange (InfPosition) and decision/reporting code that assumes Position; porting strategy code from Position to InfPosition.","solutions":["Use Position (real cash/holdings) whenever code must enumerate holdings","Branch on type: if isinstance(position, InfPosition): use exchange/decision data instead of the position","Restructure the strategy to source the candidate universe from the strategy/instruments argument, not the position"],"exampleFix":"# before\nfor stock in position.get_stock_list():\n    ...\n\n# after\nif isinstance(position, InfPosition):\n    stock_list = list(universe_instruments)\nelse:\n    stock_list = position.get_stock_list()","handlingStrategy":"type-guard","validationCode":"from qlib.backtest.position import InfPosition\nassert not isinstance(position, InfPosition), \"InfPosition has no stock list\"","typeGuard":"def has_stock_list(pos) -> bool:\n    from qlib.backtest.position import InfPosition\n    return not isinstance(pos, InfPosition)","tryCatchPattern":"try:\n    stocks = position.get_stock_list()\nexcept NotImplementedError:\n    stocks = []","preventionTips":["Source universes from strategy config, not the position","Keep InfPosition confined to order-generation code paths"],"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"}