oss-backtest-kit
Run an overfitting checkup on an existing backtest: read freqtrade results or CSV directly.
Read the full sample report, including every check, explanation and threshold. Synthetic demo, not a trading result: the best of 40 pure-noise variants has annualised Sharpe 1.66 and PSR 0.950, but DSR falls to 0.297 after counting all 40 tries; PBO is 0.79 and the overall verdict is FAIL.
Try it in 30 seconds
Install the released version, then print the same report with three lines of Python (no result file needed):
python -m pip install oss-backtest-kit==0.2.0
from numpy.random import default_rng
from oss_backtest_kit.checkup import checkup
print(checkup(default_rng(0).normal(0, 0.01, (365, 40)), n_trials=40).to_markdown())
Have your own results? Replace my_result.zip with your result file or folder. --trials 20 is an example: replace 20 with the actual total number of versions tried, including unsaved ones.
python -m oss_backtest_kit.checkup my_result.zip --trials 20 --html report.html
Open report.html locally. Use a CSV path in the same command for CSV input. Nothing is downloaded and no account is needed. See the input quick reference below.
Prefer Colab? Run the quick start notebook: install 0.2.0, then display the synthetic checkup report before the engine tutorial.
Available after installing 0.3.0: the candidate adds a one-command synthetic demo (no result file or matplotlib needed):
python -m oss_backtest_kit.checkup --demo --html report.html
For a real export, reproduce the freqtrade 2026.10 futures checkup: 43 daily returns, single-result PBO n/a, and drawdown from realised equity.
Your results: quick reference
- freqtrade: choose the actual
backtest-result-*.zipinuser_data/backtest_results/, or the result.jsonon older exports. Keep the zip's original name. Do not choose.last_result.json,*.meta.json,*_config.json, strategy-parameter files or Hyperopt output. For several strategies in one file, add--strategy NAME. Drawdown uses realised equity from closed trades; it excludes open-position losses. - CSV: a header and two columns are enough:
date,returnordate,equity, as below. Dates are sorted ISO dates in UTC. Returns are fractions: 0.01 = 1%, not 1. Equity is the account value, not a percentage. Use one format per file.
date,return
2024-01-01,0.01
2024-01-02,-0.005
date,equity
2024-01-01,1000
2024-01-02,1010
2024-01-03,1004.95
These snippets show the format only. Fewer than 30 daily returns are refused; supply at least 30 daily returns, or 31 daily equity points. Multiple rows per day do not increase the daily count. Fewer than 180 observations cannot pass; serial dependence can reduce the effective sample further.
--trials: count every version tried, including discarded or unsaved versions. The number of saved files can understate the search. Without a supplied total the report can be at most CAUTION.- PBO: needs multiple candidate results covering the same period, with at least 30 common daily returns. Put one result per variant in a folder and pass that folder as the input. A single result reports PBO as
n/a. - Exit codes:
0means a report was generated, even when its verdict is FAIL;2means a parameter, input or report-writing failure (including insufficient input). See stderr for the specific reason.
Highlights
- Overfitting checks built in. Deflated Sharpe Ratio, Probabilistic Sharpe Ratio and Probability of Backtest Overfitting (CSCV) adjust your result for how many variants you tried, so a lucky curve is easier to spot before it costs money.
- 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.
- 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.
- Costs that bite. Perpetual-futures funding is included, and a
stressedcost level lets you check whether an edge survives worse fills. - Small and readable. Pure Python with only numpy and scipy; offline tests only; no account, API key or paid data needed.
- MIT licensed code (the market data has its own terms; see below).
Who it is for
Individual researchers and students who write their own strategies in Python and want a quick, sober second opinion on a backtest. It is not a trading bot, does not place orders and does not connect to any exchange account.
What is inside
A small research toolkit for crypto strategies, in four parts:
- 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. - 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). - A simple, config-driven backtest engine (
oss_backtest_kit.engine) for a portfolio of perpetual futures, with funding and a two-level cost model. - An overfitting checkup (
oss_backtest_kit.checkup, with readers inoss_backtest_kit.loaders): reads backtest results from other tools (freqtrade result files, CSV, arrays) and writes a Markdown or HTML report.
DISCLAIMER
This project is for research and education only. It is not investment advice. It comes with no warranty of any kind; you use it at your own risk. Backtest results are not live results: past or simulated performance says little about future outcomes, and you can lose money trading.
Status
Early release (version 0.3.0 candidate, not yet published; the available install and Colab examples use 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.
Requirements and install
- Python 3.9 or newer, with numpy and scipy (installed automatically below).
- Internet access only if you download data; everything else, tests included, runs offline.
- Some Python knowledge: you write your strategy as a small Python function.
git clone https://github.com/ww7411/oss-backtest-kit.git
cd oss-backtest-kit
pip install -e .
Tests use pytest (install the test extra first: pip install -e ".[test]"). The stats, engine and data test files can also be run directly with python3.
Quick start
Download public data (nothing is downloaded unless you run this; the output folder is yours to choose):
python -m oss_backtest_kit.data archive --kinds klines,fundingRate --symbols BTCUSDT \
--interval 1d --from 2024-01 --to 2024-06 --out ./market_data
python -m oss_backtest_kit.data check --out ./market_data \
--kind klines --symbol BTCUSDT --interval 1d
Kinds: klines (needs --interval), markPriceKlines, indexPriceKlines, premiumIndexKlines, fundingRate, metrics. Files that fail the checksum are neither saved nor recorded; existing files are never overwritten. Recent bars not yet in the archive can be exported with the rest subcommand; it writes standalone CSV files under <out>/rest/ for inspection or your own merging. They are not added to the manifest and load_market_data does not read them, so a backtest ends at the last archive file.
Run the moving-average crossover example (synthetic data, nothing downloaded):
python3 examples/ma_crossover.py
Synthetic data, not a trading result. The best of 9 moving-average variants has an average return just above zero (Sharpe ratio slightly positive, PSR 0.53), but the equity curve still ends a little below its start (0.97), because volatility drags down compounded growth; after charging for the 9 tries the DSR is 0.07, so there is no evidence of skill. Reproduce it with examples/equity_psr_dsr.py.
Draw this engine example chart (needs matplotlib, an optional extra that is not a runtime dependency):
pip install -e ".[examples]"
python3 examples/equity_psr_dsr.py
Or open the quick start notebook in Colab: the synthetic checkup report comes first, followed by this engine tutorial. Installation needs internet; calculations download no data.
Use the statistics:
import numpy as np
from oss_backtest_kit import stats
returns = np.random.default_rng(0).normal(0.0005, 0.01, 500)
print(stats.psr(returns)) # P(true Sharpe > 0)
value, benchmark, var = stats.dsr(returns, n_trials=20, # penalise 20 tries
trial_sharpes=[0.01, 0.03, 0.02])
print(stats.wilson(7, 50)) # 95% interval for 7/50
Run a backtest on your own downloaded data:
from oss_backtest_kit.engine import EngineConfig, load_market_data, run_backtest
data = load_market_data("./market_data", ["BTCUSDT"], interval="1d")
cfg = EngineConfig(symbols=["BTCUSDT"], max_leverage=1.0, rebalance_threshold=0.02)
def strategy(t, history): # called at the close of bar t, sees bars 0..t only
return {"BTCUSDT": 1.0} # sum(|weights|) must not exceed max_leverage
result = run_backtest(data, strategy, cfg, cost_level="stressed")
print(result.summary()) # result.returns feeds stats.psr / stats.dsr
Checkup: is this backtest overfitted?
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.
Try it on synthetic data first (one overfitted group, one robust group; nothing is downloaded):
python3 examples/checkup_demo.py
On your own results, from the command line:
python -m oss_backtest_kit.checkup <result file or folder> --trials N [--report out.md] [--html out.html]
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.
- The input is a freqtrade backtest result (
.jsonor.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/); seedocs/SPEC_B.mdfor 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). --trials Nis 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 1only 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.- 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. - 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). - 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.
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.
In Python:
from oss_backtest_kit.checkup import checkup
report = checkup("./results_folder", n_trials=25)
print(report.overall) # "pass", "caution" or "fail": the worst line
print(report.to_markdown()) # or report.to_html() for one self-contained file
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.
Modules
| Module | Purpose |
|---|---|
stats |
PSR, DSR, PBO (CSCV), effective trials, block bootstrap, Wilson interval |
data.archive |
Archive download with checksum verification, manifest, exclusive-create writes |
data.rest_tail |
Recent closed bars and funding from public REST endpoints |
data.check |
Manifest SHA check, gap and duplicate detection |
engine |
Config, market data loader, backtest loop, result summary |
loaders |
Read backtest results (freqtrade result files, CSV, arrays, a folder of results) as daily returns |
checkup |
Overfitting checkup and its command line; report writes the Markdown / HTML report |
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.
Tests
pip install -e ".[test]"
python3 -m pytest
All tests run offline with synthetic data and fake network responses.
Known limitations
- Fills are modelled from OHLC bars (decision at a bar close, fill at the next open with slippage and a proportional fee). Real fills depend on order books, latency and size.
- Funding is modelled as position x price x rate at each funding time, using the open price of the bar that contains the event; margin, liquidation and exchange rules are not modelled beyond stopping at zero equity (limited liability: positions are closed at that bar's close and any loss beyond zero is reported as
ruin_shortfall, sosum(pnl_by_symbol) + ruin_shortfallequals the change in equity). - Survivorship bias: the symbols you choose are the ones that exist today; delisted symbols are not included unless you add them.
- Cost defaults (
baseandstressed) are placeholders, not estimates for any venue. Set your own numbers. - Statistics assume the return series is a fair sample; PSR/DSR/PBO reduce, but do not remove, the risk of overfitting.
Data terms
This kit ships code only and never any market data (no candles, no ticks). One exception to note: tests/data/real_freqtrade_2026_10/ and tests/data/real_freqtrade_2026_10_futures/ hold the result files of two small freqtrade backtests (one spot, one futures) used as tests (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 those folders if you redistribute the package and are unsure about them. 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.
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:
- Attribution: if you share the data or anything derived from it (cleaned files, aggregated tables, published charts of the data), credit the source, link the licence, and say whether you changed it.
- NonCommercial: no commercial use of the data.
- ShareAlike: data you derive from it and share must be shared under the same licence.
2. Recent data from the REST API at fapi.binance.com (rest subcommand). This is not covered by the archive licence above. It falls under the exchange's own API and website terms of use, which this project has not reviewed; we make no statement about what they allow. Check them before using or sharing REST data.
You alone are responsible for complying with the terms of each source and with the exchange's rules.
License
MIT; see LICENSE. The licence covers this code only, not any market data you download with it (see the data terms above).
Metadata
Release files for oss-backtest-kit 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| oss_backtest_kit-0.3.0.tar.gz | 399.1 kB | With provenance | Details for oss_backtest_kit-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| oss_backtest_kit-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for oss_backtest_kit-0.3.0-py3-none-any.whl |
Total release size: 463.7 kB
Release files / oss_backtest_kit-0.3.0.tar.gz
| Download URL | oss_backtest_kit-0.3.0.tar.gz |
|---|---|
| Size | 399.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0bdb67c21b03e1e326fdc671be1f171c91984d01fca824d4731c478caf50994c
|
|
BLAKE2b-256 checksum How to use checksums |
d9d988841497b1e589bf655b2f05fa4e96fe808cf25f5eb4ba2194d4b4a022cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logRelease files / oss_backtest_kit-0.3.0-py3-none-any.whl
| Download URL | oss_backtest_kit-0.3.0-py3-none-any.whl |
|---|---|
| Size | 64.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3f4f659beaa42cf837cad85da76ed5b0d7d6ba7a4ff8518d38e5d6624cb9a091
|
|
BLAKE2b-256 checksum How to use checksums |
c551c89798675369e03886d5701ab143cf09be46134d2f6991504bb2784dc524
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logSecurity for oss-backtest-kit 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for oss_backtest_kit-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.