Metadata-Version: 2.4
Name: dsr-gate
Version: 0.1.0
Summary: Certifier — an honest backtest gate whose default answer is NO. Deflated-Sharpe + ruin-floor certification.
Author: Rocomas
License: MIT
Project-URL: Homepage, https://github.com/Rocomas/certifier
Project-URL: Demo, https://rocomas.github.io/certifier-demo/
Keywords: backtest,overfitting,deflated-sharpe,quant,trading,validation,PBO,sharpe
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Office/Business :: Financial :: Investment
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.20
Dynamic: license-file

# Certifier — an honest backtest gate whose default answer is **NO**

Most backtest tooling is built to make a strategy look good. This does the opposite:
it is engineered to **reject** a backtest — including its authors' own — unless the
edge survives every discount a skeptical statistician would apply.

Free and MIT-licensed. `numpy` + the Python standard library, nothing else.

## Try it in 30 seconds (browser, nothing uploaded)

**https://rocomas.github.io/certifier-demo/** — the whole gate runs client-side. Click
**Load an overfit**, then **Certify**, and watch the best of 400 pure-noise strategies
get REJECTED.

## What it checks

Feed it a return series and the honest size of the search that produced the strategy.
It returns **CERTIFIED** only if:

1. **Deflated Sharpe ≥ 0.95** (Bailey & López de Prado), deflated for
   - the **best-of-N selection** that produced the edge — a bigger search raises the bar,
   - the return distribution's **skew and kurtosis**,
   - an optional **publication-decay haircut** (`--haircut 0.5` for known anomalies),
   - an optional **overlapping-window correction** (`--overlap-lag h-1`);
2. **it survives a ruin floor** — a $1 book compounding the returns never draws down
   past the floor (default 51%).

Both must hold. Thin samples, overfit selections, decayed edges, and ruinous paths are
all rejected.

## Install

```bash
pip install dsr-gate                 # PyPI name: dsr-gate; import name: certifier
# or straight from source:
pip install git+https://github.com/Rocomas/certifier
```

(The PyPI name `certifier` was already taken by an unrelated TLS package — hence
`dsr-gate`. The module and CLI are both called `certifier`.)

## Use

```bash
certifier returns.csv --trials 200                 # one return per line; exit 0/1 for CI
certifier returns.csv --trials 200 --haircut 0.5 --overlap-lag 4
echo "0.01,0.02,-0.005" | certifier - --trials 50
python -m certifier.webdemo                        # local copy of the browser demo
```

```python
from certifier import certify_returns
res = certify_returns(my_returns, n_trials=200, haircut=0.5, overlap_lag=4)
print(res["verdict"], res["dsr"], res["ruin"]["survives"])
```

## Reproduce the money shot

```bash
python examples/demo.py     # dredges the best of 500 noise trials; the certifier kills it
```

```
overfit   sharpe=+0.17   DSR=0.360/0.95   ruin_ok=True   ->  REJECTED
real      sharpe=+1.96   DSR=1.000/0.95   ruin_ok=True   ->  CERTIFIED
```

Same family of Sharpes, opposite verdicts. `examples/overfit.csv` and `examples/real.csv`
are committed so you can verify from the CLI.

## The honest caveat (and what's coming)

The verdict is only as honest as your `n_trials`. Most researchers genuinely don't know
how many strategies they tried — every discarded variation counts. We're building the
layer that fixes that: a **trial ledger** that hooks your research loop, records every
backtest automatically, and certifies against *counted* trials, not claimed ones — plus a
CI gate and a signed certification report. The calculator here is free forever; the
ledger/workflow layer will be a paid tier. **Watch/star this repo** to hear when it lands.

## What it is not

It does not tune, fit, or optimize anything. A CERTIFIED verdict is a statement about
historical evidence, not investment advice and not a guarantee of future returns.

## License

MIT. Math: Bailey & López de Prado, *The Deflated Sharpe Ratio* (2014), implemented
inline in ~200 lines — audit `certifier/dsr.py` and `certifier/gate.py` yourself.
