{"record":{"id":"22e9cd04efda08a3","repo":"HKUDS/Vibe-Trading","slug":"latest-valuation-on-marks-1-date-is-value-r","errorCode":null,"errorMessage":"latest valuation on {marks[-1].date} is {value!r}; a residual value must be non-negative. If the vehicle really carries negative equity, record it under a custom kind and compute the multiple explicitly.","messagePattern":"latest valuation on (.+?) is (.+?); a residual value must be non-negative\\. If the vehicle really carries negative equity, record it under a custom kind and compute the multiple explicitly\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/fundmath.py","lineNumber":687,"sourceCode":"            ``residual_value``, ``valuation``).\n\n    Returns:\n        The latest mark's amount, or ``0.0`` when the series holds no mark --\n        which is the right answer for a fully liquidated fund.\n\n    Raises:\n        TypeError: If ``series`` is not a ``CashFlowSeries``.\n        ValueError: If the latest mark is negative. A negative NAV is possible\n            in a levered vehicle but is never what a mis-signed file means, so\n            it must be stated as a custom kind rather than inferred here.\n    \"\"\"\n    _require_series(series)\n    marks = [flow for flow in series if flow.is_valuation]\n    if not marks:\n        return 0.0\n    value = marks[-1].amount\n    if value < 0.0:\n        raise ValueError(\n            f\"latest valuation on {marks[-1].date} is {value!r}; a residual \"\n            \"value must be non-negative. If the vehicle really carries negative \"\n            \"equity, record it under a custom kind and compute the multiple \"\n            \"explicitly.\"\n        )\n    return value\n\n\ndef _require_paid_in(paid_in: float) -> float:\n    \"\"\"Reject a zero or negative denominator for a capital multiple.\n\n    Args:\n        paid_in: Paid-in capital as a positive magnitude.\n\n    Returns:\n        The same value.\n\n    Raises:","sourceCodeStart":669,"sourceCodeEnd":705,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/fundmath.py#L669-L705","documentation":"The fund-math residual_value helper takes the last valuation mark in the cash-flow series as the residual (unrealized) value and refuses negative amounts. A negative latest mark would make RVPI/TVPI/MOIC misleading, so the library raises rather than silently producing a nonsensical multiple. Negative equity must be modeled explicitly by the caller.","triggerScenarios":"Calling rvpi, tvpi, moic, fund_multiples, european_waterfall, or ks_pme on a CashFlowSeries whose most recent is_valuation flow has amount < 0 (e.g. a final mark of -1_000_000).","commonSituations":"Loading a NAV file where the final period shows negative equity (liabilities exceed assets), or a sign-convention mistake where outflows were recorded as negative valuations instead of negative contributions.","solutions":["Check the sign convention of your valuation records; NAV marks should be non-negative","If the vehicle truly has negative equity, record it under a custom flow kind and compute the multiple manually instead of relying on residual_value","Drop or correct the offending final valuation mark and re-run the multiple"],"exampleFix":"# before\nseries.append(Flow(date=d, amount=-250_000.0, kind=\"valuation\"))\nrvpi(series, paid_in=1_000_000.0)  # raises ValueError\n\n# after\nseries.append(Flow(date=d, amount=0.0, kind=\"valuation\"))\n# negative equity tracked separately under a custom kind and handled explicitly","handlingStrategy":"validation","validationCode":"latest = [f for f in series if f.is_valuation]\nif latest and latest[-1].amount < 0:\n    raise CustomDataError(\"negative final NAV; model explicitly\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate final NAV sign at data-load time","Keep valuation marks non-negative by convention","Document negative-equity handling in your data dictionary"],"tags":["fund-math","valuation","rvpi","sign-convention"],"backgroundTag":"invalid-input-value","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}