HKUDS/Vibe-Trading · error · ValuationError

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

Error message

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

What it means

_require_nonnegative coerces then rejects values that fail float() (strings like '5%', None) with 'must be a number'. It guards bridge/sign-sensitive magnitudes (used by wacc, equity_bridge, sensitivity_grid) where the caller supplies a magnitude and the formula applies the sign.

Source

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

    """Check a value that is a signed formula's magnitude, so must be >= 0.

    Args:
        value: The candidate magnitude.
        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 negative or not a finite number. A
            negative magnitude here would silently flip the sign the bridge
            formula already applies.
    """
    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) or numeric < 0.0:
        raise ValuationError(
            f"{model}: {name} must be supplied as a non-negative magnitude "
            f"(its sign is applied by the bridge formula), got {numeric!r}"
        )
    return numeric


def _require_finite(value: float, name: str, model: str) -> float:
    """Check a value is a finite number, refusing NaN and infinity.

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

    Returns:
        ``value`` as a float.

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Parse/convert to float upstream; strip '%' and divide by 100 where applicable.
  2. Default optional magnitudes to 0.0 when genuinely absent rather than None.
  3. Validate config types at load time so strings never reach the model.

Example fix

# before
wacc(..., debt_beta='0.15')

# after
wacc(..., debt_beta=0.15)
Defensive patterns

Strategy: type-guard

Validate before calling

try:
    magnitude = float(value)
except (TypeError, ValueError):
    raise ValueError(f'expected numeric magnitude, got {value!r}')

Type guard

def is_numeric(v):
    return isinstance(v, (int, float)) and not isinstance(v, bool)

Try / catch

except ValuationError as e:
    if 'must be a number' in str(e):
        magnitude = parse_percent_string(value)

Prevention

When it happens

Trigger: Calling wacc/equity_bridge/sensitivity_grid with a non-numeric magnitude, e.g. a spread of None or '1.5%' instead of 0.015.

Common situations: Config values as formatted strings; optional parameters left as None by a partial-config loader; Excel imports with text cells.

Related errors


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