candlebench answers one question: does a candlestick pattern beat random entry,
after costs, on dates it was not chosen on? Everything below serves that
measurement. stock.py at the repository root is a separate ticker scorer and
shares no code with the package.
bars (alpaca | yfinance | synthetic | ticks)
-> .cache/bars/<source>/<interval>/<SYMBOL>.parquet bars.py
-> sampled (symbol, session) trials, discovery / holdout sampling.py
-> per-session geometry and prior trend patterns/context.py
-> pattern masks (registry applies history + trend gates) patterns/
-> trades and stop-matched random controls engine.py (+ _enginecore.cpp)
-> per-pattern statistics, bootstrap, Holm, verdicts metrics.py
-> RunResult runner.py
-> terminal table, JSON, Parquet trades leaderboard.py, trades.py
-> HTML report, static dashboard, live dashboard report.py, site.py, web/
| Module | Owns |
|---|---|
config.py |
The TOML schema, defaults and validation. Every user value is checked here. |
universe.py |
The built-in 117-symbol list, fixed so a seed reproduces a run. |
bars.py |
Bar sources, download, validation, atomic cache writes, session grouping. alpaca.py, ticks.py and synthetic.py register themselves as sources. |
quotes.py, costs.py |
Observed NBBO half-spreads per symbol and time of day, the bar-based spread estimator, and the fixed fallback. |
sampling.py |
Draws trials from what the cache holds, reserves the chronological holdout, honours run.end_date. |
patterns/ |
The detector registry: 66 patterns in single, double, triple, multi, plus the random controls. Detectors return boolean masks; history and trend gates are applied centrally. |
engine.py |
Signal to closed trade: entry, stop at the pattern's extreme, target, timeout, costs, and the stop-matched controls. _enginecore.cpp is an optional C++ walk held bit-identical to the Python one by tests/test_engine_golden.py. |
metrics.py |
Aggregation, date-clustered bootstrap, Holm correction with a declared experiment count, minimum detectable effects, verdicts. |
runner.py |
Orchestrates one run: discovery, selection, holdout, warnings, provenance. |
walkforward.py |
Repeats the run per fold and tests the pooled out-of-sample trades once. |
signals.py |
Loads a user's own detector file and tests it with the same pipeline (candlebench test). |
trades.py |
The trade frame: pinned dtypes, Parquet I/O, queries, equity curves, breakdowns. |
leaderboard.py, report.py, site.py |
Terminal and JSON output, the self-contained HTML report, the static dashboard export. |
web/ |
The local dashboard server, background jobs and run history. server.py validates every request; --read-only refuses work. |
provenance.py |
Records commit, packages, config hash and data hash with every run. |
- No look-ahead. A detector sees only bars up to its signal bar; the trend gate reads the bar before the pattern starts. Matched controls enter 1-5 bars after their pattern, never before.
- Unavailable is not zero. A statistic that cannot be computed is
Noneand renders asn/a. - Holdout is untouched until discovery has chosen. Only discovery candidates are evaluated on it.
- The static site answers every query exactly as the server does, enforced
by
tests/browser/test_static_site.py. - No prices from licensed data are published. Reports and sites carry R multiples and dates only unless the source is synthetic.
- Credentials come from the environment only, never from config or a browser request.
- Python, NumPy, pandas, PyArrow: vectorised detectors and Parquet caches keep a million-trade run to minutes on one core.
- Optional C++ (pybind11) for the trade walk, built with flags that forbid fused multiply-add so results stay bit-identical to Python.
- No web framework:
http.serverplus one vanilla JS file, so the same page runs against the live server or static JSON files on GitHub Pages. - GitHub Actions: tests on Python 3.11 and 3.12, Chromium tests, Pylint,
wheel and container builds (
ci.yml), the published site (pages.yml), and tagged releases (release.yml).
candlebench fetchandcandlebench quotesfill the cache.candlebench run --config X --json out.jsonfrom a clean commit.- Price-free trades go to the
data-2026-10-08GitHub release; the JSON todocs/results/;candlebench reportwritesdocs/reports/. pages.ymldownloads the trades, rebuilds the dashboards and deploys.
Experiment write-ups that justify each design decision live in
docs/experiments/. DESIGN.md covers the dashboard's visual design.