HKUDS/Vibe-Trading · error · ValuationError

{model}: {name} must be supplied as a non-negative magnitude

Error message

{model}: {name} must be supplied as a non-negative magnitude (its sign is applied by the bridge formula), got {numeric!r}

What it means

After coercion, _require_nonnegative rejects non-finite or negative magnitudes: these parameters are supplied as non-negative magnitudes whose sign is applied by the bridge formula, so a negative input would silently flip the sign of the result.

Source

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

    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.

    Raises:

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Pass the absolute magnitude: abs(value) if the sign is genuinely the magnitude's opposite.
  2. Check finiteness at source and repair NaN/inf inputs.
  3. Confirm parameter semantics in the docstring: magnitude only, sign handled internally.

Example fix

# before
equity_bridge(..., risk_premium=-0.045)  # stored as a negative

# after
equity_bridge(..., risk_premium=abs(stored_value))  # 0.045, sign applied by formula
Defensive patterns

Strategy: validation

Validate before calling

m = float(magnitude)
if not math.isfinite(m) or m < 0:
    raise ValueError(f'magnitude must be non-negative finite, got {m}')

Type guard

def is_nonnegative_finite(v):
    return isinstance(v, (int, float)) and math.isfinite(v) and v >= 0

Try / catch

except ValuationError as e:
    if 'non-negative magnitude' in str(e):
        magnitude = abs(magnitude)  # if sign was the only issue

Prevention

When it happens

Trigger: Passing -0.02, math.nan, or inf as a magnitude to wacc/equity_bridge/sensitivity_grid — e.g. entering a spread as a negative because it was stored as a signed change.

Common situations: Data stored as signed deltas (rate cuts as negative) fed into magnitude parameters; NaN from empty series; double-negation bugs when converting (1 - tax) style inputs.

Related errors


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