{"record":{"id":"0bbc3d70876721c0","repo":"HKUDS/Vibe-Trading","slug":"var-backtest-needs-at-least-2-aligned-observations","errorCode":null,"errorMessage":"var_backtest needs at least 2 aligned observations, got {ret_values.size}","messagePattern":"var_backtest needs at least 2 aligned observations, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/var_backtest.py","lineNumber":629,"sourceCode":"    Args:\n        returns: Realised returns, signed, in chronological order.\n        var: VaR forecasts as positive loss magnitudes -- one per return, or a\n            scalar for a constant-VaR model. When both sides are indexed Series\n            the labels must match exactly.\n        confidence: VaR confidence level the model claims, e.g. 0.99.\n        significance: Level at which each ``rejected`` flag is decided.\n\n    Returns:\n        A :class:`VarBacktestReport` carrying the Kupiec, independence, joint\n        and Basel results plus the breach dates when an index was supplied.\n\n    Raises:\n        ValueError: If the inputs cannot be aligned, if fewer than two finite\n            pairs survive, or if either probability is out of range.\n    \"\"\"\n    ret_values, var_values, index, dropped = _align(returns, var)\n    if ret_values.size < 2:\n        raise ValueError(\n            f\"var_backtest needs at least 2 aligned observations, got {ret_values.size}\"\n        )\n\n    breaches = ret_values < -var_values\n    conditional = christoffersen_conditional_coverage(\n        breaches, confidence=confidence, significance=significance\n    )\n    traffic = basel_traffic_light(\n        violations=int(breaches.sum()),\n        observations=int(breaches.size),\n        confidence=confidence,\n    )\n    breach_dates = tuple(index[breaches]) if index is not None else None\n\n    return VarBacktestReport(\n        confidence=confidence,\n        observations=int(breaches.size),\n        violations=int(breaches.sum()),","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/var_backtest.py#L611-L647","documentation":"var_backtest aligns returns and VaR forecasts, drops non-finite pairs, and requires at least two surviving observations because the Christoffersen independence component needs a minimum of one lag-1 transition. Fewer than two aligned points cannot support any backtest statistic.","triggerScenarios":"Calling var_backtest with empty series, one-row series, or series where all but one pair contain NaN/Inf (mismatched dates with NaN fills are the classic cause). Also when returns and var have no overlapping index.","commonSituations":"Merging returns and VaR on dates with no overlap (all-NaN alignment), loading a VaR file that is stale relative to the returns series, or backtesting during a model warm-up period where the VaR forecast is NaN.","solutions":["Check the overlap of the returns and VaR indices before calling; reindex/join explicitly on shared dates.","Drop NaN pairs yourself and assert len >= 2 (the function also returns a dropped count — inspect it).","Ensure the VaR series covers the same date range as returns."],"exampleFix":"# before\nvar_backtest(returns, var)  # non-overlapping date indices -> all NaN\n# after\ncommon = returns.index.intersection(var.index)\nvar_backtest(returns.loc[common], var.loc[common])","handlingStrategy":"validation","validationCode":"import numpy as np, pandas as pd\nr = pd.Series(returns).dropna()\nv = pd.Series(var).dropna()\ncommon = r.index.intersection(v.index)\nif len(common) < 2:\n    raise ValueError(f'insufficient overlap: {len(common)} shared points')\nresult = var_backtest(r.loc[common], v.loc[common])","typeGuard":null,"tryCatchPattern":"try:\n    result = var_backtest(returns, var)\nexcept ValueError as e:\n    if 'aligned observations' in str(e):\n        logger.warning('skipping backtest: %s', e)\n    else:\n        raise","preventionTips":["Join returns and VaR on a shared date index first.","Inspect the dropped-pair count returned by var_backtest.","Don't backtest during VaR model warm-up (NaN forecasts)."],"tags":["python","validation","data-alignment","insufficient-data","var-backtest"],"backgroundTag":"insufficient-sample-size","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}