HKUDS/Vibe-Trading · error · ValueError
bootstrap_statistic needs n_bootstrap >= 1, got {n_bootstrap
Error message
bootstrap_statistic needs n_bootstrap >= 1, got {n_bootstrap} What it means
bootstrap_statistic requires n_bootstrap >= 1; zero or negative resamples cannot produce a confidence interval, so the function validates the count before allocating the results array.
Source
Thrown at agent/src/quantlib/timeseries.py:804
data: One-dimensional sample of observations.
statistic_func: Callable mapping a resample to a scalar, e.g. ``np.mean``.
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)),View on GitHub (pinned to 80ffdda44c)
Solutions
- Pass n_bootstrap >= 1 (default 10000 is typical).
- Clamp computed values: n_bootstrap = max(1, computed).
- Validate config before the run loop.
Example fix
// before bootstrap_statistic(data, n_bootstrap=n_draws) # n_draws == 0 // after bootstrap_statistic(data, n_bootstrap=max(1, n_draws))
Defensive patterns
Strategy: validation
Validate before calling
if n_bootstrap is None or int(n_bootstrap) < 1:
n_bootstrap = 10_000
bootstrap_statistic(data, n_bootstrap=n_bootstrap) Prevention
- Clamp computed draw counts with max(1, ...).
- Validate numeric config knobs (n_bootstrap, confidence) once at startup.
When it happens
Trigger: bootstrap_statistic(data, n_bootstrap=0) or a negative value; commonly a config knob (e.g. n_bootstrap = int(confidence * 0)) that evaluates to 0.
Common situations: Parameter sweeps or YAML configs where the resample count is computed and can floor to 0; CLI flags parsed with a missing default.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- autocorrelation_test needs lags >= 1, got {lags}
- lags must be < the number of observations; got lags={lags} f
- bootstrap_statistic needs a non-empty sample
- bootstrap_statistic needs confidence in (0, 1), got {confide
- vif_test needs at least one column
AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28).
Data as JSON: /api/errors/eb72415e22fa1bb7.
Report an issue: GitHub.