Skip to main content

sharpebench (Python)

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

Python distribution of SharpeBench's honest-backtest statistics, a pyo3 binding over the same deterministic Rust kernel the SharpeBench CLI and the @general-liquidity/sharpebench npm package use. 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?
v = is_my_sharpe_real(returns, n_trials=200)
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) P(true Sharpe > benchmark) (PSR)
deflated_sharpe_ratio(returns, n_trials, trials_sr_std=0.5) PSR deflated for the size of the search (DSR)
expected_max_sharpe(trials_sr_std, n_trials) the Sharpe the best of n_trials shows with zero skill
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
bootstrap_pvalue(excess, ...) stationary-bootstrap p-value for one series
is_my_sharpe_real(returns, n_trials=1, ...) LITE verdict dict: pass | borderline | fail + explanation
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?
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 overfit-onset diagnostics
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

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sharpebench-0.16.0.tar.gz (239.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

sharpebench-0.16.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (540.6 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

sharpebench-0.16.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (541.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

sharpebench-0.16.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (546.0 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

sharpebench-0.16.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (546.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

Details for the file sharpebench-0.16.0.tar.gz.

File metadata

  • Download URL: sharpebench-0.16.0.tar.gz
  • Upload date:
  • Size: 239.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for sharpebench-0.16.0.tar.gz
Algorithm Hash digest
SHA256 5a0fd03570df5fd21fd57d406e3191b2de8967ea0861d1f684d63b2bf11d9073
MD5 62ea6aa778d97add5a8def8b79998611
BLAKE2b-256 eb2ed9c3cfc6d4679437bbd7a1d4a10442f99faadc84c6ec1d02b9553b6ede32

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharpebench-0.16.0.tar.gz:

Publisher: release.yml on general-liquidity/sharpebench

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sharpebench-0.16.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sharpebench-0.16.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5bc8c78db7e023766d9941eebbbd619dc69ff890f4ef45b693ca28399727db9b
MD5 ecc094c11fd4b52d5d3d6ff481230db7
BLAKE2b-256 e03c591e17bedd4df581f172d9998583acab1066c1d9ed2c7370b80658abec4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharpebench-0.16.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on general-liquidity/sharpebench

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sharpebench-0.16.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sharpebench-0.16.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 26488e42f81b19b8b8ba4fcdde2fd1b899714ce5bec6ba96b46b8bbd88b0aadd
MD5 32ac2774672790375da6ed0a399fdf22
BLAKE2b-256 54edaba75807acb1cb59a3c30bc5c36e34d2b69fc768d0402c6fcf5abd3c331f

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharpebench-0.16.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on general-liquidity/sharpebench

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sharpebench-0.16.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sharpebench-0.16.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 54e74aa403b9923f81e324b543691c05486080151db0bc2e7d30d0dc5e828639
MD5 050831872e4e8552d136cd51102f98aa
BLAKE2b-256 b1be816ebd9daf5ff9c82bf8be25b5418290d59428f9bce9f8b356b45ee0c4ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharpebench-0.16.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on general-liquidity/sharpebench

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sharpebench-0.16.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sharpebench-0.16.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a1340c61351dff1ab245d103682c5d996fba605b5e11fb1b398e22c3bc76a1be
MD5 af42572bc2e219a6f8a85848569a0967
BLAKE2b-256 e0aced66adf4d0bd89d9af4300d2d25310a7d8c082e1a46ad5236d82a4da588e

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharpebench-0.16.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on general-liquidity/sharpebench

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.16.0 This release

5 files

0.15.0

5 files

0.14.1

5 files

0.14.0

5 files

0.13.0

5 files

0.12.0

5 files

0.11.0

5 files

0.10.0

5 files

0.9.0

5 files

0.8.0

5 files

0.7.0

5 files

0.6.0

5 files

0.5.0

5 files

0.4.0

5 files

0.3.0

5 files

0.2.1

5 files

0.2.0

5 files

0.1.0

5 files

0.0.14

5 files

0.0.13

5 files

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