microsoft/qlib · error · NotImplementedError

Please implement the `settle_conf` method

Error message

Please implement the `settle_conf` method

What it means

BasePosition.settle_start(settle_type) is an abstract stub that always raises NotImplementedError('Please implement the `settle_conf` method'). It marks the transaction-start hook of the settlement mechanism (delayed cash vs immediate). The message text 'settle_conf' is a typo — the failing method is actually settle_start.

Source

Thrown at qlib/backtest/position.py:216

    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

        Parameters
        ----------
        settle_type : str
            Should we make delay the settlement in each execution (each execution will make the executor a step forward)
            - "cash": make the cash settlement delayed.
                - The cash you get can't be used in current step (e.g. you can't sell a stock to get cash to buy another
                        stock)
            - None: not settlement mechanism
            - TODO: other assets will be supported in the future.
        """
        raise NotImplementedError(f"Please implement the `settle_conf` method")

    def settle_commit(self) -> None:
        """
        settlement commit
        """
        raise NotImplementedError(f"Please implement the `settle_commit` method")

    def __str__(self) -> str:
        return self.__dict__.__str__()

    def __repr__(self) -> str:
        return self.__dict__.__repr__()


class Position(BasePosition):
    """Position

    current state of position

View on GitHub (pinned to 79633dd950)

Solutions

  1. Use the built-in Position class, which implements settle_start/settle_commit
  2. Add settle_start to your subclass: store the settle type and initialize cash_delay (mirror Position.settle_start)
  3. Avoid settle_type='cash' executor configs if your custom position cannot support delayed settlement

Example fix

// before
class MyPosition(BasePosition):
    ...

# after
class MyPosition(BasePosition):
    def settle_start(self, settle_type: str) -> None:
        assert self._settle_type == self.ST_NO
        self._settle_type = settle_type
        if settle_type == self.ST_CASH:
            self.position["cash_delay"] = 0.0
Defensive patterns

Strategy: type-guard

Validate before calling

required = ("settle_start", "settle_commit")
missing = [m for m in required if getattr(type(position), m) is getattr(BasePosition, m)]
assert not missing, f"position does not implement: {missing}"

Type guard

def supports_settlement(pos) -> bool:
    return type(pos).settle_start is not BasePosition.settle_start

Try / catch

try:
    position.settle_start(settle_type)
except NotImplementedError:
    # fallback: treat settlement as immediate (ST_NO behaviour)
    position.settle_start(Position.ST_NO)

Prevention

When it happens

Trigger: An executor calls position.settle_start(self.ST_CASH) (NestedExecutor with settle_type='cash' in executor config, or SimulatorExecutor wrap-up logic) while the position object's class never overrode settle_start. Instantiating BasePosition directly also triggers it.

Common situations: Custom Position subclass copied from an older qlib version that predates the settlement API; executor configured with nested executors and settle: cash while the position class only implements the old interface.

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/b7897a3a8d3f626b. Report an issue: GitHub.