Class BlockBootstrap

java.lang.Object
com.quantfinlib.backtest.validation.BlockBootstrap

public final class BlockBootstrap extends Object
Stationary block bootstrap (Politis-Romano) — the confidence interval your backtest's Sharpe ratio deserves and almost never gets. A single historical path yields ONE Sharpe estimate; resampling the path in blocks yields its sampling DISTRIBUTION, and the honest question becomes "is the 5th percentile still positive?" rather than "is 1.2 a good number?".

Why BLOCKS: returns are autocorrelated (vol clusters, trends persist), and resampling single observations (an iid bootstrap) destroys that structure and UNDERSTATES the uncertainty — the classic way to be falsely confident. Blocks of geometric mean length L preserve local dependence; the stationary variant restarts blocks with probability 1/L and wraps circularly, so every resampled path has the full original length. Rule of thumb: L ≈ n^(1/3) (about 10 for a 1,000-day history).

Deterministic per seed (replayable), and honest about what it is NOT: the bootstrap resamples the history you had — it cannot manufacture regimes the sample never contained. Pair with SharpeValidation (multiple-testing haircut) and AlphaValidation (out-of-sample discipline); this class quantifies the sampling error that remains even for an honest, single-trial backtest. Research lane.

  • Method Summary

    Modifier and Type
    Method
    Description
    static double[]
    resample(double[] series, int meanBlockLength, Random rnd)
    One stationary-bootstrap path (circular, geometric blocks).
    static double[]
    sharpeSamples(double[] returns, int meanBlockLength, int resamples, int periodsPerYear, long seed)
    The bootstrap distribution of ANNUALIZED Sharpe, sorted ascending — read percentiles with MathUtils.percentileSorted.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • sharpeSamples

      public static double[] sharpeSamples(double[] returns, int meanBlockLength, int resamples, int periodsPerYear, long seed)
      The bootstrap distribution of ANNUALIZED Sharpe, sorted ascending — read percentiles with MathUtils.percentileSorted.
      Parameters:
      returns - per-period strategy returns, ≥ 50 finite
      meanBlockLength - geometric mean block length L, ≥ 1 (1 = iid bootstrap — only for demonstrating why you should not use it)
      resamples - bootstrap paths, ≥ 100
      periodsPerYear - annualization (252 for daily)
      seed - deterministic seed
    • resample

      public static double[] resample(double[] series, int meanBlockLength, Random rnd)
      One stationary-bootstrap path (circular, geometric blocks).