HKUDS/Vibe-Trading · error · ValueError
breaches needs at least 2 observations to hold a transition,
Error message
breaches needs at least 2 observations to hold a transition, got {flags.size} What it means
The Christoffersen independence test is based on lag-1 transitions between consecutive breach flags, which requires at least two observations to form even one transition. With zero or one flag there is nothing to test, so the function refuses to compute.
Source
Thrown at agent/src/quantlib/var_backtest.py:432
Returns:
An :class:`IndependenceResult`. When the sample holds no breach, or
holds breaches only in its final position, the transition probabilities
are not separately identified; the statistic is then 0 with
``identified=False`` rather than an arbitrary number.
Raises:
ValueError: If ``breaches`` holds fewer than two observations or is not
1-D, or if ``significance`` is not strictly between 0 and 1.
"""
if not 0.0 < significance < 1.0:
raise ValueError(f"significance must be in (0, 1), got {significance}")
flags = np.asarray(breaches)
if flags.ndim != 1:
raise ValueError(f"breaches must be 1-D, got shape {flags.shape}")
if flags.size < 2:
raise ValueError(
f"breaches needs at least 2 observations to hold a transition, got {flags.size}"
)
flags = flags.astype(bool)
prev, curr = flags[:-1], flags[1:]
n00 = int(np.sum(~prev & ~curr))
n01 = int(np.sum(~prev & curr))
n10 = int(np.sum(prev & ~curr))
n11 = int(np.sum(prev & curr))
from_calm = n00 + n01
from_breach = n10 + n11
total = from_calm + from_breach
pi01 = n01 / from_calm if from_calm else 0.0
pi11 = n11 / from_breach if from_breach else 0.0
pi = (n01 + n11) / total if total else 0.0
View on GitHub (pinned to 80ffdda44c)
Solutions
- Provide at least two breach observations; for a meaningful test use hundreds.
- Check the length of your aligned, finite returns/VaR series before testing.
- If data is genuinely short-cadence, skip independence testing and report only Kupiec POF.
Example fix
# before christoffersen_independence(breaches[:1]) # after christoffersen_independence(breaches) # len(breaches) >= 2
Defensive patterns
Strategy: validation
Validate before calling
if len(breaches) < 2:
raise ValueError('need >= 2 breach observations')
christoffersen_independence(breaches, significance=0.05) Prevention
- Check series length after any NaN filtering or date slicing.
- Short samples: report only Kupiec POF.
When it happens
Trigger: Calling christoffersen_independence([]) or christoffersen_independence([1]), or calling var_backtest on a returns/var pair that aligns to fewer than two finite observations (var_backtest has its own guard, but direct calls hit this one).
Common situations: Backtesting a brand-new strategy with a single day of data, or filtering a series down (dropping NaNs, date slicing) until fewer than two points remain before calling the test.
Related errors
- var_backtest needs at least 2 aligned observations, got {ret
- invalid alpha_id
- alpha_id not found
- invalid period: {exc}
- too many running benches; wait for one to finish
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/c603eff23cd44424.
Report an issue: GitHub.