HKUDS/Vibe-Trading · error · ValuationError

{model}: {name} must be a finite number, got {numeric!r}

Error message

{model}: {name} must be a finite number, got {numeric!r}

What it means

Raised by _require_finite when the input converts to float but is not finite (NaN, +inf, -inf). Part of the package's no-silent-defaults rule: a NaN would otherwise propagate into a silently wrong per-share number.

Source

Thrown at agent/src/quantlib/valuation/dcf.py:276

        value: The candidate value.
        name: Field name for the error message.
        model: Model name for the error message.

    Returns:
        ``value`` as a float.

    Raises:
        ValuationError: If the value is not a finite number. A non-finite
            input here would otherwise flow through the valuation arithmetic
            and surface as a silently wrong per-share number, which is exactly
            the outcome the package's no-silent-defaults rule exists to prevent.
    """
    try:
        numeric = float(value)
    except (TypeError, ValueError) as exc:
        raise ValuationError(f"{model}: {name} must be a number, got {value!r}") from exc
    if not math.isfinite(numeric):
        raise ValuationError(
            f"{model}: {name} must be a finite number, got {numeric!r}"
        )
    return numeric


def _validate_weights(equity_weight: float, debt_weight: float, *, model: str) -> None:
    """Check that a pair of capital-structure weights is usable.

    Args:
        equity_weight: Proposed ``E / (D + E)``.
        debt_weight: Proposed ``D / (D + E)``.
        model: Model name for the error message.

    Raises:
        ValuationError: If either weight is negative, or if they do not sum to
            1 within :data:`_RECONCILIATION_TOLERANCE`.
    """
    if equity_weight < 0.0 or debt_weight < 0.0:

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Filter or impute NaN/inf in upstream data before valuation
  2. Guard divisions upstream (denominator zero-checks) so inf never reaches the model
  3. Assert math.isfinite on all derived inputs in a pre-flight validation step

Example fix

# before
fcff = row['fcff'] if row else float('nan')
... discount_fcff(fcff, ...)

# after
fcff = float(row['fcff']) if row and math.isfinite(row['fcff']) else raise_missing(row)
Defensive patterns

Strategy: validation

Validate before calling

import math
assert all(math.isfinite(v) for v in [beta, rfr, erp, pretax_kd]), 'non-finite input'

Type guard

def is_finite_number(x) -> TypeGuard[float]:
    return isinstance(x, (int, float)) and math.isfinite(x)

Try / catch

try:
    fcff_bridge(...)
except ValuationError as e:
    if 'finite' in str(e):
        row['status'] = 'bad_data'
        continue

Prevention

When it happens

Trigger: Passing float('nan'), float('inf'), or the result of 0.0/0.0 / overflowing computations to any numeric parameter of wacc, fcff_bridge, terminal_value, discount_fcff, equity_bridge, sensitivity_grid.

Common situations: Upstream data gaps encoded as NaN (missing rows from pandas); division-by-zero in a preprocessing step feeding the model; JSON parsing 'Infinity' literal.

Related errors


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