Skip to main content

sharpebench (Python)

Is my Sharpe real, or an artifact of luck and multiple testing?

Python distribution of SharpeBench's luck-robust quantitative evaluation statistics, a pyo3 binding over the same deterministic Rust kernel used by the SharpeBench CLI and the @general-liquidity/sharpebench npm package. Bring your own return series; everything takes plain numeric sequences (lists, tuples, numpy arrays, df["ret"].to_numpy()) and returns plain floats, lists and dicts.

import numpy as np
from sharpebench import is_my_sharpe_real, bootstrap_dsr_ci

returns = df["strategy_ret"].to_numpy()          # per-period, NOT annualized

# n_trials is the honest one: how many variants did you try before keeping this?
# periods_per_year says what a row is (default 252, daily bars).
v = is_my_sharpe_real(returns, n_trials=200, periods_per_year=252)
print(v["sharpe"], v["deflated_sharpe"], v["verdict"], v["explanation"])

ci = bootstrap_dsr_ci(returns, n_trials=200)
print(ci["lower"], ci["point"], ci["upper"])

Surface

Function Answers
sharpe_ratio(returns) observed per-period Sharpe
moments(returns, target=0.0) mean / std / skew / kurtosis / downside deviation / Sortino
probabilistic_sharpe_ratio(returns, sr_benchmark=0.0) PSR: one minus the p-value of H0: SR <= benchmark (not the probability the true Sharpe exceeds it)
deflated_sharpe_ratio(returns, n_trials, trials_sr_std=None, periods_per_year=None) PSR against the best of n_trials zero-skill trials (DSR): one minus a p-value, not the probability of skill. trials_sr_std is per period; omitted, it is the annualized 0.5 prior over sqrt(periods_per_year) (default 252)
expected_max_sharpe(trials_sr_std, n_trials) the per-period Sharpe the best of n_trials shows with zero skill, from a per-period trials_sr_std
min_track_record_length(returns, ...) periods needed before the Sharpe is believable
bootstrap_dsr_ci(returns, n_trials, ...) {point, se, lower, upper} on the DSR itself; trials_sr_std / periods_per_year as in deflated_sharpe_ratio
bootstrap_pvalue(excess, ...) stationary-bootstrap p-value for one series
is_my_sharpe_real(returns, n_trials=1, ..., periods_per_year=None) LITE verdict dict: pass | borderline | fail + explanation. trials_sr_std is annualized and periods_per_year (default 252, flagged) converts it
is_my_sharpe_real_full(field, ...) FULL verdict over a whole candidate field (LITE + snooping family + PBO + HLZ)
reality_check_pvalue(field, ...) White's Reality Check over the field
spa_pvalue / spa_consistent_pvalue(field, ...) Hansen's SPA (liberal / consistent)
step_down_significant(field, ..., alpha=0.05) Romano-Wolf step-down, per candidate, FWER-controlled
probability_of_backtest_overfitting(perf_matrix, s=16) CSCV PBO
benjamini_hochberg(p_values, q=0.05) / fdr_verdict(...) BH-FDR rejections and the operator summary
hlz_gate(t_stat, t_threshold=None) the Harvey-Liu-Zhu |t| >= 3.0 factor bar
selection_robustness(candidates, n_trials, ...) best vs median DSR: is the headline a lucky pick? trials_sr_std / periods_per_year as in deflated_sharpe_ratio
runs_for_power(effect, alpha, power) how many runs to detect an effect
pass_k(passed_per_run, mode="all", n=None) pass^k reliability: won on every run, not on average
budget_curve(...) DSR by search budget, marginal DSR, and the non-improvement onset. trials_sr_std is annualized (default 0.5) and converted by periods_per_year (default 252)
rank_board(submissions, config_json="") / score_one(...) Full composite scoring over the CLI-compatible JSON contract
rank_returns(field, config_json="") Build and rank a board from agent IDs and per-run return arrays
default_score_config() Serialize the default scoring configuration
never_catastrophic_config() Serialize the preset that asks only whether every run avoids catastrophe
relative_to_benchmark_config(id) Serialize the benchmark-relative pass preset

Units of the deflation prior

