{"record":{"id":"19293eac996c8017","repo":"HKUDS/Vibe-Trading","slug":"model-name-must-be-supplied-as-a-non-negative","errorCode":null,"errorMessage":"{model}: {name} must be supplied as a non-negative magnitude (its sign is applied by the bridge formula), got {numeric!r}","messagePattern":"(.+?): (.+?) must be supplied as a non-negative magnitude \\(its sign is applied by the bridge formula\\), got (.+?)","errorType":"validation","errorClass":"ValuationError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/valuation/dcf.py","lineNumber":247,"sourceCode":"    Args:\n        value: The candidate magnitude.\n        name: Field name for the error message.\n        model: Model name for the error message.\n\n    Returns:\n        ``value`` as a float.\n\n    Raises:\n        ValuationError: If the value is negative or not a finite number. A\n            negative magnitude here would silently flip the sign the bridge\n            formula already applies.\n    \"\"\"\n    try:\n        numeric = float(value)\n    except (TypeError, ValueError) as exc:\n        raise ValuationError(f\"{model}: {name} must be a number, got {value!r}\") from exc\n    if not math.isfinite(numeric) or numeric < 0.0:\n        raise ValuationError(\n            f\"{model}: {name} must be supplied as a non-negative magnitude \"\n            f\"(its sign is applied by the bridge formula), got {numeric!r}\"\n        )\n    return numeric\n\n\ndef _require_finite(value: float, name: str, model: str) -> float:\n    \"\"\"Check a value is a finite number, refusing NaN and infinity.\n\n    Args:\n        value: The candidate value.\n        name: Field name for the error message.\n        model: Model name for the error message.\n\n    Returns:\n        ``value`` as a float.\n\n    Raises:","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/valuation/dcf.py#L229-L265","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass the absolute magnitude: abs(value) if the sign is genuinely the magnitude's opposite.","Check finiteness at source and repair NaN/inf inputs.","Confirm parameter semantics in the docstring: magnitude only, sign handled internally."],"exampleFix":"# before\nequity_bridge(..., risk_premium=-0.045)  # stored as a negative\n\n# after\nequity_bridge(..., risk_premium=abs(stored_value))  # 0.045, sign applied by formula","handlingStrategy":"validation","validationCode":"m = float(magnitude)\nif not math.isfinite(m) or m < 0:\n    raise ValueError(f'magnitude must be non-negative finite, got {m}')","typeGuard":"def is_nonnegative_finite(v):\n    return isinstance(v, (int, float)) and math.isfinite(v) and v >= 0","tryCatchPattern":"except ValuationError as e:\n    if 'non-negative magnitude' in str(e):\n        magnitude = abs(magnitude)  # if sign was the only issue","preventionTips":["Store magnitudes unsigned; let formulas apply signs","Validate finiteness/sign on bridge inputs before calling"],"tags":["valuation","sign-error","nan","magnitude"],"backgroundTag":"value-out-of-range","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}