HKUDS/Vibe-Trading · error · ValuationError

comps: cash_and_equivalents must be a finite number, got

Error message

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

What it means

The EV bridge requires cash_and_equivalents to be finite. Since cash is subtracted from debt to get net debt, NaN cash would corrupt the bridge in both directions (EV and implied equity).

Solutions

  1. Print/validate cash_and_equivalents before the bridge call and trace where NaN came from.
  2. Substitute a justified value (0.0 or sourced cash figure) once confirmed.
  3. Add ingestion-time finite checks for all bridge inputs.

Example fix

# before
ev = enterprise_value(market_cap, total_debt, cash)  # cash = nan

# after
cash = 0.0 if cash is None or not math.isfinite(cash) else float(cash)
ev = enterprise_value(market_cap, total_debt, cash)
Defensive patterns

Strategy: validation

Validate before calling

import math
cash = 0.0 if cash is None else float(cash)
if not math.isfinite(cash):
    raise ValueError(f'cash not finite: {cash!r}')

Try / catch

except ValuationError as e:
    if 'cash_and_equivalents' in str(e):
        cash = 0.0  # documented fallback
        ev = enterprise_value(market_cap, total_debt, cash)

Prevention

When it happens

Trigger: Calling enterprise_value / equity_value_from_enterprise_value with cash_and_equivalents=math.nan or float('inf'), e.g. a missing cash figure parsed into NaN.

Common situations: Missing cash line in scraped or API-fetched balance sheets; pandas operations (mean of empty series) returning NaN; unit-conversion bugs producing inf.

Related errors


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

Appendix: source

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

    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}"
            )
        sign = -1.0 if name == "investments_in_associates" else 1.0
        total += sign * value
    return total, tuple(omitted)

View on GitHub (pinned to 80ffdda44c)