HKUDS/Vibe-Trading · error · ValueError

bootstrap_statistic needs a non-empty sample

Error message

bootstrap_statistic needs a non-empty sample

What it means

bootstrap_statistic refuses an empty sample: np.asarray(data).ravel() must yield at least one element, otherwise resampling and percentile confidence intervals are undefined.

Source

Thrown at agent/src/quantlib/timeseries.py:802

    Args:
        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)),

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Check sample.size > 0 before calling.
  2. Debug why the filter/mask producing the data matched zero rows.
  3. Fall back to a default window or skip bootstrapping when data is unavailable.

Example fix

// before
bootstrap_statistic(returns[mask])  # mask matches nothing
// after
if len(returns[mask]) == 0:
    return None
bootstrap_statistic(returns[mask])
Defensive patterns

Strategy: validation

Validate before calling

import numpy as np
if np.asarray(data).size == 0:
    raise ValueError("no data to bootstrap")
bootstrap_statistic(data, ...)

Prevention

When it happens

Trigger: bootstrap_statistic([]) or passing a returns array filtered down to zero rows (e.g. returns[returns > 0.5] matching nothing); an empty pandas Series or column.

Common situations: Date-range or mask filters that match no rows, empty ticker histories, downstream of dropna removing everything.

Related errors


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