overfit-audit 0.1.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.
- overfit_audit-0.1.0/.github/workflows/ci.yml +25 -0
- overfit_audit-0.1.0/.github/workflows/release.yml +58 -0
- overfit_audit-0.1.0/.gitignore +14 -0
- overfit_audit-0.1.0/AGENTS.md +27 -0
- overfit_audit-0.1.0/CHANGELOG.md +44 -0
- overfit_audit-0.1.0/CITATION.cff +104 -0
- overfit_audit-0.1.0/CONTRIBUTING.md +65 -0
- overfit_audit-0.1.0/LICENSE +21 -0
- overfit_audit-0.1.0/PKG-INFO +192 -0
- overfit_audit-0.1.0/README.md +161 -0
- overfit_audit-0.1.0/docs/SPEC.md +276 -0
- overfit_audit-0.1.0/docs/bootstrap.md +106 -0
- overfit_audit-0.1.0/docs/freqtrade.md +107 -0
- overfit_audit-0.1.0/docs/lookahead.md +84 -0
- overfit_audit-0.1.0/docs/nulls.md +104 -0
- overfit_audit-0.1.0/docs/pbo.md +62 -0
- overfit_audit-0.1.0/docs/report.md +101 -0
- overfit_audit-0.1.0/docs/sharpe.md +102 -0
- overfit_audit-0.1.0/docs/splits.md +71 -0
- overfit_audit-0.1.0/docs/trials.md +70 -0
- overfit_audit-0.1.0/examples/quickstart.py +51 -0
- overfit_audit-0.1.0/pyproject.toml +47 -0
- overfit_audit-0.1.0/src/overfit_audit/__init__.py +29 -0
- overfit_audit-0.1.0/src/overfit_audit/_resample.py +44 -0
- overfit_audit-0.1.0/src/overfit_audit/_validation.py +59 -0
- overfit_audit-0.1.0/src/overfit_audit/adapters/__init__.py +5 -0
- overfit_audit-0.1.0/src/overfit_audit/adapters/freqtrade.py +431 -0
- overfit_audit-0.1.0/src/overfit_audit/bootstrap.py +482 -0
- overfit_audit-0.1.0/src/overfit_audit/lookahead.py +425 -0
- overfit_audit-0.1.0/src/overfit_audit/nulls.py +302 -0
- overfit_audit-0.1.0/src/overfit_audit/pbo.py +278 -0
- overfit_audit-0.1.0/src/overfit_audit/report.py +612 -0
- overfit_audit-0.1.0/src/overfit_audit/sharpe.py +373 -0
- overfit_audit-0.1.0/src/overfit_audit/splits.py +263 -0
- overfit_audit-0.1.0/src/overfit_audit/trials.py +168 -0
- overfit_audit-0.1.0/tests/fixtures/freqtrade/.last_result.json +1 -0
- overfit_audit-0.1.0/tests/fixtures/freqtrade/backtest-result-2026-01-15_00-00-00.json +212 -0
- overfit_audit-0.1.0/tests/fixtures/freqtrade/backtest-result-2026-01-15_00-00-00.zip +0 -0
- overfit_audit-0.1.0/tests/fixtures/freqtrade/strategy_SyntheticTrend_2026-01-15_00-00-00.fthypt +4 -0
- overfit_audit-0.1.0/tests/test_bootstrap.py +241 -0
- overfit_audit-0.1.0/tests/test_freqtrade.py +207 -0
- overfit_audit-0.1.0/tests/test_lookahead.py +208 -0
- overfit_audit-0.1.0/tests/test_nulls.py +179 -0
- overfit_audit-0.1.0/tests/test_pbo.py +171 -0
- overfit_audit-0.1.0/tests/test_report.py +181 -0
- overfit_audit-0.1.0/tests/test_resample.py +40 -0
- overfit_audit-0.1.0/tests/test_sharpe.py +259 -0
- overfit_audit-0.1.0/tests/test_splits.py +124 -0
- overfit_audit-0.1.0/tests/test_trials.py +144 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
test:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
python-version: ["3.10", "3.13"]
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
- uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
- run: pip install -e ".[dev]"
|
|
24
|
+
- run: ruff check .
|
|
25
|
+
- run: pytest -q
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
# Publishes to PyPI when a version tag (for example v0.1.0) is pushed.
|
|
4
|
+
# Uses PyPI Trusted Publishing (OpenID Connect): no API token is stored
|
|
5
|
+
# in this repository.
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
push:
|
|
9
|
+
tags: ["v*"]
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
build:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- uses: actions/setup-python@v5
|
|
20
|
+
with:
|
|
21
|
+
python-version: "3.13"
|
|
22
|
+
- name: Check that the tag matches the package version
|
|
23
|
+
run: |
|
|
24
|
+
version=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
|
|
25
|
+
if [ "v${version}" != "${GITHUB_REF_NAME}" ]; then
|
|
26
|
+
echo "Tag ${GITHUB_REF_NAME} does not match package version ${version}" >&2
|
|
27
|
+
exit 1
|
|
28
|
+
fi
|
|
29
|
+
- run: python -m pip install --upgrade build twine
|
|
30
|
+
- run: python -m build
|
|
31
|
+
- run: python -m twine check --strict dist/*
|
|
32
|
+
- name: Test the built wheel outside the source tree
|
|
33
|
+
run: |
|
|
34
|
+
python -m venv /tmp/wheel-env
|
|
35
|
+
/tmp/wheel-env/bin/pip install dist/*.whl "pytest>=7" "arch>=7"
|
|
36
|
+
cd /tmp
|
|
37
|
+
/tmp/wheel-env/bin/python -c "import overfit_audit, sys; assert overfit_audit.__file__.startswith(sys.prefix), overfit_audit.__file__"
|
|
38
|
+
/tmp/wheel-env/bin/python -m pytest -q -p no:cacheprovider "${GITHUB_WORKSPACE}/tests"
|
|
39
|
+
- uses: actions/upload-artifact@v4
|
|
40
|
+
with:
|
|
41
|
+
name: dist
|
|
42
|
+
path: dist/
|
|
43
|
+
if-no-files-found: error
|
|
44
|
+
|
|
45
|
+
publish:
|
|
46
|
+
needs: build
|
|
47
|
+
runs-on: ubuntu-latest
|
|
48
|
+
environment:
|
|
49
|
+
name: pypi
|
|
50
|
+
url: https://pypi.org/project/overfit-audit/
|
|
51
|
+
permissions:
|
|
52
|
+
id-token: write
|
|
53
|
+
steps:
|
|
54
|
+
- uses: actions/download-artifact@v4
|
|
55
|
+
with:
|
|
56
|
+
name: dist
|
|
57
|
+
path: dist/
|
|
58
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Instructions for coding agents
|
|
2
|
+
|
|
3
|
+
These rules apply to every change in this repository.
|
|
4
|
+
|
|
5
|
+
1. **English only.** All code, comments, docstrings, docs, test names, commit
|
|
6
|
+
messages and PR text are in English. Do not add text in any other language.
|
|
7
|
+
2. **Commit identity.** Before the first commit run
|
|
8
|
+
`git config user.name "javadzareei"` and
|
|
9
|
+
`git config user.email "55209479+javadzareei@users.noreply.github.com"`.
|
|
10
|
+
Never commit with any other e-mail address.
|
|
11
|
+
3. **Scope.** Follow `docs/SPEC.md`. Do not add features, modules or runtime
|
|
12
|
+
dependencies that it does not list. Runtime dependencies: numpy, scipy,
|
|
13
|
+
pandas. `arch` is allowed in tests only.
|
|
14
|
+
4. **Core modules.** Do not edit `src/overfit_audit/sharpe.py`,
|
|
15
|
+
`src/overfit_audit/_validation.py`, `src/overfit_audit/_resample.py`,
|
|
16
|
+
`tests/test_sharpe.py` or `tests/test_resample.py` unless the task says so;
|
|
17
|
+
import from them.
|
|
18
|
+
5. **No private material.** No data files except tiny synthetic fixtures, no
|
|
19
|
+
secrets, no network access in code or tests, no references to private
|
|
20
|
+
projects, exchanges' private APIs or trading strategies beyond generic
|
|
21
|
+
examples on synthetic data.
|
|
22
|
+
6. **Implement from the papers** cited in `docs/SPEC.md`. Do not copy code from
|
|
23
|
+
other projects. Cite the paper in each public function's docstring.
|
|
24
|
+
7. **Quality gates.** Every public function has type hints, a NumPy-style
|
|
25
|
+
docstring and tests. Before finishing run
|
|
26
|
+
`pip install -e ".[dev]" && ruff check . && pytest -q` and keep them green.
|
|
27
|
+
Report the exact commands and their output in the PR description.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `overfit-audit` are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-12-05
|
|
11
|
+
|
|
12
|
+
First public release.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- `overfit_audit.sharpe`: per-period Sharpe ratio, sample moments (Pearson
|
|
17
|
+
kurtosis), Mertens standard error, Probabilistic Sharpe Ratio (PSR), Minimum
|
|
18
|
+
Track Record Length (MinTRL), exact and paper-approximate expected maximum
|
|
19
|
+
standard normal, Deflated Sharpe Ratio (DSR), and `annualise`/`deannualise`.
|
|
20
|
+
- `overfit_audit.trials`: `trial_sharpes` and `effective_n` (eigenvalue
|
|
21
|
+
participation ratio and complete-linkage correlation clustering).
|
|
22
|
+
- `overfit_audit.pbo`: vectorised combinatorially symmetric cross-validation
|
|
23
|
+
(`cscv`) returning PBO, rank logits, degradation fit, and out-of-sample loss
|
|
24
|
+
probability (`PBOResult`).
|
|
25
|
+
- `overfit_audit.bootstrap`: Politis-White-Patton `optimal_block_length`,
|
|
26
|
+
stationary bootstrap resampling, White's `reality_check`, Hansen's `spa`,
|
|
27
|
+
and Romano-Wolf `stepm`.
|
|
28
|
+
- `overfit_audit.splits`: scikit-learn compatible `WalkForward` (rolling or
|
|
29
|
+
anchored with purge) and `CombinatorialPurgedKFold` (with purge, embargo, and
|
|
30
|
+
`paths()`).
|
|
31
|
+
- `overfit_audit.lookahead`: `check_truncation`, `check_future_perturbation`,
|
|
32
|
+
and `check_warmup` signal audits returning `LookaheadReport`.
|
|
33
|
+
- `overfit_audit.nulls`: synthetic return generators (`gbm`, `garch11`,
|
|
34
|
+
`block_bootstrap`) and `false_positive_rate` with exact 95% Clopper-Pearson
|
|
35
|
+
confidence intervals.
|
|
36
|
+
- `overfit_audit.report`: end-to-end `audit()` function and `AuditReport` with
|
|
37
|
+
`to_markdown()` and JSON-safe `to_dict()`.
|
|
38
|
+
- `overfit_audit.adapters.freqtrade`: experimental readers (`load_backtest`,
|
|
39
|
+
`daily_returns`, `load_hyperopt`) for Freqtrade's documented export formats.
|
|
40
|
+
- Module documentation under `docs/`, quick-start example
|
|
41
|
+
`examples/quickstart.py`, `CONTRIBUTING.md`, and `CITATION.cff`.
|
|
42
|
+
|
|
43
|
+
[Unreleased]: https://github.com/javadzareei/overfit-audit/compare/v0.1.0...HEAD
|
|
44
|
+
[0.1.0]: https://github.com/javadzareei/overfit-audit/releases/tag/v0.1.0
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use overfit-audit in your research or workflow, please cite it using this metadata."
|
|
3
|
+
title: "overfit-audit"
|
|
4
|
+
version: "0.1.0"
|
|
5
|
+
date-released: "2026-12-05"
|
|
6
|
+
repository-code: "https://github.com/javadzareei/overfit-audit"
|
|
7
|
+
license: "MIT"
|
|
8
|
+
type: software
|
|
9
|
+
abstract: >-
|
|
10
|
+
Statistical checks for backtest overfitting: probabilistic and deflated
|
|
11
|
+
Sharpe ratios, effective trial counts, probability of backtest overfitting
|
|
12
|
+
(CSCV), White's Reality Check, Hansen's SPA, Romano-Wolf StepM, purged
|
|
13
|
+
walk-forward and combinatorial cross-validation, look-ahead signal audits,
|
|
14
|
+
and null-model false-positive calibration.
|
|
15
|
+
authors:
|
|
16
|
+
- name: "The overfit-audit authors"
|
|
17
|
+
keywords:
|
|
18
|
+
- backtest
|
|
19
|
+
- overfitting
|
|
20
|
+
- deflated-sharpe-ratio
|
|
21
|
+
- probability-of-backtest-overfitting
|
|
22
|
+
- reality-check
|
|
23
|
+
- superior-predictive-ability
|
|
24
|
+
- walk-forward
|
|
25
|
+
- quantitative-finance
|
|
26
|
+
references:
|
|
27
|
+
- type: article
|
|
28
|
+
authors:
|
|
29
|
+
- family-names: "Bailey"
|
|
30
|
+
given-names: "David H."
|
|
31
|
+
- family-names: "Lopez de Prado"
|
|
32
|
+
given-names: "Marcos"
|
|
33
|
+
title: "The Sharpe ratio efficient frontier"
|
|
34
|
+
journal: "Journal of Risk"
|
|
35
|
+
volume: 15
|
|
36
|
+
issue: 2
|
|
37
|
+
start: 3
|
|
38
|
+
end: 44
|
|
39
|
+
year: 2012
|
|
40
|
+
- type: article
|
|
41
|
+
authors:
|
|
42
|
+
- family-names: "Bailey"
|
|
43
|
+
given-names: "David H."
|
|
44
|
+
- family-names: "Lopez de Prado"
|
|
45
|
+
given-names: "Marcos"
|
|
46
|
+
title: "The deflated Sharpe ratio: correcting for selection bias, backtest overfitting and non-normality"
|
|
47
|
+
journal: "Journal of Portfolio Management"
|
|
48
|
+
volume: 40
|
|
49
|
+
issue: 5
|
|
50
|
+
start: 94
|
|
51
|
+
end: 107
|
|
52
|
+
year: 2014
|
|
53
|
+
- type: article
|
|
54
|
+
authors:
|
|
55
|
+
- family-names: "Bailey"
|
|
56
|
+
given-names: "David H."
|
|
57
|
+
- family-names: "Borwein"
|
|
58
|
+
given-names: "Jonathan M."
|
|
59
|
+
- family-names: "Lopez de Prado"
|
|
60
|
+
given-names: "Marcos"
|
|
61
|
+
- family-names: "Zhu"
|
|
62
|
+
given-names: "Qiji Jim"
|
|
63
|
+
title: "The probability of backtest overfitting"
|
|
64
|
+
journal: "Journal of Computational Finance"
|
|
65
|
+
volume: 20
|
|
66
|
+
issue: 4
|
|
67
|
+
start: 39
|
|
68
|
+
end: 69
|
|
69
|
+
year: 2017
|
|
70
|
+
- type: article
|
|
71
|
+
authors:
|
|
72
|
+
- family-names: "White"
|
|
73
|
+
given-names: "Halbert"
|
|
74
|
+
title: "A reality check for data snooping"
|
|
75
|
+
journal: "Econometrica"
|
|
76
|
+
volume: 68
|
|
77
|
+
issue: 5
|
|
78
|
+
start: 1097
|
|
79
|
+
end: 1126
|
|
80
|
+
year: 2000
|
|
81
|
+
- type: article
|
|
82
|
+
authors:
|
|
83
|
+
- family-names: "Hansen"
|
|
84
|
+
given-names: "Peter Reinhard"
|
|
85
|
+
title: "A test for superior predictive ability"
|
|
86
|
+
journal: "Journal of Business & Economic Statistics"
|
|
87
|
+
volume: 23
|
|
88
|
+
issue: 4
|
|
89
|
+
start: 365
|
|
90
|
+
end: 380
|
|
91
|
+
year: 2005
|
|
92
|
+
- type: article
|
|
93
|
+
authors:
|
|
94
|
+
- family-names: "Romano"
|
|
95
|
+
given-names: "Joseph P."
|
|
96
|
+
- family-names: "Wolf"
|
|
97
|
+
given-names: "Michael"
|
|
98
|
+
title: "Stepwise multiple testing as formalized data snooping"
|
|
99
|
+
journal: "Econometrica"
|
|
100
|
+
volume: 73
|
|
101
|
+
issue: 4
|
|
102
|
+
start: 1237
|
|
103
|
+
end: 1282
|
|
104
|
+
year: 2005
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Contributing to overfit-audit
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to `overfit-audit`.
|
|
4
|
+
|
|
5
|
+
## Scope and principles
|
|
6
|
+
|
|
7
|
+
- **Follow the specification.** Version 0.1 scope, public APIs, and acceptance
|
|
8
|
+
criteria are defined in [docs/SPEC.md](docs/SPEC.md). Please open an issue to
|
|
9
|
+
discuss new modules or API changes before implementing them.
|
|
10
|
+
- **Minimal runtime dependencies.** Runtime dependencies are `numpy`, `scipy`,
|
|
11
|
+
and `pandas` only. `arch` is permitted in tests as an independent numerical
|
|
12
|
+
reference, never in runtime code.
|
|
13
|
+
- **Implement from primary papers.** Write code fresh from the cited papers; do
|
|
14
|
+
not copy code from other projects (especially copyleft-licensed projects).
|
|
15
|
+
Cite the relevant paper in every public function's docstring.
|
|
16
|
+
- **English only.** All code, comments, docstrings, documentation, tests,
|
|
17
|
+
commit messages, and pull request descriptions must be written in English.
|
|
18
|
+
- **No private material.** Do not commit real trading datasets, private
|
|
19
|
+
strategies, secrets, or tests requiring network access. Use small synthetic
|
|
20
|
+
fixtures only.
|
|
21
|
+
|
|
22
|
+
## Conventions
|
|
23
|
+
|
|
24
|
+
- Python >= 3.10 with full type hints.
|
|
25
|
+
- NumPy-style docstrings stating formulas, parameter meanings, and citations.
|
|
26
|
+
- Per-period Sharpe ratios everywhere (never annualise silently); Pearson
|
|
27
|
+
kurtosis (normal = 3).
|
|
28
|
+
- Validate inputs explicitly with `overfit_audit._validation` and raise
|
|
29
|
+
`ValueError` with actionable messages; never drop or fill NaN/infinite values
|
|
30
|
+
silently.
|
|
31
|
+
- Every stochastic function accepts `seed: int | numpy.random.Generator | None`
|
|
32
|
+
and uses `overfit_audit._resample.as_rng` / `numpy.random.default_rng`.
|
|
33
|
+
- Result objects are frozen dataclasses with a JSON-safe `to_dict()` method.
|
|
34
|
+
|
|
35
|
+
## Development setup and quality gates
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install -e ".[dev]"
|
|
39
|
+
ruff check .
|
|
40
|
+
pytest -q
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Tests must be deterministic, require no network access, and keep the full
|
|
44
|
+
suite fast (under 60 seconds on a single CPU). Mark longer Monte Carlo checks
|
|
45
|
+
with `@pytest.mark.slow`.
|
|
46
|
+
|
|
47
|
+
## Pull requests
|
|
48
|
+
|
|
49
|
+
1. Branch off `main` (never push directly to `main`).
|
|
50
|
+
2. Keep changes focused and include unit tests and documentation updates for
|
|
51
|
+
any public behavior change.
|
|
52
|
+
3. Run the quality gates above and include the exact commands and their output
|
|
53
|
+
in your pull request description.
|
|
54
|
+
|
|
55
|
+
## Releasing
|
|
56
|
+
|
|
57
|
+
Maintainers release from `main`:
|
|
58
|
+
|
|
59
|
+
1. Set the new version in `pyproject.toml`, `src/overfit_audit/__init__.py`
|
|
60
|
+
and `CITATION.cff`, and move the `Unreleased` changelog entries under a new
|
|
61
|
+
version heading.
|
|
62
|
+
2. Merge that change with green CI.
|
|
63
|
+
3. Push a tag `vX.Y.Z` that matches the version. The `Release` workflow
|
|
64
|
+
builds the sdist and wheel, tests the wheel outside the source tree and
|
|
65
|
+
publishes to PyPI through Trusted Publishing.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The overfit-audit authors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: overfit-audit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Statistical checks for backtest overfitting: deflated Sharpe, PBO, SPA/StepM, purged walk-forward, look-ahead audits and null-model calibration.
|
|
5
|
+
Project-URL: Homepage, https://github.com/javadzareei/overfit-audit
|
|
6
|
+
Project-URL: Issues, https://github.com/javadzareei/overfit-audit/issues
|
|
7
|
+
Author: The overfit-audit authors
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: backtest,deflated sharpe ratio,overfitting,pbo,quant,reality check,spa,walk-forward
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Requires-Dist: numpy>=1.24
|
|
20
|
+
Requires-Dist: pandas>=2.0
|
|
21
|
+
Requires-Dist: scipy>=1.10
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: arch>=7; extra == 'dev'
|
|
24
|
+
Requires-Dist: mypy>=1.8; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
26
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
27
|
+
Provides-Extra: test
|
|
28
|
+
Requires-Dist: arch>=7; extra == 'test'
|
|
29
|
+
Requires-Dist: pytest>=7; extra == 'test'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# overfit-audit
|
|
33
|
+
|
|
34
|
+
Statistical checks for backtest overfitting, for anyone who searches over
|
|
35
|
+
trading strategies or parameters and wants to know whether the winner is real.
|
|
36
|
+
|
|
37
|
+
> Status: alpha (`0.1.0`). Runtime dependencies: `numpy`, `scipy`,
|
|
38
|
+
> and `pandas` only.
|
|
39
|
+
|
|
40
|
+
## What it answers
|
|
41
|
+
|
|
42
|
+
When you evaluate dozens or hundreds of strategy variants and keep the best
|
|
43
|
+
one, standard backtest metrics overstate true skill. `overfit-audit` estimates
|
|
44
|
+
how much of an observed backtest result is selection luck and checks for
|
|
45
|
+
common validation bugs:
|
|
46
|
+
|
|
47
|
+
| Module | Question | Methods | Docs |
|
|
48
|
+
| --- | --- | --- | --- |
|
|
49
|
+
| `sharpe` | Is the Sharpe ratio above zero, or above what the best of *N* no-skill trials would show? | Probabilistic Sharpe ratio (PSR), deflated Sharpe ratio (DSR), minimum track record length (MinTRL) | [docs/sharpe.md](docs/sharpe.md) |
|
|
50
|
+
| `trials` | How many effectively independent trials are in the search? | Per-period trial Sharpes, eigenvalue participation ratio, correlation clustering | [docs/trials.md](docs/trials.md) |
|
|
51
|
+
| `pbo` | How often does the in-sample winner underperform out of sample? | Combinatorially symmetric cross-validation (CSCV), PBO, rank logits, degradation fit | [docs/pbo.md](docs/pbo.md) |
|
|
52
|
+
| `bootstrap` | Does any trial beat a benchmark after accounting for data snooping and serial correlation? | Politis-White optimal block length, White's Reality Check, Hansen's SPA, Romano-Wolf StepM | [docs/bootstrap.md](docs/bootstrap.md) |
|
|
53
|
+
| `splits` | How do I split time series without label leakage? | Rolling/anchored purged `WalkForward`, `CombinatorialPurgedKFold` with embargo and backtest paths | [docs/splits.md](docs/splits.md) |
|
|
54
|
+
| `lookahead` | Does a signal function peek into the future or depend on history length? | Truncation check, future perturbation check, warm-up sensitivity check | [docs/lookahead.md](docs/lookahead.md) |
|
|
55
|
+
| `nulls` | How often does my whole research pipeline claim a discovery on no-skill data? | GBM, Student-t GARCH(1,1), demeaned stationary block bootstrap, Clopper-Pearson false-positive rate | [docs/nulls.md](docs/nulls.md) |
|
|
56
|
+
| `report` | Can I run the core multiple-testing checks together in one call? | `audit()` and `AuditReport` (`to_markdown()`, `to_dict()`) | [docs/report.md](docs/report.md) |
|
|
57
|
+
| `adapters.freqtrade` | *(Experimental)* How do I audit Freqtrade backtests and hyperopt runs? | `load_backtest`, `daily_returns`, `load_hyperopt` (reads output files only; no Freqtrade dependency) | [docs/freqtrade.md](docs/freqtrade.md) |
|
|
58
|
+
|
|
59
|
+
## Install
|
|
60
|
+
|
|
61
|
+
Python 3.10 or newer is required.
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install overfit-audit # runtime dependencies only (numpy, scipy, pandas)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
For development, from a clone of this repository:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install -e ".[dev]" # adds pytest, arch (reference tests only), ruff, mypy
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Quick start
|
|
74
|
+
|
|
75
|
+
Generate synthetic zero-drift daily prices with `nulls.gbm`, search 200
|
|
76
|
+
moving-average crossover variants without look-ahead, and audit the full
|
|
77
|
+
return matrix with `audit(...)`:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
import numpy as np
|
|
81
|
+
import pandas as pd
|
|
82
|
+
from overfit_audit import audit, nulls
|
|
83
|
+
|
|
84
|
+
asset_returns = nulls.gbm(n_obs=1200, mu=0.0, sigma=0.01, seed=0)
|
|
85
|
+
prices = pd.Series(np.cumprod(1.0 + asset_returns))
|
|
86
|
+
|
|
87
|
+
fast_windows = range(5, 45, 2) # 20 fast windows
|
|
88
|
+
slow_windows = range(50, 250, 20) # 10 slow windows -> 200 variants
|
|
89
|
+
warmup = max(slow_windows)
|
|
90
|
+
|
|
91
|
+
trials = {}
|
|
92
|
+
for fast in fast_windows:
|
|
93
|
+
f_ma = prices.rolling(fast).mean().to_numpy()
|
|
94
|
+
for slow in slow_windows:
|
|
95
|
+
s_ma = prices.rolling(slow).mean().to_numpy()
|
|
96
|
+
pos = np.where(f_ma[warmup - 1 : -1] > s_ma[warmup - 1 : -1], 1.0, -1.0)
|
|
97
|
+
trials[f"ma_{fast}_{slow}"] = pos * asset_returns[warmup:]
|
|
98
|
+
|
|
99
|
+
report = audit(pd.DataFrame(trials), n_boot=2000, pbo_blocks=16, seed=0)
|
|
100
|
+
print(report.to_markdown())
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
See [examples/quickstart.py](examples/quickstart.py) for the complete runnable
|
|
104
|
+
script (runs in a few seconds).
|
|
105
|
+
|
|
106
|
+
Conventions used across all modules:
|
|
107
|
+
|
|
108
|
+
- **Input shape**: `T x N` matrix with rows in chronological order (oldest
|
|
109
|
+
first) and columns as trials.
|
|
110
|
+
- **Units**: Sharpe ratios are **per period**, never annualised silently. Use
|
|
111
|
+
`sharpe.annualise` / `sharpe.deannualise` to convert.
|
|
112
|
+
- **Kurtosis**: **Pearson** kurtosis (normal = 3), not excess kurtosis.
|
|
113
|
+
- **Validation**: NaN, infinite values, constant series, and too-short inputs
|
|
114
|
+
raise `ValueError` instead of being silently dropped or filled.
|
|
115
|
+
|
|
116
|
+
## How to read the numbers
|
|
117
|
+
|
|
118
|
+
- **Per-period Sharpe & PSR(0)**: PSR(0) is the probability that the selected
|
|
119
|
+
trial's true Sharpe ratio is positive *assuming it was the only trial you ever
|
|
120
|
+
tested*. High PSR(0) is common for the winner of a large search on pure noise.
|
|
121
|
+
- **DSR (raw `n_trials`)**: Deflates the Sharpe test against the expected
|
|
122
|
+
maximum of `n_trials` no-skill trials (`SR_0`), accounting for skewness and
|
|
123
|
+
kurtosis. Values below 0.95 mean the selected Sharpe is not distinguishable
|
|
124
|
+
from selection luck at the 95% level. Always include discarded variants in
|
|
125
|
+
`n_trials`.
|
|
126
|
+
- **DSR (effective `N`)**: Shown as a secondary diagnostic using the eigenvalue
|
|
127
|
+
participation ratio of the trial correlation matrix. Because the sample
|
|
128
|
+
participation ratio is biased downward unless `N << T`, effective-`N` DSR is
|
|
129
|
+
optimistic when `N` is not much smaller than `T`; use raw `n_trials` as the
|
|
130
|
+
primary figure.
|
|
131
|
+
- **PBO (CSCV)**: Fraction of combinatorially symmetric splits in which the
|
|
132
|
+
in-sample winner ranks at or below the out-of-sample median. Values near or
|
|
133
|
+
above 0.50 indicate that in-sample ranking did no better than chance out of
|
|
134
|
+
sample. Also check `prob_oos_loss` for absolute out-of-sample performance.
|
|
135
|
+
- **Reality Check & SPA p-values**: Stationary-bootstrap tests of whether the
|
|
136
|
+
best trial beats the benchmark after accounting for both multiple testing and
|
|
137
|
+
serial correlation. Hansen's consistent SPA p-value (`p_consistent`) is
|
|
138
|
+
generally more powerful than White's Reality Check when poor variants are
|
|
139
|
+
present; `p_lower` and `p_upper` bound it.
|
|
140
|
+
- **StepM survivors**: Trials that remain significant at familywise error rate
|
|
141
|
+
`alpha` (default 0.05) under Romano-Wolf stepwise multiple testing.
|
|
142
|
+
- **Look-ahead & null calibration**: Passing statistical tests does not catch
|
|
143
|
+
look-ahead leakage. Run `lookahead.check_truncation`,
|
|
144
|
+
`check_future_perturbation`, and `check_warmup` on your signal code, and use
|
|
145
|
+
`nulls.false_positive_rate` to verify that your end-to-end discovery pipeline
|
|
146
|
+
hits its nominal false-positive rate on synthetic no-skill data.
|
|
147
|
+
|
|
148
|
+
## References
|
|
149
|
+
|
|
150
|
+
- Bailey, D. H. and Lopez de Prado, M. (2012). *The Sharpe ratio efficient
|
|
151
|
+
frontier*. Journal of Risk 15(2), 3–44.
|
|
152
|
+
- Bailey, D. H. and Lopez de Prado, M. (2014). *The deflated Sharpe ratio:
|
|
153
|
+
correcting for selection bias, backtest overfitting and non-normality*.
|
|
154
|
+
Journal of Portfolio Management 40(5), 94–107.
|
|
155
|
+
- Bailey, D. H., Borwein, J. M., Lopez de Prado, M. and Zhu, Q. J. (2017).
|
|
156
|
+
*The probability of backtest overfitting*. Journal of Computational Finance
|
|
157
|
+
20(4), 39–69.
|
|
158
|
+
- Bollerslev, T. (1986, 1987). *Generalized autoregressive conditional
|
|
159
|
+
heteroskedasticity*, Journal of Econometrics 31(3), 307–327; *A conditionally
|
|
160
|
+
heteroskedastic time series model for speculative prices and rates of
|
|
161
|
+
return*, Review of Economics and Statistics 69(3), 542–547.
|
|
162
|
+
- Clopper, C. J. and Pearson, E. S. (1934). *The use of confidence or fiducial
|
|
163
|
+
limits illustrated in the case of the binomial*. Biometrika 26(4), 404–413.
|
|
164
|
+
- Hansen, P. R. (2005). *A test for superior predictive ability*. Journal of
|
|
165
|
+
Business and Economic Statistics 23(4), 365–380.
|
|
166
|
+
- Lopez de Prado, M. (2018). *Advances in Financial Machine Learning*,
|
|
167
|
+
Chapters 7 and 12. Wiley.
|
|
168
|
+
- Mertens, E. (2002). *Comments on variance of the IID estimator in Lo (2002)*.
|
|
169
|
+
Working paper.
|
|
170
|
+
- Patton, A., Politis, D. N. and White, H. (2009). *Correction to "Automatic
|
|
171
|
+
block-length selection for the dependent bootstrap" by D. Politis and
|
|
172
|
+
H. White*. Econometric Reviews 28(4), 372–375.
|
|
173
|
+
- Politis, D. N. and Romano, J. P. (1994). *The stationary bootstrap*. Journal
|
|
174
|
+
of the American Statistical Association 89(428), 1303–1313.
|
|
175
|
+
- Politis, D. N. and White, H. (2004). *Automatic block-length selection for
|
|
176
|
+
the dependent bootstrap*. Econometric Reviews 23(1), 53–70.
|
|
177
|
+
- Romano, J. P. and Wolf, M. (2005). *Stepwise multiple testing as formalized
|
|
178
|
+
data snooping*. Econometrica 73(4), 1237–1282.
|
|
179
|
+
- White, H. (2000). *A reality check for data snooping*. Econometrica 68(5),
|
|
180
|
+
1097–1126.
|
|
181
|
+
|
|
182
|
+
## AI-assistance note
|
|
183
|
+
|
|
184
|
+
Parts of this library were written with the help of AI assistants (Anthropic
|
|
185
|
+
Claude, OpenAI Codex and Google Gemini wrote code; Gemini also reviewed the
|
|
186
|
+
formulas) and
|
|
187
|
+
reviewed by the maintainer; every formula is tested against published values or
|
|
188
|
+
an independent implementation.
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
|
|
192
|
+
MIT. See [LICENSE](LICENSE).
|