HKUDS/Vibe-Trading · error · ValuationError

comps.enterprise_value: market_cap must be a finite number,

Error message

comps.enterprise_value: market_cap must be a finite number, got {market_cap!r}

What it means

enterprise_value validates that market_cap is finite before adding the bridge delta. A NaN or infinite market cap (the anchor of the whole EV computation) would make every downstream multiple meaningless, so it is rejected.

Source

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

        MissingInputError: If `market_cap`, `total_debt` or
            `cash_and_equivalents` is absent.
        ValuationError: If `market_cap` or any supplied bridge line is not a
            finite number.
    """
    require_inputs(
        {
            "market_cap": market_cap,
            "total_debt": total_debt,
            "cash_and_equivalents": cash_and_equivalents,
        },
        ("market_cap", "total_debt", "cash_and_equivalents"),
        "comps.enterprise_value",
    )
    delta, omitted = _bridge_delta(
        total_debt, cash_and_equivalents, minority_interest, preferred_stock, investments_in_associates
    )
    if not math.isfinite(market_cap):
        raise ValuationError(
            f"comps.enterprise_value: market_cap must be a finite number, got {market_cap!r}"
        )
    ev = float(market_cap) + delta
    return EVBridgeResult(
        direction="equity_to_ev",
        equity_value=float(market_cap),
        enterprise_value=ev,
        total_debt=float(total_debt),
        cash_and_equivalents=float(cash_and_equivalents),
        minority_interest=minority_interest,
        preferred_stock=preferred_stock,
        investments_in_associates=investments_in_associates,
        omitted_components=omitted,
    )


def equity_value_from_enterprise_value(
    *,

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Validate market cap at its source (price * shares) with a finite check.
  2. Backfill or drop the peer whose market cap is unavailable.
  3. Guard before calling: if not math.isfinite(market_cap): skip/exclude the peer.

Example fix

# before
ev = enterprise_value(price * shares, ...)  # shares = nan

# after
market_cap = price * shares
if not math.isfinite(market_cap):
    raise ValueError(f'bad market cap for {ticker}')
ev = enterprise_value(market_cap, ...)
Defensive patterns

Strategy: validation

Validate before calling

if market_cap is None or not math.isfinite(market_cap):
    raise ValueError(f'bad market cap: {market_cap!r}')

Type guard

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

Try / catch

try:
    ev = enterprise_value(market_cap, ...)
except ValuationError:
    skip_peer(peer)  # excluded from the comp set

Prevention

When it happens

Trigger: Calling enterprise_value(market_cap=math.nan) or with inf; commonly a market cap computed as price * shares where shares is NaN, or a ' MISSING' string converted badly.

Common situations: Price feed gaps producing NaN; share counts of 0 combined with inf prices; API responses with null market cap coerced to NaN.

Related errors


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