{"record":{"id":"3bea6e4969fbe80b","repo":"HKUDS/Vibe-Trading","slug":"preferred-rate-must-be-non-negative-got-rate-r","errorCode":null,"errorMessage":"preferred rate must be non-negative, got {rate!r}","messagePattern":"preferred rate must be non-negative, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/fundmath.py","lineNumber":961,"sourceCode":"        compounding: One of :data:`PREFERRED_COMPOUNDING`. ``\"compound\"``\n            accrues ``(1 + rate) ** years - 1``; ``\"simple\"`` accrues\n            ``rate * years``.\n        days_per_year: Day basis for the year fraction.\n        contribution_kinds: Kind labels counted as capital in.\n\n    Returns:\n        The preferred return owed, as a positive magnitude excluding the return\n        of capital itself. ``0.0`` when nothing has been drawn.\n\n    Raises:\n        TypeError: If ``series`` is not a ``CashFlowSeries``.\n        ValueError: If the rate is negative, the compounding convention is\n            unknown, ``as_of`` precedes a contribution, or ``as_of`` is omitted\n            for an empty series.\n    \"\"\"\n    _require_series(series)\n    if rate < 0.0:\n        raise ValueError(f\"preferred rate must be non-negative, got {rate!r}\")\n    if compounding not in PREFERRED_COMPOUNDING:\n        raise ValueError(\n            f\"compounding={compounding!r} is not one of {PREFERRED_COMPOUNDING}\"\n        )\n    if days_per_year <= 0:\n        raise ValueError(f\"days_per_year must be positive, got {days_per_year!r}\")\n\n    contributions = tuple(series.filter(kind=contribution_kinds))\n    if not contributions:\n        return 0.0\n\n    if as_of is None:\n        if series.is_empty:\n            raise ValueError(\"as_of is required for an empty series\")\n        measurement = max(series.dates())\n    else:\n        measurement = normalize_date(as_of, field_name=\"as_of\")\n","sourceCodeStart":943,"sourceCodeEnd":979,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/fundmath.py#L943-L979","documentation":"preferred_return_amount validates its hurdle rate and rejects negative values because the compounding convention for a negative preferred rate is undefined. Only rate >= 0 is accepted.","triggerScenarios":"Calling preferred_return_amount(series, rate=-0.08) (or european_waterfall/_pooled_entitlement with a negative hurdle rate parameter).","commonSituations":"Parsing a hurdle like '-8' from config when it was meant as 8%; sign errors when converting an annual rate; unit tests passing negative fixtures.","solutions":["Pass the rate as a non-negative decimal (0.08 for 8%)","Check the config/parse step that produced the negative value","Use 0.0 explicitly for a no-hurdle fund"],"exampleFix":"# before\npreferred_return_amount(series, rate=-0.08)\n\n# after\npreferred_return_amount(series, rate=0.08)","handlingStrategy":"validation","validationCode":"if rate < 0:\n    raise ConfigError(f\"hurdle rate must be >= 0, got {rate}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate rates at the config boundary","Use abs() only after confirming the sign error, never as a blanket fix"],"tags":["fund-math","preferred-return","hurdle-rate","validation"],"backgroundTag":"invalid-argument-range","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}