HKUDS/Vibe-Trading · error · ValuationError
{model}: {name} must be a finite number, got {val!r}
Error message
{model}: {name} must be a finite number, got {val!r} What it means
calendarise_metric validates that every fiscal-period value it uses to calendarise a metric (last_full_fiscal_year, current_year_to_date, prior_year_to_date, next_full_fiscal_year) is a finite number before combining them under an LTM/NTM policy. NaN or infinity in any period would silently poison the blended figure, so the library refuses it.
Source
Thrown at agent/src/quantlib/valuation/comps.py:273
ValuationError: If `policy` is not one of `CALENDARISATION_POLICIES`,
or if any supplied period value is not a finite number.
MissingInputError: If `periods` lacks a field this policy needs.
"""
if policy not in CALENDARISATION_POLICIES:
raise ValuationError(
f"comps.calendarise_metric: unknown policy {policy!r}, must be "
f"one of {CALENDARISATION_POLICIES}"
)
model = f"comps.calendarise_metric[{company_name}.{metric_name}:{policy}]"
for name, val in (
("last_full_fiscal_year", periods.last_full_fiscal_year),
("current_year_to_date", periods.current_year_to_date),
("prior_year_to_date", periods.prior_year_to_date),
("next_full_fiscal_year", periods.next_full_fiscal_year),
):
if val is not None and not math.isfinite(val):
raise ValuationError(
f"{model}: {name} must be a finite number, got {val!r}"
)
if policy == "ltm":
require_inputs(
{
"last_full_fiscal_year": periods.last_full_fiscal_year,
"current_year_to_date": periods.current_year_to_date,
"prior_year_to_date": periods.prior_year_to_date,
},
("last_full_fiscal_year", "current_year_to_date", "prior_year_to_date"),
model,
)
value = (
periods.last_full_fiscal_year
+ periods.current_year_to_date
- periods.prior_year_to_date
)View on GitHub (pinned to 80ffdda44c)
Solutions
- Find which period value is non-finite: log the peer name and the four period values before calling run_comps.
- Drop or repair peers with NaN/inf periods (fillna with sourced estimates or exclude the peer).
- Guard your ingestion layer: math.isfinite check per numeric field before constructing fiscal periods.
- If NaN means 'not reported', pass None instead so calendarise_metric treats it as missing rather than invalid.
Example fix
# before
periods = {"last_full_fiscal_year": df.iloc[0]["fy_revenue"], ...} # may be NaN
# after
import math
periods = {k: (v if v is None or math.isfinite(v) else None) for k, v in raw_periods.items()} Defensive patterns
Strategy: validation
Validate before calling
import math
for name, v in periods.items():
if v is not None and not math.isfinite(v):
raise ValueError(f'non-finite period {name}: {v!r}') Type guard
def has_finite_periods(p):
return all(v is None or (isinstance(v, (int, float)) and math.isfinite(v)) for v in p.values()) Try / catch
from quantlib.valuation.contracts import ValuationError
try:
run_comps(target, peers, policy)
except ValuationError as e:
if 'must be a finite number' in str(e):
log.warning('dropping peer with non-finite periods: %s', e)
raise Prevention
- Sanitize fiscal-period dicts with math.isfinite before constructing peers
- Map missing values to None, not NaN
- Add DataFrame dropna/finite filters on numeric columns at ingestion
When it happens
Trigger: Calling run_comps / peer_multiple_set where a peer or target's fiscal periods dict contains math.nan, float('inf'), or a numpy NaN for any period key; typically the data came from a pandas frame or JSON with missing values coerced to NaN.
Common situations: Loading peer financials from CSV/DataFrame where missing cells become NaN; joining data sources that emit nulls; upstream arithmetic producing inf (division by zero) that is fed straight into fiscal periods.
Related errors
- comps: total_debt must be a finite number, got {total_debt!r
- comps.enterprise_value: market_cap must be a finite number,
- {model}: {name} must be a finite number, got {numeric!r}
- label_end_times holds a non-finite value
- valuations[{index}] must be a (date, value) pair, got {type(
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/10f7ebb7e6c13229.
Report an issue: GitHub.