microsoft/qlib · error · NotImplementedError

Please implement the `check_stock` method

Error message

Please implement the `check_stock` method

What it means

Error "Please implement the `check_stock` method" thrown in microsoft/qlib.

Source

Thrown at qlib/backtest/position.py:55

            should we skip the updating operator
        """
        return False

    def check_stock(self, stock_id: str) -> bool:
        """
        check if is the stock in the position

        Parameters
        ----------
        stock_id : str
            the id of the stock

        Returns
        -------
        bool:
            if is the stock in the position
        """
        raise NotImplementedError(f"Please implement the `check_stock` method")

    def update_order(self, order: Order, trade_val: float, cost: float, trade_price: float) -> None:
        """
        Parameters
        ----------
        order : Order
            the order to update the position
        trade_val : float
            the trade value(money) of dealing results
        cost : float
            the trade cost of the dealing results
        trade_price : float
            the trade price of the dealing results
        """
        raise NotImplementedError(f"Please implement the `update_order` method")

    def update_stock_price(self, stock_id: str, price: float) -> None:
        """

View on GitHub (pinned to 79633dd950)

Solutions

  1. Implement the `check_stock` method in your Position subclass before calling it.
  2. Use the built-in Position class which already implements `check_stock`.

When it happens

Trigger: This error is raised at qlib/backtest/position.py:55 when the guard condition fails: "Please implement the `check_stock` 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/2261254d57a43102. Report an issue: GitHub.