HKUDS/Vibe-Trading · error · ValueError

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

Error message

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

What it means

kupiec_pof requires the test significance level strictly in (0, 1); 0, 1 or out-of-range values raise ValueError. Significance (e.g. 0.05) selects the chi-square critical value for rejecting the coverage null, and the boundaries make the test meaningless.

Source

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

    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,
        statistic=statistic,
        p_value=p_value,

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Use a fraction: 5% -> 0.05.
  2. Verify you have not swapped the confidence and significance positional/keyword args.
  3. Range-check user-supplied alpha before the call.

Example fix

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

Strategy: validation

Validate before calling

assert 0.0 < significance < 1.0

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Passing significance=5 (percent instead of fraction), significance=0, or significance=1; also swapping significance with confidence so both end up wrong.

Common situations: Percent-vs-fraction confusion in config files; hardcoded alphas copied from documentation quoting '5%'; argument-order mixups.

Related errors


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