{"record":{"id":"43f4d57f2b80c9b6","repo":"microsoft/qlib","slug":"please-implement-the-get-stock-amount-dict-metho","errorCode":null,"errorMessage":"Please implement the `get_stock_amount_dict` method","messagePattern":"Please implement the `get_stock_amount_dict` method","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/backtest/position.py","lineNumber":157,"sourceCode":"            Default: not include those unavailable cash\n\n        Returns\n        -------\n        float:\n            the available(tradable) cash in position\n        \"\"\"\n        raise NotImplementedError(f\"Please implement the `get_cash` method\")\n\n    def get_stock_amount_dict(self) -> dict:\n        \"\"\"\n        generate stock amount dict {stock_id : amount of stock}\n\n        Returns\n        -------\n        Dict:\n            {stock_id : amount of stock}\n        \"\"\"\n        raise NotImplementedError(f\"Please implement the `get_stock_amount_dict` method\")\n\n    def get_stock_weight_dict(self, only_stock: bool = False) -> dict:\n        \"\"\"\n        generate stock weight dict {stock_id : value weight of stock in the position}\n        it is meaningful in the beginning or the end of each trade step\n        - During execution of each trading step, the weight may be not consistent with the portfolio value\n\n        Parameters\n        ----------\n        only_stock : bool\n            If only_stock=True, the weight of each stock in total stock will be returned\n            If only_stock=False, the weight of each stock in total assets(stock + cash) will be returned\n\n        Returns\n        -------\n        Dict:\n            {stock_id : value weight of stock in the position}\n        \"\"\"","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/backtest/position.py#L139-L175","documentation":"Error \"Please implement the `get_stock_amount_dict` method\" thrown in microsoft/qlib.","triggerScenarios":"This error is raised at qlib/backtest/position.py:157 when the guard condition fails: \"Please implement the `get_stock_amount_dict` method\". It triggers when the code path receives input or a state that violates the precondition checked at this point — e.g. an unimplemented abstract method being called, an unsupported argument type/value, or an invalid configuration. To avoid it, satisfy the documented precondition before this call: implement the required method in your subclass, or pass a supported value of the expected type as described by the message.","commonSituations":"See trigger scenarios.","solutions":["Implement the `get_stock_amount_dict` method in your Position subclass before calling it.","Use the built-in Position class which already implements `get_stock_amount_dict`."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}