HKUDS/Vibe-Trading · error · ValuationError

comps: total_debt must be a finite number, got {total_debt!r

Error message

comps: total_debt must be a finite number, got {total_debt!r}

What it means

The equity-to-enterprise-value bridge requires total_debt to be a finite number. _bridge_delta computes total_debt - cash plus optional components, so a NaN/inf debt would propagate into every EV and multiple downstream, hence the hard failure.

Source

Thrown at agent/src/quantlib/valuation/comps.py:388

def _bridge_delta(
    total_debt: float,
    cash_and_equivalents: float,
    minority_interest: float | None,
    preferred_stock: float | None,
    investments_in_associates: float | None,
) -> tuple[float, tuple[str, ...]]:
    """Compute the EV-minus-equity-value delta and which optional items were omitted.

    The delta is added to equity value to reach EV, and subtracted from EV to
    reach equity value -- the two public bridge functions differ only in
    which side is the known input.

    Returns:
        `(delta, omitted_components)`.
    """
    omitted: list[str] = []
    if not math.isfinite(total_debt):
        raise ValuationError(
            f"comps: total_debt must be a finite number, got {total_debt!r}"
        )
    if not math.isfinite(cash_and_equivalents):
        raise ValuationError(
            f"comps: cash_and_equivalents must be a finite number, got {cash_and_equivalents!r}"
        )
    total = total_debt - cash_and_equivalents
    for name, value in (
        ("minority_interest", minority_interest),
        ("preferred_stock", preferred_stock),
        ("investments_in_associates", investments_in_associates),
    ):
        if value is None:
            omitted.append(name)
            continue
        if not math.isfinite(value):
            raise ValuationError(
                f"comps: {name} must be a finite number, got {value!r}"

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Check the debt input: print total_debt before the call and locate the NaN/inf source.
  2. Coerce missing debt lines to 0.0 only when you can justify zero debt, else supply a sourced estimate.
  3. Add a finite guard in your data layer: if not math.isfinite(total_debt): raise/repair before calling.

Example fix

# before
ev = enterprise_value(market_cap, total_debt=df['debt'].sum())  # NaN if column empty

# after
total_debt = float(df['debt'].sum() or 0.0)
assert math.isfinite(total_debt)
ev = enterprise_value(market_cap, total_debt=total_debt)
Defensive patterns

Strategy: validation

Validate before calling

import math
total_debt = float(total_debt)
assert math.isfinite(total_debt), total_debt

Type guard

def finite_float(v):
    return isinstance(v, (int, float)) and math.isfinite(v)

Try / catch

try:
    ev = enterprise_value(...)
except ValuationError as e:
    if 'total_debt' in str(e):
        # repair or exclude the peer
        ...

Prevention

When it happens

Trigger: Calling enterprise_value or equity_value_from_enterprise_value with total_debt=math.nan or float('inf'); often debt is summed from balance-sheet lines where one is NaN.

Common situations: Balance-sheet extraction returning NaN for a missing debt line; DataFrame sum over all-NaN columns yielding NaN; JSON nulls coerced to NaN by a numeric parser.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/868e99aa9ab5e5d8. Report an issue: GitHub.