{"record":{"id":"375679e770942a01","repo":"HKUDS/Vibe-Trading","slug":"bootstrap-statistic-needs-confidence-in-0-1-go","errorCode":null,"errorMessage":"bootstrap_statistic needs confidence in (0, 1), got {confidence}","messagePattern":"bootstrap_statistic needs confidence in \\(0, 1\\), got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"agent/src/quantlib/timeseries.py","lineNumber":806,"sourceCode":"        n_bootstrap: Number of bootstrap resamples.\n        confidence: Confidence level in (0, 1), e.g. 0.95 for a 95% interval.\n        seed: Seed for the random generator; pass an int for reproducible output.\n\n    Returns:\n        Dict with keys ``point_estimate``, ``bootstrap_mean``, ``bootstrap_std``,\n        ``ci_lower``, ``ci_upper`` (all float) and ``confidence`` (float, echoed).\n\n    Raises:\n        ValueError: If ``data`` is empty, ``n_bootstrap`` is below 1, or\n            ``confidence`` is not strictly inside (0, 1).\n    \"\"\"\n    sample = np.asarray(data, dtype=float).ravel()\n    if sample.size == 0:\n        raise ValueError(\"bootstrap_statistic needs a non-empty sample\")\n    if n_bootstrap < 1:\n        raise ValueError(f\"bootstrap_statistic needs n_bootstrap >= 1, got {n_bootstrap}\")\n    if not 0.0 < confidence < 1.0:\n        raise ValueError(f\"bootstrap_statistic needs confidence in (0, 1), got {confidence}\")\n\n    rng = np.random.default_rng(seed)\n    n = sample.size\n    # Resample one draw at a time. Materialising the whole (n_bootstrap, n)\n    # index matrix would be ~160MB at the default 10000 draws over 2000 bars.\n    bootstrap_stats = np.empty(n_bootstrap, dtype=float)\n    for i in range(n_bootstrap):\n        bootstrap_stats[i] = float(statistic_func(sample[rng.integers(0, n, size=n)]))\n\n    alpha = 1 - confidence\n    return {\n        \"point_estimate\": float(statistic_func(sample)),\n        \"bootstrap_mean\": float(np.mean(bootstrap_stats)),\n        \"bootstrap_std\": float(np.std(bootstrap_stats)),\n        \"ci_lower\": float(np.percentile(bootstrap_stats, alpha / 2 * 100)),\n        \"ci_upper\": float(np.percentile(bootstrap_stats, (1 - alpha / 2) * 100)),\n        \"confidence\": confidence,\n    }","sourceCodeStart":788,"sourceCodeEnd":824,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/quantlib/timeseries.py#L788-L824","documentation":"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.","triggerScenarios":"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).","commonSituations":"Config files storing confidence as 95 or 0.95 inconsistently; UI dropdowns returning percentages; refactoring from APIs that take alpha.","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."],"exampleFix":"// before\nbootstrap_statistic(data, confidence=95)\n// after\nbootstrap_statistic(data, confidence=0.95)","handlingStrategy":"validation","validationCode":"if not 0.0 < confidence < 1.0:\n    if 0.0 < confidence <= 100.0:  # percentage form\n        confidence = confidence / 100.0\n    else:\n        raise ValueError(f\"confidence must be in (0,1), got {confidence}\")\nbootstrap_statistic(data, confidence=confidence)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on fractions (0.95) in configs, never percentages.","Document the (0,1) open interval at every API boundary that forwards confidence."],"tags":["python","statistics","bootstrap","confidence-level"],"backgroundTag":"confidence-level-out-of-range","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}