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

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 same input yields byte-identical output on any platform.

Relationship to sharpearena

sharpearena is the environment: a leak-free, point-in-time arena where a trading agent produces a track, scored end-to-end by score_run. 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.8.0.tar.gz (179.4 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.8.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (504.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

sharpebench-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (504.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

sharpebench-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (507.6 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

sharpebench-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (507.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for sharpebench-0.8.0.tar.gz
Algorithm Hash digest
SHA256 a612836caa3798120af474aaac543fec3bd2b242dd612e721f557908f38f9fc5
MD5 e9442dca8288d9f9a5d07f90b1d2f1ad
BLAKE2b-256 6caef1ea45ff732dfcb8107e873dc826f74d1f530c0d201ce17f497f599b25ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharpebench-0.8.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.8.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sharpebench-0.8.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1a8290dcf397e029e1f44d9b3d1e337eacd6e5b4801ca2c91bbdae8972ea0e4e
MD5 ae0d5441853b1749f5dda9516ed45d0a
BLAKE2b-256 3b4187febfafc281d2041e8f338971bb99195d726fb622ed1edb4558a6b78c04

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharpebench-0.8.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.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sharpebench-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2e85adaef8b5b9ddf7233de596c2728dfde38597b381d1ddfa225b1e0e3fb655
MD5 3959a97a2133c69f3924b8a37c60f285
BLAKE2b-256 15a89da82b6f16cdba75a429f584f97e831a68e089b71ee23650a0b08b61ab1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharpebench-0.8.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.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sharpebench-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc83e1b0cbf538c1f48d12c09818c38c2ebb8247fe8be28e56aef31b7183a5c3
MD5 c198553eefd3edbaaaf5616cf6c99f37
BLAKE2b-256 343fc1697284a64e53b8fb468ed8fcae688b466aa08a2b8e8a0ffe811d3b50ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharpebench-0.8.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.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sharpebench-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eac3617edf1d2d7fb01b52079d4dee0b7e00a420fcc9753f4fca11b37f88ad43
MD5 7c2036c807fdaa86b1777d7135a5fa1d
BLAKE2b-256 ccadefd6a6538837a546ee4b796c5b292e1e6c0fb30526995159ed8fdbb0bc2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for sharpebench-0.8.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

0.16.0

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

This release

0.8.0 This release

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