HKUDS/Vibe-Trading · error · ValueError

confidence must be in (0, 1), got {confidence}

Error message

confidence must be in (0, 1), got {confidence}

What it means

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.

Source

Thrown at agent/src/quantlib/var_backtest.py:368

        confidence: VaR confidence level the model claims, e.g. 0.99.
        significance: Level at which ``rejected`` is decided.

    Returns:
        A :class:`KupiecResult`.

    Raises:
        ValueError: If ``observations`` is not positive, if ``violations`` is
            negative or exceeds ``observations``, or if either probability is
            not strictly between 0 and 1.
    """
    if observations <= 0:
        raise ValueError(f"observations must be > 0, got {observations}")
    if not 0 <= violations <= observations:
        raise ValueError(
            f"violations must be in [0, {observations}], got {violations}"
        )
    if not 0.0 < confidence < 1.0:
        raise ValueError(f"confidence must be in (0, 1), got {confidence}")
    if not 0.0 < significance < 1.0:
        raise ValueError(f"significance must be in (0, 1), got {significance}")

    expected_rate = 1.0 - confidence
    observed_rate = violations / observations
    calm = observations - violations

    restricted = xlogy(calm, 1.0 - expected_rate) + xlogy(violations, expected_rate)
    unrestricted = xlogy(calm, 1.0 - observed_rate) + xlogy(violations, observed_rate)
    statistic = float(max(-2.0 * (restricted - unrestricted), 0.0))
    p_value = float(chi2.sf(statistic, df=1))

    return KupiecResult(
        observations=observations,
        violations=violations,
        expected_violations=observations * expected_rate,
        violation_rate=observed_rate,
        expected_rate=expected_rate,

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Convert percent to a fraction: 99 -> 0.99.
  2. Check for accidental swap with the significance argument.
  3. Validate 0 < c < 1 in config loading.

Example fix

# before
kupiec_pof(n, v, confidence=99, significance=0.05)
# after
kupiec_pof(n, v, confidence=0.99, significance=0.05)
Defensive patterns

Strategy: validation

Validate before calling

assert 0.0 < confidence < 1.0

Type guard

def valid_probability(p) -> bool:
    return isinstance(p, (int, float)) and 0.0 < p < 1.0

Try / catch

except ValueError as e:
    if 'confidence must be in (0, 1)' in str(e): confidence /= 100.0; retry

Prevention

When it happens

Trigger: 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.

Common situations: Configs storing '99' instead of 0.99; copying parameters from papers that quote percentages; argument-order mixups between confidence and significance.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/63048ba886de356d. Report an issue: GitHub.