{"record":{"id":"6b37b42610e2f5b1","repo":"HKUDS/Vibe-Trading","slug":"as-of-is-required-for-an-empty-series","errorCode":null,"errorMessage":"as_of is required for an empty series","messagePattern":"as_of is required for an empty series","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/fundmath.py","lineNumber":975,"sourceCode":"            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\n    total = 0.0\n    for flow in contributions:\n        years = (measurement - flow.date).days / days_per_year\n        if years < 0.0:\n            raise ValueError(\n                f\"contribution on {flow.date} is after as_of={measurement}; a \"\n                \"preferred return cannot accrue backwards\"\n            )\n        principal = -flow.amount\n        if compounding == \"compound\":\n            total += principal * ((1.0 + rate) ** years - 1.0)\n        else:\n            total += principal * rate * years\n    return total","sourceCodeStart":957,"sourceCodeEnd":993,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/fundmath.py#L957-L993","documentation":"When as_of is omitted, preferred_return_amount measures at the latest flow date, which is impossible for an empty series, so an explicit as_of is mandatory in that case.","triggerScenarios":"Calling preferred_return_amount on an empty CashFlowSeries with as_of=None (the default).","commonSituations":"Running the calculation over a batch of funds where some have no contributions yet; filters that removed all flows before the call.","solutions":["Pass an explicit as_of date, e.g. as_of=\"2024-12-31\"","Skip empty series in batch jobs before calling"],"exampleFix":"# before\npreferred_return_amount(empty_series, rate=0.08)\n\n# after\npreferred_return_amount(empty_series, rate=0.08, as_of=\"2024-12-31\")","handlingStrategy":"validation","validationCode":"if series.is_empty and as_of is None:\n    as_of = period_end_date  # supply explicit measurement date","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass as_of explicitly in batch pipelines","Skip empty series early"],"tags":["fund-math","preferred-return","empty-series","required-parameter"],"backgroundTag":"missing-required-parameter","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}