oss-backtest-kit 0.1.0__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. oss_backtest_kit-0.2.0/CHANGELOG.md +39 -0
  2. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/MANIFEST.in +3 -0
  3. {oss_backtest_kit-0.1.0/src/oss_backtest_kit.egg-info → oss_backtest_kit-0.2.0}/PKG-INFO +67 -17
  4. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/README.md +64 -16
  5. oss_backtest_kit-0.2.0/docs/SPEC_B.md +353 -0
  6. oss_backtest_kit-0.2.0/examples/checkup_demo.py +68 -0
  7. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/examples/quickstart.ipynb +2 -4
  8. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/pyproject.toml +3 -3
  9. oss_backtest_kit-0.2.0/src/oss_backtest_kit/__init__.py +6 -0
  10. oss_backtest_kit-0.2.0/src/oss_backtest_kit/_cli.py +135 -0
  11. oss_backtest_kit-0.2.0/src/oss_backtest_kit/_disclosure.py +62 -0
  12. oss_backtest_kit-0.2.0/src/oss_backtest_kit/checkup.py +392 -0
  13. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/src/oss_backtest_kit/data/archive.py +86 -18
  14. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/src/oss_backtest_kit/engine.py +4 -1
  15. oss_backtest_kit-0.2.0/src/oss_backtest_kit/loaders/__init__.py +12 -0
  16. oss_backtest_kit-0.2.0/src/oss_backtest_kit/loaders/_series.py +321 -0
  17. oss_backtest_kit-0.2.0/src/oss_backtest_kit/loaders/csvload.py +127 -0
  18. oss_backtest_kit-0.2.0/src/oss_backtest_kit/loaders/freqtrade_results.py +241 -0
  19. oss_backtest_kit-0.2.0/src/oss_backtest_kit/loaders/matrix.py +151 -0
  20. oss_backtest_kit-0.2.0/src/oss_backtest_kit/report.py +164 -0
  21. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/src/oss_backtest_kit/stats.py +137 -27
  22. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0/src/oss_backtest_kit.egg-info}/PKG-INFO +67 -17
  23. oss_backtest_kit-0.2.0/src/oss_backtest_kit.egg-info/SOURCES.txt +61 -0
  24. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/src/oss_backtest_kit.egg-info/requires.txt +2 -0
  25. oss_backtest_kit-0.2.0/tests/data/equity.csv +5 -0
  26. oss_backtest_kit-0.2.0/tests/data/freqtrade_2021_1_no_balance.json +1 -0
  27. oss_backtest_kit-0.2.0/tests/data/freqtrade_2022_1_spot.json +1 -0
  28. oss_backtest_kit-0.2.0/tests/data/freqtrade_2026_10_futures.json +1 -0
  29. oss_backtest_kit-0.2.0/tests/data/freqtrade_legacy_list.json +11 -0
  30. oss_backtest_kit-0.2.0/tests/data/freqtrade_multi.json +65 -0
  31. oss_backtest_kit-0.2.0/tests/data/freqtrade_single.json +57 -0
  32. oss_backtest_kit-0.2.0/tests/data/real_freqtrade_2026_10/backtest-result-2026-11-23_14-38-07.json +1 -0
  33. oss_backtest_kit-0.2.0/tests/data/real_freqtrade_2026_10/backtest-result-2026-11-23_14-38-07_RsiLikeStrategy.py +25 -0
  34. oss_backtest_kit-0.2.0/tests/data/real_freqtrade_2026_10/backtest-result-2026-11-23_14-38-07_RsiLikeStrategy_wallet.feather +0 -0
  35. oss_backtest_kit-0.2.0/tests/data/real_freqtrade_2026_10/backtest-result-2026-11-23_14-38-07_config.json +1 -0
  36. oss_backtest_kit-0.2.0/tests/data/real_freqtrade_2026_10/backtest-result-2026-11-23_14-38-07_market_change.feather +0 -0
  37. oss_backtest_kit-0.2.0/tests/data/real_freqtrade_2026_10_futures/backtest-result-2026-11-24_03-53-16.json +1 -0
  38. oss_backtest_kit-0.2.0/tests/data/real_freqtrade_2026_10_futures/backtest-result-2026-11-24_03-53-16_SmaCrossStrategy.py +31 -0
  39. oss_backtest_kit-0.2.0/tests/data/real_freqtrade_2026_10_futures/backtest-result-2026-11-24_03-53-16_SmaCrossStrategy_wallet.feather +0 -0
  40. oss_backtest_kit-0.2.0/tests/data/real_freqtrade_2026_10_futures/backtest-result-2026-11-24_03-53-16_config.json +1 -0
  41. oss_backtest_kit-0.2.0/tests/data/real_freqtrade_2026_10_futures/backtest-result-2026-11-24_03-53-16_market_change.feather +0 -0
  42. oss_backtest_kit-0.2.0/tests/data/returns.csv +5 -0
  43. oss_backtest_kit-0.2.0/tests/test_checkup.py +949 -0
  44. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/tests/test_data.py +126 -0
  45. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/tests/test_engine.py +11 -0
  46. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/tests/test_examples.py +22 -0
  47. oss_backtest_kit-0.2.0/tests/test_loaders.py +1041 -0
  48. oss_backtest_kit-0.2.0/tests/test_package.py +69 -0
  49. oss_backtest_kit-0.2.0/tests/test_report.py +199 -0
  50. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/tests/test_stats.py +141 -0
  51. oss_backtest_kit-0.1.0/CHANGELOG.md +0 -12
  52. oss_backtest_kit-0.1.0/src/oss_backtest_kit/__init__.py +0 -6
  53. oss_backtest_kit-0.1.0/src/oss_backtest_kit.egg-info/SOURCES.txt +0 -28
  54. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/LICENSE +0 -0
  55. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/docs/social_preview.png +0 -0
  56. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/examples/equity_psr_dsr.png +0 -0
  57. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/examples/equity_psr_dsr.py +0 -0
  58. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/examples/ma_crossover.py +0 -0
  59. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/setup.cfg +0 -0
  60. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/src/oss_backtest_kit/data/__init__.py +0 -0
  61. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/src/oss_backtest_kit/data/__main__.py +0 -0
  62. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/src/oss_backtest_kit/data/_http.py +0 -0
  63. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/src/oss_backtest_kit/data/check.py +0 -0
  64. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/src/oss_backtest_kit/data/rest_tail.py +0 -0
  65. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/src/oss_backtest_kit.egg-info/dependency_links.txt +0 -0
  66. {oss_backtest_kit-0.1.0 → oss_backtest_kit-0.2.0}/src/oss_backtest_kit.egg-info/top_level.txt +0 -0
