microsoft/qlib · error · NotImplementedError
Please implement the `get_stock_price` method
Error message
Please implement the `get_stock_price` method
What it means
Error "Please implement the `get_stock_price` method" thrown in microsoft/qlib.
Source
Thrown at qlib/backtest/position.py:115
def calculate_value(self) -> float:
raise NotImplementedError(f"Please implement the `calculate_value` method")
def get_stock_list(self) -> List[str]:
"""
Get the list of stocks in the position.
"""
raise NotImplementedError(f"Please implement the `get_stock_list` method")
def get_stock_price(self, code: str) -> float:
"""
get the latest price of the stock
Parameters
----------
code :
the code of the stock
"""
raise NotImplementedError(f"Please implement the `get_stock_price` method")
def get_stock_amount(self, code: str) -> float:
"""
get the amount of the stock
Parameters
----------
code :
the code of the stock
Returns
-------
float:
the amount of the stock
"""
raise NotImplementedError(f"Please implement the `get_stock_amount` method")
def get_cash(self, include_settle: bool = False) -> float:View on GitHub (pinned to 79633dd950)
Solutions
- Implement the `get_stock_price` method in your Position subclass before calling it.
- Use the built-in Position class which already implements `get_stock_price`.
When it happens
Trigger: This error is raised at qlib/backtest/position.py:115 when the guard condition fails: "Please implement the `get_stock_price` 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.
Common situations: See trigger scenarios.
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/e06c9b170f419543.
Report an issue: GitHub.