microsoft/qlib · error · ValueError
method {method} is not supported!
Error message
method {method} is not supported! What it means
Raised in qlib/backtest/report.py by the fulfillment-rate (FFR) metric calculator. The method argument controls how per-order FFR values are combined and only supports 'mean' (simple average), 'amount_weighted' (weighted by absolute deal amount), and 'value_weighted' (weighted by absolute trade value). Any other method string raises ValueError.
Source
Thrown at qlib/backtest/report.py:568
pa_config = indicator_config.get("pa_config", {})
self._agg_base_price(inner_order_indicators, decision_list, trade_exchange, pa_config=pa_config) # TODO
self._agg_order_price_advantage()
def _cal_trade_fulfill_rate(self, method: str = "mean") -> Optional[BaseSingleMetric]:
if method == "mean":
return self.order_indicator.transfer(
lambda ffr: ffr.mean(),
)
elif method == "amount_weighted":
return self.order_indicator.transfer(
lambda ffr, deal_amount: (ffr * deal_amount.abs()).sum() / (deal_amount.abs().sum()),
)
elif method == "value_weighted":
return self.order_indicator.transfer(
lambda ffr, trade_value: (ffr * trade_value.abs()).sum() / (trade_value.abs().sum()),
)
else:
raise ValueError(f"method {method} is not supported!")
def _cal_trade_price_advantage(self, method: str = "mean") -> Optional[BaseSingleMetric]:
if method == "mean":
return self.order_indicator.transfer(lambda pa: pa.mean())
elif method == "amount_weighted":
return self.order_indicator.transfer(
lambda pa, deal_amount: (pa * deal_amount.abs()).sum() / (deal_amount.abs().sum()),
)
elif method == "value_weighted":
return self.order_indicator.transfer(
lambda pa, trade_value: (pa * trade_value.abs()).sum() / (trade_value.abs().sum()),
)
else:
raise ValueError(f"method {method} is not supported!")
def _cal_trade_positive_rate(self) -> Optional[BaseSingleMetric]:
def func(pa):
return (pa > 0).sum() / pa.count()View on GitHub (pinned to 79633dd950)
Solutions
- Use one of the three supported methods: 'mean', 'amount_weighted', or 'value_weighted'.
- If a custom aggregation is required, subclass the indicator calculator and override _cal_ffr instead of passing a new method string.
- Verify the exact spelling in the workflow YAML — matching is exact and case-sensitive.
Example fix
# before
indicator_config = {'ffr': {'method': 'median'}}
# after
indicator_config = {'ffr': {'method': 'mean'}} # or 'amount_weighted' / 'value_weighted' Defensive patterns
Strategy: validation
Validate before calling
SUPPORTED = {'mean', 'amount_weighted', 'value_weighted'}
if method not in SUPPORTED:
raise ValueError(f'method must be one of {sorted(SUPPORTED)}')
# only then build the indicator config Type guard
def is_ffr_method(m: str) -> bool:
return m in {'mean', 'amount_weighted', 'value_weighted'} Try / catch
try:
ffr = calc._cal_ffr(method)
except ValueError:
ffr = calc._cal_ffr('mean') # explicit safe default, log a warning Prevention
- Validate metric method strings against the supported set before building report configs.
- Beware exact case-sensitive matching when editing workflow YAMLs.
When it happens
Trigger: Passing method to the FFR indicator via the report config, e.g. {'ffr': {'method': 'median'}}, or calling the internal _cal_ffr(method=...) with an unsupported string.
Common situations: Users extend portfolio analysis workflows and try to add a new weighting (e.g. 'share_weighted' or 'median') through config alone without subclassing the indicator calculator; or they typo 'amount_weighted' as 'amountweighted'.
Related errors
- This type of input {rtype} is not supported
- file "{}" does not exist
- Only py/yml/yaml/json type are supported now!
- trade_calendar is necessary for getting TradeRangeByTime.
- The decision didn't provide an index range
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/4a3f9f0f740ac340.
Report an issue: GitHub.