@@ -0,0 +1,39 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ Overfitting checkup.
6
+
7
+ - `oss_backtest_kit.loaders`: read backtest results from other tools without installing them: freqtrade result files (`.json` / `.zip`), CSV (returns or equity curve), NumPy arrays and pandas Series (pandas stays optional), and a folder of results aligned into a return matrix. Unreadable fields raise a clear error; nothing is guessed.
8
+ - The freqtrade reader was checked on a real result written by freqtrade 2026.10 (its files are kept in `tests/data/real_freqtrade_2026_10/` and zipped by the test, provenance in `docs/SPEC_B.md`) and on a futures run with long and short trades (`tests/data/real_freqtrade_2026_10_futures/`); other freqtrade versions are read from their sources only.
9
+ - `oss_backtest_kit.checkup` and `python -m oss_backtest_kit.checkup`: annualised Sharpe, maximum drawdown, PSR, DSR (with the number of trials you give), effective number of trials, PBO (two or more results) and a circular block bootstrap interval, each with a verdict (pass / caution / fail) and one plain sentence. Short or sparse series are capped at caution; fewer than 30 observations are refused.
10
+ - Reports: Markdown with a disclaimer and the thresholds used, and an optional single-file HTML report (inline CSS, no scripts, no network).
11
+ - `stats.block_bootstrap_sharpe`: percentile interval of the annualised Sharpe ratio.
12
+ - Example `examples/checkup_demo.py` (synthetic data, offline: one overfitted and one robust group), README sections "Checkup" and the 30-second try-it moved to the top, and a written specification (`docs/SPEC_B.md`) with one test or more per item.
13
+ - Checkup: one result without `--trials` can no longer pass (the DSR line says it cannot be judged and the overall verdict is at most CAUTION); command-line switches `--strategy`, `--starting-balance`, `--time-col`, `--value-col`, `--kind` for the loader options, and loader errors name them; freqtrade formats documented per version (2021.1 to 2026.10) with test fixtures; PSR above 0.999 reads "more than 99.9%"; fewer backslashes in terminal output.
14
+ - Checkup grades stricter: an equity curve with unevenly spaced points (for example a 41-day jump between daily points) is now refused with an error, because PSR, DSR, PBO and the bootstrap assume equal periods. Add the missing dates, or pass `fill_flat=True` / `--fill-flat` if the account truly did not change on the missing days (the report says how many days were filled). Loaders now record where each series came from (`DailyReturns.spans`, `.basis`, `ReturnMatrix.sources`).
15
+ - Checkup grades stricter again: when more than 5% of the described result's returns were excluded by date alignment, no line can be a pass, and the report writes how many were excluded (before, after and inside the common window). A freqtrade report now says it was built from closed trades only (open positions are not marked to market).
16
+ - Checkup grades stricter: several results without `--trials` can no longer pass either (N is the number of results, only a lower bound, so the DSR line and the overall verdict are at most CAUTION); returns with persistent serial dependence are judged on the effective number of observations (`stats.autocorr_time`, new `n_obs` argument of `stats.psr` / `stats.dsr`), with longer bootstrap blocks, and too few effective observations cap every line at caution. The report adds a `Serial dependence` line.
17
+ - Checkup input and wording: `block` must be a whole number of at least 1 (a `CheckupError` otherwise), an array of more than two dimensions is a `CheckupError`, shown autocorrelation times and effective counts are rounded down so they never contradict the limit they are compared with, the PBO line says how many splits were left out because results tied, a long bootstrap block that leaves fewer than 4 blocks is named as such, and the error for unevenly spaced results in an already aligned matrix says to pass `fill_flat` when loading.
18
+ - Fix: the download manifest is now rewritten to a temporary file and replaced atomically, so a write error can no longer leave a partial last line.
19
+ - The sdist now includes the test data files.
20
+ - The `test` and `dev` extras now install pandas, so a clean `pip install .[test]` runs every test; the denied-word test compares hashes, so the packaged tests no longer carry readable internal names.
21
+ - Serial dependence notes show the rounded-down effective observation count and explain the formula minimum when the estimate is below three.
22
+
23
+ ### Fixes in the 0.1.0 API
24
+
25
+ - `stats.sharpe`, `stats.psr`, `stats.dsr`, and the bootstrap judge zero variance relative to the scale of the returns, so constant returns now give a Sharpe of 0 and a PSR of `NaN`, where 0.1.0 could give a Sharpe of about 5.75e15.
26
+ - `stats.max_drawdown` now works on log equity to avoid overflow on long series.
27
+ - `stats.pbo_cscv` now breaks in-sample Sharpe ties by return sum and skips splits that still tie, so it can return `None` even with two or more columns (0.1.0 returned `None` only with fewer than two), and the new `stats.pbo_cscv_detail` also returns the count of skipped splits.
28
+ - If an interrupted 0.1.0 download left a partial manifest row, `data` downloads the corresponding file again and `engine` raises an error if it reads the unfinished row.
29
+
30
+ ## 0.1.0
31
+
32
+ First packaged release.
33
+
34
+ - Multiple-testing statistics: Sharpe, PSR, DSR, PBO (CSCV), effective number of trials, circular block bootstrap, Wilson interval.
35
+ - Binance public archive download with SHA-256 verification, manifest, and gap / duplicate checks; REST helper that exports recent bars to separate CSV files.
36
+ - Config-driven perpetual-futures backtest engine: next-open fills, funding, `base` and `stressed` cost levels.
37
+ - Packaging metadata, README quick start, MIT licence.
38
+ - Examples: effect chart script with PSR / DSR computed by the library (`examples/equity_psr_dsr.py`, matplotlib via the optional `examples` extra), a Colab quick start notebook (`examples/quickstart.ipynb`), and a 1280x640 social preview card; smoke tests for the examples. Release workflow runs the offline tests first and requires the tag to equal `v` plus the pyproject version; CI runs on pushes to `main` and on pull requests. The test jobs install matplotlib and nbformat (in the `test` extra) so the example tests run instead of being skipped; the release workflow also refuses a tag whose commit is not on `main`. The full-dependency test jobs also fail if any test is skipped.
39
+ - Dependency floors (numpy 1.21.6, scipy 1.7.3), CI workflow for Python 3.9 to 3.13, tag-triggered release workflow (PyPI Trusted Publishing), sdist includes this changelog.
@@ -1,4 +1,7 @@
1
1
  include CHANGELOG.md
