Metadata-Version: 2.4
Name: quantproof
Version: 0.1.5
Summary: Selection-bias tools for trading research: deflated Sharpe, luck curves, and a known-answer smoke test for your Sharpe reporting path.
Author: QuantProof
License: MIT License
        
        Copyright (c) 2026 Quantproof
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: QuantProof Pro (paid tier), https://quantproof.gumroad.com/l/quantproof-pro
Project-URL: All QuantProof tools, https://quantproof.gumroad.com
Keywords: backtesting,overfitting,deflated sharpe,quant,trading,validation
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.22
Dynamic: license-file

# QuantProof

**Checks whether your best backtest is better than luck.**

If you tried 200 strategies, the best one looks good by chance. Two
hundred random strategies over ten years of daily data will hand their
best performer a Sharpe near 0.9 with no edge anywhere in the pile.
QuantProof computes how good your winner has to be before luck stops
being the explanation, and tells you whether it clears that bar.

## The instruments

### `quantproof.canary`: a smoke test for your Sharpe adapter

Feed your wrapped pipeline four things whose true value is known by
construction, and check the reported numbers:

- a **crystal ball** that knows tomorrow's return. It must report a
  large Sharpe. If it doesn't, signal is being destroyed between the
  positions and the report.
- an **anti-oracle**, wrong on purpose every day. It must report a
  large negative Sharpe. A positive number here means the pipeline is
  discarding the sign of performance.
- a **dead strategy** that never trades. It must report roughly zero.
  Anything else means the pipeline manufactures performance from
  nothing.
- a **coin-flip mine**: N random strategies on signal-free synthetic
  prices. The best will look good. The harness checks it against the
  luck curve so you see what selection alone buys on your equipment.

This is a smoke test under one declared contract, not a validator of
your backtester. The contract is frictionless. Wrap your pipeline with
costs, risk-free adjustments, and nonstandard conventions switched off,
because the fixtures are graded against a frictionless expectation and
the canary cannot tell an honest cost model from a defect. It exercises
only the path from positions to reported Sharpe on synthetic data. A
pass means that narrow path is not provably broken in these ways, and
nothing more.

What it catches, measured on deliberately corrupted pipelines: sign
errors and sign destruction (an abs() around the Sharpe), large
manufactured performance (additive bias beyond the stated dead
tolerance), destroyed signal transmission, and non-finite reports.
What it misses, measured the same way: small additive bias inside the
tolerance, clipping, wrong annualization factors, and moderate
scaling, because Sharpe-level fixtures cannot see them reliably. That
list is why it is called a smoke test.

```python
import numpy as np
from quantproof import run_canary

def my_pipeline(prices, positions):
    # wrap your backtester with costs off; return the annualized Sharpe
    # (this body is the reference frictionless implementation; replace
    # it with a call into your own machinery)
    returns = np.diff(prices) / prices[:-1]
    strategy = positions[:-1] * returns
    std = strategy.std(ddof=1)
    if std == 0.0:
        return 0.0
    return float(strategy.mean() / std * np.sqrt(252.0))

print(run_canary(my_pipeline).summary())
```

### `quantproof.deflate`: what is your Sharpe worth after honesty?

Probabilistic and Deflated Sharpe Ratios (Bailey & López de Prado).
PSR prices track length and fat tails; DSR additionally charges you
for every configuration you looked at before keeping this one.

```python
from quantproof import deflated_sharpe

verdict = deflated_sharpe(daily_returns, n_trials=140)
print(verdict["deflated_sharpe_probability"], verdict["passes_95"])
```

### `quantproof.luck`: the luck curve

The expected best Sharpe from N skill-less trials, at every N.
And `trials_to_explain(your_sharpe, n_obs)`, which computes how many
trials of pure luck it would take to match a track record.

## What you need to bring

The suite degrades gracefully down a ladder of what you actually have:

| You have | What works |
|---|---|
| Nothing but a backtester | The canary. It generates its own synthetic data; you bring only your pipeline. |
| One return series + an honest count of what you tried | The deflated Sharpe and the luck margin: the core verdict. |
| Just a claimed Sharpe, a track length, and a trial count (say, a vendor's ad) | The luck curve and `trials_to_explain`: enough to price whether the claim is even interesting. |
| Every trial kept | The full picture, including overfitting analysis (PBO, in the paid tier). |

Two honest notes. Short tracks widen every error bar, and the tools say
so: below 60 observations `deflated_sharpe` reports
`sufficient_evidence: False` and refuses to pass the track, because
"not enough data yet" is a real answer. And the more trial records you
keep, the more the suite can do: keep every trial, not just the winner.

## What QuantProof does NOT do

Honesty about the tools themselves:

- The canary is a smoke test of the positions-to-Sharpe path under a
  frictionless contract. It does not validate your **data** (splits,
  survivorship, stale quotes), your fills, or strategy logic it never
  runs, and it cannot detect corruption that only activates outside
  its fixtures.
- DSR assumes you report `n_trials` honestly, meaning every variant
  you *looked at*, not just the ones you kept. Undercounting buys
  false comfort.
- The default deflation hurdle uses the independent zero-skill special
  case (sigma = sqrt(1/T)). If the Sharpe dispersion across your real
  trials is wider, that default understates the hurdle; pass
  `trial_sr_std` measured from your trials whenever you have them.
- The math assumes returns stationary enough for sample moments to
  mean something. Below 60 observations the probability is still
  returned, but it is not decision grade. The result carries
  `sufficient_evidence: False` and `passes_95` is forced False no
  matter how high the number reads.
- The probabilities are independence-based approximations. Serial
  dependence in returns and correlation between trials both make the
  reported confidence overstate the truth; neither is corrected for
  here.
- A passing grade means "not provably broken in these ways". That is
  necessary, never sufficient. Nothing here predicts returns, and
  nothing here is investment advice.

## Install

```
pip install quantproof
```

Depends on numpy only. Python 3.9+.

## The pro tier

The free core answers whether the number is luck. QuantProof Pro adds
the two instruments serious review demands:

- PBO, the probability of backtest overfitting, computed by combinatorially
  symmetric cross-validation over your full trial matrix.
- The certificate, a single self-contained HTML evidence report. It shows
  what was tested, the numbers, and which evidence is missing, and it is
  self-issued and says so on its face.

One-time license: https://quantproof.gumroad.com/l/quantproof-pro

## The QuantProof line

Part of the QuantProof line. All tools: https://quantproof.gumroad.com
Free core: https://pypi.org/project/quantproof/ (pip install quantproof)
