feat: add block-bootstrap backtest intervals

This commit is contained in:
Hermes Agent
2026-07-26 23:05:05 +00:00
parent a54dec357f
commit 1f754ed85d
2 changed files with 119 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
from backtesting import statistics
def test_moving_block_bootstrap_is_deterministic_and_handles_constant_series():
first = statistics.moving_block_bootstrap_ci(
[12.5] * 120,
block_size=15,
n_resamples=200,
seed=7,
)
second = statistics.moving_block_bootstrap_ci(
[12.5] * 120,
block_size=15,
n_resamples=200,
seed=7,
)
assert first == second
assert first == {"estimate": 12.5, "ci_low": 12.5, "ci_high": 12.5, "n": 120}
def test_summarize_returns_reports_observations_and_block_bootstrap_interval():
summary = statistics.summarize_returns(
[10.0, -5.0, 20.0, -10.0],
block_size=2,
n_resamples=200,
seed=3,
)
assert summary["n"] == 4
assert summary["mean"] == 3.75
assert summary["median"] == 2.5
assert summary["win_rate"] == 50.0
assert summary["mean_ci_low"] <= summary["mean"] <= summary["mean_ci_high"]