2
2
  include LICENSE
3
3
  recursive-include examples *.py *.png *.ipynb
4
+ recursive-include tests *.py *.csv *.json *.feather
5
+ include docs/SPEC_B.md
4
6
  include docs/social_preview.png
7
+ prune tests/audit_ce
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oss-backtest-kit
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: A small, generic toolkit for crypto strategy research and backtest statistics.
5
5
  License-Expression: MIT
6
6
  Project-URL: Homepage, https://github.com/ww7411/oss-backtest-kit
@@ -29,12 +29,14 @@ Provides-Extra: test
29
29
  Requires-Dist: pytest; extra == "test"
30
30
  Requires-Dist: matplotlib; extra == "test"
31
31
  Requires-Dist: nbformat; extra == "test"
32
+ Requires-Dist: pandas>=1.3; extra == "test"
32
33
  Provides-Extra: examples
33
34
  Requires-Dist: matplotlib; extra == "examples"
34
35
  Provides-Extra: dev
35
36
  Requires-Dist: pytest; extra == "dev"
36
37
  Requires-Dist: matplotlib; extra == "dev"
37
38
  Requires-Dist: nbformat; extra == "dev"
39
+ Requires-Dist: pandas>=1.3; extra == "dev"
38
40
  Dynamic: license-file