Every Sharpe here is per period. The verdicts (is_my_sharpe_real*) and budget_curve take trials_sr_std annualized, like the leaderboard's ScoreConfig, and divide it by sqrt(periods_per_year). The raw primitives (deflated_sharpe_ratio, bootstrap_dsr_ci, selection_robustness, expected_max_sharpe) take it per period and use an explicit value as given. Omitted, the first three use the annualized 0.5 prior at periods_per_year (default 252): 0.5 / sqrt(252) = 0.0315 per period on daily returns. Through 0.19.0 they used 0.5 per period, an annualized dispersion of about 7.9 on daily returns.

deflated_sharpe_ratio(returns, n_trials=200)                         # 0.5 / sqrt(252) per period
deflated_sharpe_ratio(returns, n_trials=200, periods_per_year=8760)  # hourly: 0.5 / sqrt(8760)
deflated_sharpe_ratio(returns, n_trials=200, trials_sr_std=0.02)     # your per-period value, as given

Matrix orientation

Two conventions, deliberately unchanged from the papers they come from:

  • the data-snooping family (reality_check_pvalue, spa_*, step_down_significant, is_my_sharpe_real_full) takes a field: N rows (strategies) x T cols (time);
  • probability_of_backtest_overfitting takes the transpose: T rows (time) x N cols (strategies).

Determinism

No I/O, no clock, no ambient randomness. The bootstraps take an explicit seed (defaulted to a fixed constant, so a result is reproducible unless you ask for otherwise). The Python suite matches the public example board to the committed Rust golden on Ubuntu CI. Rust CI separately checks two committed golden fields on Linux, macOS, and Windows; neither check covers every possible input or host.

Relationship to sharpearena

sharpearena is the environment: a point-in-time market API where a trading agent produces a track, scored end-to-end by its score_run helper. It does not provide process containment. sharpebench is the judge for a track you already have: your own backtest, live P&L, or a field of candidate strategies. They share one Rust statistics kernel, so the verdict is identical either way; this package simply does not, and will not, duplicate arena run-scoring.

Building from source

python -m pip install maturin
python -m maturin develop --manifest-path crates/sharpebench-py/Cargo.toml
python -m pytest crates/sharpebench-py/tests

MIT OR Apache-2.0.

Metadata

Release files for sharpebench 0.21.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sharpebench 0.21.0
File Size Uploaded
sharpebench-0.21.0.tar.gz 390.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for sharpebench 0.21.0
File
sharpebench-0.21.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
sharpebench-0.21.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
sharpebench-0.21.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
sharpebench-0.21.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details

Total release size: 3.1 MB

Release files / sharpebench-0.21.0.tar.gz

Download URL sharpebench-0.21.0.tar.gz
Size 390.5 kB
Tags Source
SHA-256 checksum
How to use checksums
09655491a38eafe69dda725014b92161bcee054b2c38e3ab5db13fc226e75913
BLAKE2b-256 checksum
How to use checksums
6364591dc82f8b781e9f5abaa155a548e228c32cc737742a3964a40715d14574
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 10, 2026.

Transparency log

Release files / sharpebench-0.21.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL sharpebench-0.21.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 668.5 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
6375fccd598e71f9f400e3ddb3940459c79f0869959b2a74a27ad50d8cf96da2
BLAKE2b-256 checksum
How to use checksums
77d43238cd7e1849337fcc7c3530c76f3c9adf01db4eaa43dfd62b3b1272d494
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 10, 2026.

Transparency log

Release files / sharpebench-0.21.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL sharpebench-0.21.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 669.1 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
4337d8ae8840d63ff8f6189d6a3aaaef5a4dbff29bb3a250eca8522ba2610582
BLAKE2b-256 checksum
How to use checksums
79522f8fe6ede5e30309c50fa89b8054134a81b79b4c9917211e647adb7c016e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 10, 2026.

Transparency log

Release files / sharpebench-0.21.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL sharpebench-0.21.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 674.0 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
2a056f4eaa57474048ba41ee58e000833b22d887a12824bdd94987b3ad9b44b8
BLAKE2b-256 checksum
How to use checksums
185eac385f6564047a09e58c8ddee0521ffc4715fdd998cc39d3a4959c76062f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 10, 2026.

Transparency log

Release files / sharpebench-0.21.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL sharpebench-0.21.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 674.0 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
a30387302bac418a94f670188b157148c62902624a54240cd5b602b8e86bbb88
BLAKE2b-256 checksum
How to use checksums
c8cf8797008dce67c63c5ed6ce8a58d7dd32d510d6497743258293608c840e15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 10, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page