{"record":{"id":"63048ba886de356d","repo":"HKUDS/Vibe-Trading","slug":"confidence-must-be-in-0-1-got-confidence-63048b","errorCode":null,"errorMessage":"confidence must be in (0, 1), got {confidence}","messagePattern":"confidence must be in \\(0, 1\\), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/var_backtest.py","lineNumber":368,"sourceCode":"        confidence: VaR confidence level the model claims, e.g. 0.99.\n        significance: Level at which ``rejected`` is decided.\n\n    Returns:\n        A :class:`KupiecResult`.\n\n    Raises:\n        ValueError: If ``observations`` is not positive, if ``violations`` is\n            negative or exceeds ``observations``, or if either probability is\n            not strictly between 0 and 1.\n    \"\"\"\n    if observations <= 0:\n        raise ValueError(f\"observations must be > 0, got {observations}\")\n    if not 0 <= violations <= observations:\n        raise ValueError(\n            f\"violations must be in [0, {observations}], got {violations}\"\n        )\n    if not 0.0 < confidence < 1.0:\n        raise ValueError(f\"confidence must be in (0, 1), got {confidence}\")\n    if not 0.0 < significance < 1.0:\n        raise ValueError(f\"significance must be in (0, 1), got {significance}\")\n\n    expected_rate = 1.0 - confidence\n    observed_rate = violations / observations\n    calm = observations - violations\n\n    restricted = xlogy(calm, 1.0 - expected_rate) + xlogy(violations, expected_rate)\n    unrestricted = xlogy(calm, 1.0 - observed_rate) + xlogy(violations, observed_rate)\n    statistic = float(max(-2.0 * (restricted - unrestricted), 0.0))\n    p_value = float(chi2.sf(statistic, df=1))\n\n    return KupiecResult(\n        observations=observations,\n        violations=violations,\n        expected_violations=observations * expected_rate,\n        violation_rate=observed_rate,\n        expected_rate=expected_rate,","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/var_backtest.py#L350-L386","documentation":"kupiec_pof requires the VaR confidence level to be strictly between 0 and 1; 0, 1, negatives, or values > 1 raise ValueError. The confidence determines the expected breach rate (1 - confidence) used in the likelihood ratio, and at the boundaries the null likelihood degenerates.","triggerScenarios":"Passing confidence=0.99 as 99 (percent), confidence=1, or confidence=0 — often when config stores percent integers or the argument is swapped with significance.","commonSituations":"Configs storing '99' instead of 0.99; copying parameters from papers that quote percentages; argument-order mixups between confidence and significance.","solutions":["Convert percent to a fraction: 99 -> 0.99.","Check for accidental swap with the significance argument.","Validate 0 < c < 1 in config loading."],"exampleFix":"# before\nkupiec_pof(n, v, confidence=99, significance=0.05)\n# after\nkupiec_pof(n, v, confidence=0.99, significance=0.05)","handlingStrategy":"validation","validationCode":"assert 0.0 < confidence < 1.0","typeGuard":"def valid_probability(p) -> bool:\n    return isinstance(p, (int, float)) and 0.0 < p < 1.0","tryCatchPattern":"except ValueError as e:\n    if 'confidence must be in (0, 1)' in str(e): confidence /= 100.0; retry","preventionTips":["Store confidence as a fraction (0.99) in config, never percent","Pass confidence/significance as keywords to avoid swapping"],"tags":["var-backtest","kupiec","range-validation","confidence-level"],"backgroundTag":"probability-out-of-range","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}