39
41
 
40
42
  # oss-backtest-kit
@@ -45,7 +47,25 @@ Dynamic: license-file
45
47
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ww7411/oss-backtest-kit/blob/main/LICENSE)
46
48
  [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ww7411/oss-backtest-kit/blob/main/examples/quickstart.ipynb)
47
49
 
48
- **Is your backtest real, or did you just try enough ideas until one looked good?** A small, honest toolkit for crypto futures research: verified public data, a no-look-ahead backtest engine, and the statistics that tell you how much of your Sharpe ratio is luck.
50
+ **Run an overfitting checkup on a backtest you already have (freqtrade result or CSV, one command).** Is your backtest real, or did you just try enough ideas until one looked good? A small, honest toolkit for crypto futures research: verified public data, a no-look-ahead backtest engine, and the statistics that tell you how much of your Sharpe ratio is luck.
51
+
52
+ ## Try it in 30 seconds
53
+
54
+ Check a backtest you already have (a freqtrade result `.zip` / `.json`, a CSV of returns or equity, or a folder of results; nothing is downloaded and no account is needed):
55
+
56
+ ```
57
+ pip install oss-backtest-kit
58
+ python -m oss_backtest_kit.checkup <your result file or folder> --trials N
59
+ ```
60
+
61
+ No result at hand? The statistics also work on any array of returns:
62
+
63
+ ```
64
+ pip install oss-backtest-kit
65
+ python -c "import numpy as np; from oss_backtest_kit import stats; r = np.random.default_rng(0).normal(0.0005, 0.01, 500); print('PSR', stats.psr(r)); print('DSR', stats.dsr(r, n_trials=20, trial_sharpes=[0.01, 0.03, 0.02])[0])"
66
+ ```
67
+
68
+ The second number is lower than the first: the Deflated Sharpe Ratio charges you for the 20 variants you tried.
49
69
 
