HKUDS/Vibe-Trading · error · ValueError
bootstrap_statistic needs confidence in (0, 1), got {confide
Error message
bootstrap_statistic needs confidence in (0, 1), got {confidence} What it means
bootstrap_statistic requires confidence strictly inside (0, 1). Values of 0, 1, or outside give degenerate percentiles (min/max of the sample), so they are rejected before resampling.
Source
Thrown at agent/src/quantlib/timeseries.py:806
n_bootstrap: Number of bootstrap resamples.
confidence: Confidence level in (0, 1), e.g. 0.95 for a 95% interval.
seed: Seed for the random generator; pass an int for reproducible output.
Returns:
Dict with keys ``point_estimate``, ``bootstrap_mean``, ``bootstrap_std``,
``ci_lower``, ``ci_upper`` (all float) and ``confidence`` (float, echoed).
Raises:
ValueError: If ``data`` is empty, ``n_bootstrap`` is below 1, or
``confidence`` is not strictly inside (0, 1).
"""
sample = np.asarray(data, dtype=float).ravel()
if sample.size == 0:
raise ValueError("bootstrap_statistic needs a non-empty sample")
if n_bootstrap < 1:
raise ValueError(f"bootstrap_statistic needs n_bootstrap >= 1, got {n_bootstrap}")
if not 0.0 < confidence < 1.0:
raise ValueError(f"bootstrap_statistic needs confidence in (0, 1), got {confidence}")
rng = np.random.default_rng(seed)
n = sample.size
# Resample one draw at a time. Materialising the whole (n_bootstrap, n)
# index matrix would be ~160MB at the default 10000 draws over 2000 bars.
bootstrap_stats = np.empty(n_bootstrap, dtype=float)
for i in range(n_bootstrap):
bootstrap_stats[i] = float(statistic_func(sample[rng.integers(0, n, size=n)]))
alpha = 1 - confidence
return {
"point_estimate": float(statistic_func(sample)),
"bootstrap_mean": float(np.mean(bootstrap_stats)),
"bootstrap_std": float(np.std(bootstrap_stats)),
"ci_lower": float(np.percentile(bootstrap_stats, alpha / 2 * 100)),
"ci_upper": float(np.percentile(bootstrap_stats, (1 - alpha / 2) * 100)),
"confidence": confidence,
}View on GitHub (pinned to 80ffdda44c)
Solutions
- Pass a fraction strictly between 0 and 1, e.g. 0.95.
- If your config stores percentages, divide by 100 at the call site (and assert 0 < value < 1 for percentages in (0,100)).
- Reject 0.0/1.0 explicitly in config validation.
Example fix
// before bootstrap_statistic(data, confidence=95) // after bootstrap_statistic(data, confidence=0.95)
Defensive patterns
Strategy: validation
Validate before calling
if not 0.0 < confidence < 1.0:
if 0.0 < confidence <= 100.0: # percentage form
confidence = confidence / 100.0
else:
raise ValueError(f"confidence must be in (0,1), got {confidence}")
bootstrap_statistic(data, confidence=confidence) Prevention
- Standardize on fractions (0.95) in configs, never percentages.
- Document the (0,1) open interval at every API boundary that forwards confidence.
When it happens
Trigger: bootstrap_statistic(data, confidence=0.0 or 1.0 or 95); the classic mistake is passing a percentage (95) instead of a fraction (0.95).
Common situations: Config files storing confidence as 95 or 0.95 inconsistently; UI dropdowns returning percentages; refactoring from APIs that take alpha.
Related errors
- bootstrap_statistic needs a non-empty sample
- bootstrap_statistic needs n_bootstrap >= 1, got {n_bootstrap
- confidence must be in (0.0, 1.0), got {confidence}
- autocorrelation_test needs lags >= 1, got {lags}
- lags must be < the number of observations; got lags={lags} f
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/375679e770942a01.
Report an issue: GitHub.