microsoft/qlib · error · NotImplementedError

Please implement the `add_count_all` method

Error message

Please implement the `add_count_all` method

What it means

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

Source

Thrown at qlib/backtest/position.py:187

            If only_stock=False, the weight of each stock in total assets(stock + cash) will be returned

        Returns
        -------
        Dict:
            {stock_id : value weight of stock in the position}
        """
        raise NotImplementedError(f"Please implement the `get_stock_weight_dict` method")

    def add_count_all(self, bar: str) -> None:
        """
        Will be called at the end of each bar on each level

        Parameters
        ----------
        bar :
            The level to be updated
        """
        raise NotImplementedError(f"Please implement the `add_count_all` method")

    def update_weight_all(self) -> None:
        """
        Updating the position weight;

        # TODO: this function is a little weird. The weight data in the position is in a wrong state after dealing order
        # and before updating weight.
        """
        raise NotImplementedError(f"Please implement the `add_count_all` method")

    ST_CASH = "cash"
    ST_NO = "None"  # String is more typehint friendly than None

    def settle_start(self, settle_type: str) -> None:
        """
        settlement start
        It will act like start and commit a transaction

View on GitHub (pinned to 79633dd950)

Solutions

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

When it happens

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