50
70
  ![Equity curve of the best of 9 variants with PSR and DSR computed by the library; synthetic data, not a trading result](https://raw.githubusercontent.com/ww7411/oss-backtest-kit/main/examples/equity_psr_dsr.png)
51
71
 
@@ -57,7 +77,7 @@ Dynamic: license-file
57
77
  - **Data you can trust.** Every Binance public archive file is checked against its published SHA-256 before it is saved; a manifest records what you have; gaps and duplicate bars are reported, not silently filled.
58
78
  - **No look-ahead by design.** Your strategy is called at a bar's close and sees only bars up to that point; orders fill at the next bar's open with slippage and fees.
59
79
  - **Costs that bite.** Perpetual-futures funding is included, and a `stressed` cost level lets you check whether an edge survives worse fills.
60
- - **Small and readable.** Pure Python with only numpy and scipy; 62 offline tests; no account, API key or paid data needed.
80
+ - **Small and readable.** Pure Python with only numpy and scipy; offline tests only; no account, API key or paid data needed.
61
81
  - **MIT licensed** code (the market data has its own terms; see below).
62
82
 
63
83
  ## Who it is for
@@ -66,11 +86,12 @@ Individual researchers and students who write their own strategies in Python and
66
86
 
67
87
  ## What is inside
68
88
 
69
- A small research toolkit for crypto strategies, in three parts:
89
+ A small research toolkit for crypto strategies, in four parts:
70
90
 
71
91
  1. **Multiple-testing statistics** (`oss_backtest_kit.stats`): Sharpe, Probabilistic Sharpe Ratio (PSR), Deflated Sharpe Ratio (DSR), Probability of Backtest Overfitting (CSCV), effective number of trials, circular block bootstrap, Wilson intervals.
72
92
  2. **Public data download and verification** (`oss_backtest_kit.data`): fetches Binance public archive files, verifies each against its published SHA-256 checksum, records a manifest, and checks bar continuity. A REST helper exports the most recent days as separate CSV files (not loaded by the engine).
73
93
  3. **A simple, config-driven backtest engine** (`oss_backtest_kit.engine`) for a portfolio of perpetual futures, with funding and a two-level cost model.
94
+ 4. **An overfitting checkup** (`oss_backtest_kit.checkup`, with readers in `oss_backtest_kit.loaders`): reads backtest results from other tools (freqtrade result files, CSV, arrays) and writes a Markdown or HTML report.
74
95
 
75
96
  ## DISCLAIMER
76
97
 
@@ -78,18 +99,7 @@ This project is for **research and education only**. It is **not investment advi
78
99
 
79
100
  ## Status
80
101
 
81
- Early release (version 0.1.0). The project is maintained: bug reports and pull requests are welcome. The API may still change before 1.0; see [CHANGELOG.md](https://github.com/ww7411/oss-backtest-kit/blob/main/CHANGELOG.md).
82
-
83
- ## Try it in 30 seconds
84
-
85
- No data download and no account needed:
86
-
87
- ```
88
- pip install oss-backtest-kit
89
- python -c "import numpy as np; from oss_backtest_kit import stats; r = np.random.default_rng(0).normal(0.0005, 0.01, 500); print('PSR', stats.psr(r)); print('DSR', stats.dsr(r, n_trials=20, trial_sharpes=[0.01, 0.03, 0.02])[0])"
90
- ```
91
-
92
- The second number is lower than the first: the Deflated Sharpe Ratio charges you for the 20 variants you tried.
102
+ Early release (version 0.2.0). The project is maintained: bug reports and pull requests are welcome. The API may still change before 1.0; see [CHANGELOG.md](https://github.com/ww7411/oss-backtest-kit/blob/main/CHANGELOG.md).
93
103
 
94
104
  ## Requirements and install
95
105
 
@@ -161,6 +171,44 @@ result = run_backtest(data, strategy, cfg, cost_level="stressed")
161
171
  print(result.summary()) # result.returns feeds stats.psr / stats.dsr
162
172
  ```
163
173
 
174
+ ## Checkup: is this backtest overfitted?
175
+
176
+ The checkup reads the result of a backtest you already ran (in this kit or in another tool) and answers one question: how much of the result could be luck from trying many versions. It needs only numpy and scipy, runs offline and does not install or import the other tool.
177
+
178
+ Try it on synthetic data first (one overfitted group, one robust group; nothing is downloaded):
179
+
180
+ ```
181
+ python3 examples/checkup_demo.py
182
+ ```
183
+
184
+ On your own results, from the command line:
185
+
186
+ ```
187
+ python -m oss_backtest_kit.checkup <result file or folder> --trials N [--report out.md] [--html out.html]
188
+ ```
189
+
190
+ If the reader asks for more information, give it with a switch: `--strategy NAME` (a freqtrade file that holds several strategies), `--starting-balance X` (a freqtrade file that does not state the starting balance), and for CSV files `--time-col NAME`, `--value-col NAME` and `--kind returns|equity`. A folder reads every strategy of every file in it.
191
+
192
+ - The input is a freqtrade backtest result (`.json` or `.zip`; supported from the format documentation and test fixtures for freqtrade 2021.1 to 2026.10; verified on real results of one version only, freqtrade 2026.10: one spot run and one futures run with long and short trades (`tests/data/real_freqtrade_2026_10/`, `tests/data/real_freqtrade_2026_10_futures/`); see `docs/SPEC_B.md` for what was and was not checked), a CSV with a date column and a return column (or an equity curve), or a folder holding one such file per parameter set. In Python you can also pass a NumPy array or a pandas Series (pandas is optional and never imported by the kit).
193
+ - `--trials N` is how many versions you tried in total, **including the ones you did not save**. If you leave it out, the number of result files is used, and the report says so. A too-small N makes the Deflated Sharpe Ratio too kind. With one result and no `--trials`, nothing can be deflated, so the DSR line says it cannot be judged and the overall verdict is at most CAUTION; pass `--trials 1` only if that really was the only version you tried. With several results and no `--trials`, the number of results is only a lower bound, so the overall verdict is also at most CAUTION.
194
+ - Returns that depend on each other from day to day (long runs of similar values) carry less evidence than their row count suggests: the report estimates how many rows make one independent observation (`Serial dependence`) and judges PSR, DSR, the sample-size rule and the bootstrap on that effective count.
195
+ - With two or more results the report also gives PBO (Probability of Backtest Overfitting), and the Sharpe, PSR, DSR and bootstrap lines describe the result with the highest Sharpe (or the one you name with `--select`).
196
+ - Exit status 0 means the checkup ran (whatever the verdict); 2 means the input could not be checked, and the message on stderr says why.
197
+
198
+ How to read the report. Each line has a verdict in words: PASS, CAUTION, FAIL (or INFO for facts such as the drawdown) and one sentence. The thresholds are printed at the bottom of every report. Read the DSR and PBO lines first when you tried several versions: PSR and the bootstrap interval are not corrected for picking the best one. Fewer than 180 observations can never pass, and fewer than 30 are refused. The report also lists notes, for example when the data is not daily or very sparse.
199
+
200
+ In Python:
201
+
202
+ ```python
203
+ from oss_backtest_kit.checkup import checkup
204
+
205
+ report = checkup("./results_folder", n_trials=25)
206
+ print(report.overall) # "pass", "caution" or "fail": the worst line
207
+ print(report.to_markdown()) # or report.to_html() for one self-contained file
208
+ ```
209
+
210
+ **The checkup only lowers the risk of shipping an overfitted backtest. It cannot show that a strategy will make money**: a result can pass every line and still lose money live, and the thresholds are conventions, not guarantees. See the disclaimer below.
211
+
164
212
  ## Modules
165
213
 
166
214
  | Module | Purpose |
@@ -170,6 +218,8 @@ print(result.summary()) # result.returns feeds stats.psr / stats.dsr
170
218
  | `data.rest_tail` | Recent closed bars and funding from public REST endpoints |
171
219
  | `data.check` | Manifest SHA check, gap and duplicate detection |
172
220
  | `engine` | Config, market data loader, backtest loop, result summary |
221
+ | `loaders` | Read backtest results (freqtrade result files, CSV, arrays, a folder of results) as daily returns |
222
+ | `checkup` | Overfitting checkup and its command line; `report` writes the Markdown / HTML report |
173
223
 
174
224
  The data client allows a single host per task, uses https only, ignores environment proxy settings, refuses redirects, bounds response size and time, and stops when free disk space is low.
175
225
 
@@ -192,7 +242,7 @@ All tests run offline with synthetic data and fake network responses.
192
242
 
193
243
  ## Data terms
194
244
 
195
- This kit ships **code only and never any data**. It downloads from two different sources, which have **different terms**. Nothing here is legal advice; read the current terms yourself before downloading, using or sharing any data.
245
+ This kit ships **code only and never any market data** (no candles, no ticks). One exception to note: `tests/data/real_freqtrade_2026_10/` holds the result files of one small freqtrade backtest used as a test (trade records of a demonstration strategy, computed from public exchange candles, plus a market-change and a wallet series derived from them; not the raw candles). Delete that folder if you redistribute the package and are unsure about it. It downloads from two different sources, which have **different terms**. Nothing here is legal advice; read the current terms yourself before downloading, using or sharing any data.
196
246
 
197
247
  **1. Archive files from `data.binance.vision`** (`archive` subcommand). These are described in the `binance/binance-public-data` repository (https://github.com/binance/binance-public-data), whose `TERMS_AND_CONDITIONS.md` states a CC BY-NC-SA 4.0 licence (https://creativecommons.org/licenses/by-nc-sa/4.0/). As we read that licence, it means:
198
248
 
@@ -6,7 +6,25 @@
6
6
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ww7411/oss-backtest-kit/blob/main/LICENSE)
7
7
  [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ww7411/oss-backtest-kit/blob/main/examples/quickstart.ipynb)
8
8
 
9
- **Is your backtest real, or did you just try enough ideas until one looked good?** A small, honest toolkit for crypto futures research: verified public data, a no-look-ahead backtest engine, and the statistics that tell you how much of your Sharpe ratio is luck.
9
+ **Run an overfitting checkup on a backtest you already have (freqtrade result or CSV, one command).** Is your backtest real, or did you just try enough ideas until one looked good? A small, honest toolkit for crypto futures research: verified public data, a no-look-ahead backtest engine, and the statistics that tell you how much of your Sharpe ratio is luck.
10
+
11
+ ## Try it in 30 seconds
12
+
13
+ Check a backtest you already have (a freqtrade result `.zip` / `.json`, a CSV of returns or equity, or a folder of results; nothing is downloaded and no account is needed):
14
+
15
+ ```
16
+ pip install oss-backtest-kit
17
+ python -m oss_backtest_kit.checkup <your result file or folder> --trials N
18
+ ```
19
+
20
+ No result at hand? The statistics also work on any array of returns:
21
+
22
+ ```
23
+ pip install oss-backtest-kit
24
+ python -c "import numpy as np; from oss_backtest_kit import stats; r = np.random.default_rng(0).normal(0.0005, 0.01, 500); print('PSR', stats.psr(r)); print('DSR', stats.dsr(r, n_trials=20, trial_sharpes=[0.01, 0.03, 0.02])[0])"
25
+ ```
26
+
27
+ The second number is lower than the first: the Deflated Sharpe Ratio charges you for the 20 variants you tried.
10
28
 
11
29
  ![Equity curve of the best of 9 variants with PSR and DSR computed by the library; synthetic data, not a trading result](https://raw.githubusercontent.com/ww7411/oss-backtest-kit/main/examples/equity_psr_dsr.png)
12
30
 
@@ -18,7 +36,7 @@
18
36
  - **Data you can trust.** Every Binance public archive file is checked against its published SHA-256 before it is saved; a manifest records what you have; gaps and duplicate bars are reported, not silently filled.
19
37
  - **No look-ahead by design.** Your strategy is called at a bar's close and sees only bars up to that point; orders fill at the next bar's open with slippage and fees.
20
38
  - **Costs that bite.** Perpetual-futures funding is included, and a `stressed` cost level lets you check whether an edge survives worse fills.
21
- - **Small and readable.** Pure Python with only numpy and scipy; 62 offline tests; no account, API key or paid data needed.
39
+ - **Small and readable.** Pure Python with only numpy and scipy; offline tests only; no account, API key or paid data needed.
22
40
  - **MIT licensed** code (the market data has its own terms; see below).
23
41
 
24
42
  ## Who it is for
@@ -27,11 +45,12 @@ Individual researchers and students who write their own strategies in Python and
27
45
 
28
46
  ## What is inside
29
47
 
30
- A small research toolkit for crypto strategies, in three parts:
48
+ A small research toolkit for crypto strategies, in four parts:
31
49
 
32
50
  1. **Multiple-testing statistics** (`oss_backtest_kit.stats`): Sharpe, Probabilistic Sharpe Ratio (PSR), Deflated Sharpe Ratio (DSR), Probability of Backtest Overfitting (CSCV), effective number of trials, circular block bootstrap, Wilson intervals.
33
51
  2. **Public data download and verification** (`oss_backtest_kit.data`): fetches Binance public archive files, verifies each against its published SHA-256 checksum, records a manifest, and checks bar continuity. A REST helper exports the most recent days as separate CSV files (not loaded by the engine).
34
52
  3. **A simple, config-driven backtest engine** (`oss_backtest_kit.engine`) for a portfolio of perpetual futures, with funding and a two-level cost model.
53
+ 4. **An overfitting checkup** (`oss_backtest_kit.checkup`, with readers in `oss_backtest_kit.loaders`): reads backtest results from other tools (freqtrade result files, CSV, arrays) and writes a Markdown or HTML report.
35
54
 
36
55
  ## DISCLAIMER
37
56
 
@@ -39,18 +58,7 @@ This project is for **research and education only**. It is **not investment advi
39
58
 
40
59
  ## Status
41
60
 
42
- Early release (version 0.1.0). The project is maintained: bug reports and pull requests are welcome. The API may still change before 1.0; see [CHANGELOG.md](https://github.com/ww7411/oss-backtest-kit/blob/main/CHANGELOG.md).
43
-
44
- ## Try it in 30 seconds
45
-
46
- No data download and no account needed:
47
-
48
- ```
49
- pip install oss-backtest-kit
50
- python -c "import numpy as np; from oss_backtest_kit import stats; r = np.random.default_rng(0).normal(0.0005, 0.01, 500); print('PSR', stats.psr(r)); print('DSR', stats.dsr(r, n_trials=20, trial_sharpes=[0.01, 0.03, 0.02])[0])"
51
- ```
52
-
53
- The second number is lower than the first: the Deflated Sharpe Ratio charges you for the 20 variants you tried.
61
+ Early release (version 0.2.0). The project is maintained: bug reports and pull requests are welcome. The API may still change before 1.0; see [CHANGELOG.md](https://github.com/ww7411/oss-backtest-kit/blob/main/CHANGELOG.md).
54
62
 
55
63
  ## Requirements and install
56
64
 
@@ -122,6 +130,44 @@ result = run_backtest(data, strategy, cfg, cost_level="stressed")
122
130
  print(result.summary()) # result.returns feeds stats.psr / stats.dsr
123
131
  ```
124
132
 
133
+ ## Checkup: is this backtest overfitted?
134
+
135
+ The checkup reads the result of a backtest you already ran (in this kit or in another tool) and answers one question: how much of the result could be luck from trying many versions. It needs only numpy and scipy, runs offline and does not install or import the other tool.
136
+
137
+ Try it on synthetic data first (one overfitted group, one robust group; nothing is downloaded):
138
+
139
+ ```
140
+ python3 examples/checkup_demo.py
141
+ ```
142
+
143
+ On your own results, from the command line:
144
+
145
+ ```
146
+ python -m oss_backtest_kit.checkup <result file or folder> --trials N [--report out.md] [--html out.html]
147
+ ```
148
+
149
+ If the reader asks for more information, give it with a switch: `--strategy NAME` (a freqtrade file that holds several strategies), `--starting-balance X` (a freqtrade file that does not state the starting balance), and for CSV files `--time-col NAME`, `--value-col NAME` and `--kind returns|equity`. A folder reads every strategy of every file in it.
150
+
151
+ - The input is a freqtrade backtest result (`.json` or `.zip`; supported from the format documentation and test fixtures for freqtrade 2021.1 to 2026.10; verified on real results of one version only, freqtrade 2026.10: one spot run and one futures run with long and short trades (`tests/data/real_freqtrade_2026_10/`, `tests/data/real_freqtrade_2026_10_futures/`); see `docs/SPEC_B.md` for what was and was not checked), a CSV with a date column and a return column (or an equity curve), or a folder holding one such file per parameter set. In Python you can also pass a NumPy array or a pandas Series (pandas is optional and never imported by the kit).
152
+ - `--trials N` is how many versions you tried in total, **including the ones you did not save**. If you leave it out, the number of result files is used, and the report says so. A too-small N makes the Deflated Sharpe Ratio too kind. With one result and no `--trials`, nothing can be deflated, so the DSR line says it cannot be judged and the overall verdict is at most CAUTION; pass `--trials 1` only if that really was the only version you tried. With several results and no `--trials`, the number of results is only a lower bound, so the overall verdict is also at most CAUTION.
153
+ - Returns that depend on each other from day to day (long runs of similar values) carry less evidence than their row count suggests: the report estimates how many rows make one independent observation (`Serial dependence`) and judges PSR, DSR, the sample-size rule and the bootstrap on that effective count.
154
+ - With two or more results the report also gives PBO (Probability of Backtest Overfitting), and the Sharpe, PSR, DSR and bootstrap lines describe the result with the highest Sharpe (or the one you name with `--select`).
155
+ - Exit status 0 means the checkup ran (whatever the verdict); 2 means the input could not be checked, and the message on stderr says why.
156
+
157
+ How to read the report. Each line has a verdict in words: PASS, CAUTION, FAIL (or INFO for facts such as the drawdown) and one sentence. The thresholds are printed at the bottom of every report. Read the DSR and PBO lines first when you tried several versions: PSR and the bootstrap interval are not corrected for picking the best one. Fewer than 180 observations can never pass, and fewer than 30 are refused. The report also lists notes, for example when the data is not daily or very sparse.
158
+
159
+ In Python:
160
+
161
+ ```python
162
+ from oss_backtest_kit.checkup import checkup
163
+
164
+ report = checkup("./results_folder", n_trials=25)
165
+ print(report.overall) # "pass", "caution" or "fail": the worst line
166
+ print(report.to_markdown()) # or report.to_html() for one self-contained file
167
+ ```
168
+
169
+ **The checkup only lowers the risk of shipping an overfitted backtest. It cannot show that a strategy will make money**: a result can pass every line and still lose money live, and the thresholds are conventions, not guarantees. See the disclaimer below.
170
+
125
171
  ## Modules
126
172
 
127
173
  | Module | Purpose |
@@ -131,6 +177,8 @@ print(result.summary()) # result.returns feeds stats.psr / stats.dsr
131
177
  | `data.rest_tail` | Recent closed bars and funding from public REST endpoints |
132
178
  | `data.check` | Manifest SHA check, gap and duplicate detection |
133
179
  | `engine` | Config, market data loader, backtest loop, result summary |
180
+ | `loaders` | Read backtest results (freqtrade result files, CSV, arrays, a folder of results) as daily returns |
181
+ | `checkup` | Overfitting checkup and its command line; `report` writes the Markdown / HTML report |
134
182
 
135
183
  The data client allows a single host per task, uses https only, ignores environment proxy settings, refuses redirects, bounds response size and time, and stops when free disk space is low.
136
184
 
@@ -153,7 +201,7 @@ All tests run offline with synthetic data and fake network responses.
153
201
 
154
202
  ## Data terms
155
203
 
156
- This kit ships **code only and never any data**. It downloads from two different sources, which have **different terms**. Nothing here is legal advice; read the current terms yourself before downloading, using or sharing any data.
204
+ This kit ships **code only and never any market data** (no candles, no ticks). One exception to note: `tests/data/real_freqtrade_2026_10/` holds the result files of one small freqtrade backtest used as a test (trade records of a demonstration strategy, computed from public exchange candles, plus a market-change and a wallet series derived from them; not the raw candles). Delete that folder if you redistribute the package and are unsure about it. It downloads from two different sources, which have **different terms**. Nothing here is legal advice; read the current terms yourself before downloading, using or sharing any data.
157
205
 
158
206
  **1. Archive files from `data.binance.vision`** (`archive` subcommand). These are described in the `binance/binance-public-data` repository (https://github.com/binance/binance-public-data), whose `TERMS_AND_CONDITIONS.md` states a CC BY-NC-SA 4.0 licence (https://creativecommons.org/licenses/by-nc-sa/4.0/). As we read that licence, it means:
159
207