microsoft/qlib · error · NotImplementedError
InfPosition doesn't support stock list position
Error message
InfPosition doesn't support stock list position
What it means
InfPosition tracks no per-instrument holdings (amounts are all infinite), so there is no meaningful stock list to enumerate; get_stock_list() raises NotImplementedError by design. Code that iterates holdings (weight computation, count updates, per-stock reporting) is incompatible with InfPosition.
Source
Thrown at qlib/backtest/position.py:537
pass
def update_stock_price(self, stock_id: str, price: float) -> None:
pass
def calculate_stock_value(self) -> float:
"""
Returns
-------
float:
infinity stock value
"""
return np.inf
def calculate_value(self) -> float:
raise NotImplementedError(f"InfPosition doesn't support calculating value")
def get_stock_list(self) -> List[str]:
raise NotImplementedError(f"InfPosition doesn't support stock list position")
def get_stock_price(self, code: str) -> float:
"""the price of the inf position is meaningless"""
return np.nan
def get_stock_amount(self, code: str) -> float:
return np.inf
def get_cash(self, include_settle: bool = False) -> float:
return np.inf
def get_stock_amount_dict(self) -> dict:
raise NotImplementedError(f"InfPosition doesn't support get_stock_amount_dict")
def get_stock_weight_dict(self, only_stock: bool = False) -> dict:
raise NotImplementedError(f"InfPosition doesn't support get_stock_weight_dict")
def add_count_all(self, bar: str) -> None:View on GitHub (pinned to 79633dd950)
Solutions
- Use Position (real cash/holdings) whenever code must enumerate holdings
- Branch on type: if isinstance(position, InfPosition): use exchange/decision data instead of the position
- Restructure the strategy to source the candidate universe from the strategy/instruments argument, not the position
Example fix
# before
for stock in position.get_stock_list():
...
# after
if isinstance(position, InfPosition):
stock_list = list(universe_instruments)
else:
stock_list = position.get_stock_list() Defensive patterns
Strategy: type-guard
Validate before calling
from qlib.backtest.position import InfPosition assert not isinstance(position, InfPosition), "InfPosition has no stock list"
Type guard
def has_stock_list(pos) -> bool:
from qlib.backtest.position import InfPosition
return not isinstance(pos, InfPosition) Try / catch
try:
stocks = position.get_stock_list()
except NotImplementedError:
stocks = [] Prevention
- Source universes from strategy config, not the position
- Keep InfPosition confined to order-generation code paths
When it happens
Trigger: Calling get_stock_list() on an InfPosition: update_weight_all-like loops, reporters enumerating self.position keys, or strategies that iterate position.get_stock_list() to build rebalance decisions while the account was configured with InfPosition.
Common situations: Sharing one position object between an order-generating exchange (InfPosition) and decision/reporting code that assumes Position; porting strategy code from Position to InfPosition.
Related errors
- InfPosition doesn't support calculating value
- InfPosition doesn't support get_stock_amount_dict
- InfPosition doesn't support get_stock_weight_dict
- InfPosition doesn't support add_count_all
- InfPosition doesn't support update_weight_all
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/52cd10facb0b82f4.
Report an issue: GitHub.