Skip to content
AuthoredWritten by hand against the code; every example on it is executed by the docs checks. No human has reviewed this page yet.

Examples Catalog

Every example below is a file in this repository that you can execute. The point of this page is that you should not have to trust a snippet: each entry names the file, the command that runs it, and what it demonstrates.

All of them need the Python bindings built first — see Python Bindings Setup. The Rust example needs only cargo.

FileRun it withDemonstrates
crates/openquant/examples/research_notebook_smoke.rscargo run -p openquant --example research_notebook_smokeThe minimum Rust path: CUSUM event sampling → max-Sharpe allocation → VaR/ES/CDaR. ~30 lines, asserts its own invariants.
notebooks/python/scripts/run_notebooks.pyjust notebooks-runExecutes every research notebook in a Jupyter kernel and saves their tables and figures; fails on any cell error. CI runs it and checks the committed outputs are current.
notebooks/python/scripts/smoke_all.pyjust notebook-smokePlain-script mirror of the core notebook calls; a quick check that the Python surface works.
experiments/run_pipeline.pyjust exp-runA config-driven pipeline run (experiments/configs/futures_oil_baseline.toml) that writes artifacts to experiments/artifacts.
python/benchmarks/benchmark_pipeline.pyjust py-benchTimes the mid-frequency pipeline over 30 iterations at 2048 bars.
python/benchmarks/benchmark_data_processing.pyjust py-bench-dataTime and throughput of openquant.data loading (CSV and Parquet), cleaning, calendar alignment and quality reporting at 200k rows × 4 symbols. The committed results are on the Performance page.
python/tests/just py-test46 test modules, many of which double as usage examples — test_pipeline_api.py and test_bindings_contract.py are the two worth reading first.

The thirteen notebooks under notebooks/python/ are numbered in reading order, from 01_event_labeling_and_pipeline.ipynb to 14_fracdiff_features_classifier.ipynb (06 was removed; 11 replaces it). Notebooks 09 to 14 are research runbooks, listed under Runbooks below and in the research gallery; 01 to 08 are API tours that claim nothing (see the notebook contract). They are committed with their outputs, and their figures are exported to docs-site/public/figures/notebooks/. All of them run on synthetic data: 09 to 14 read the SYNTHETIC SYN_A..SYN_E sample through openquant.data.fetch, and run on real data only when you pass your own source.

just notebooks-run writes each notebook figure here in both site themes. These two come from 11_meta_labeling_triple_barrier.ipynb and describe SYNTHETIC price paths with a planted signal, not a real market.

Cumulative net log return on a simulated planted-signal path for a moving-average crossover, the crossover filtered by a meta-labeling model, and an oracle filter that knows the hidden regime. Cumulative net log return on a simulated planted-signal path for a moving-average crossover, the crossover filtered by a meta-labeling model, and an oracle filter that knows the hidden regime. Box plots over simulated paths of the precision gain and the net Sharpe ratio gain of meta-labeling over the primary model at three signal strengths, with the oracle's mean gain marked. Box plots over simulated paths of the precision gain and the net Sharpe ratio gain of meta-labeling over the primary model at three signal strengths, with the oracle's mean gain marked.

Studies that state a hypothesis up front and end with a promotion decision, each with a page under Research. The research gallery shows every runbook’s hypothesis, figures, result and decision on one page:

  • Fracdiff: stationarity versus memory — 09_fracdiff_stationarity_memory.ipynb, the FFD d-sweep (AFML Fig. 5.5) on SYNTHETIC data, checked against simulated series of known memory.
  • HRP vs IVP and CLA out of sample — 10_hrp_vs_ivp_cla_oos.ipynb, AFML §16.6’s Monte Carlo on SYNTHETIC data.
  • Triple-barrier labeling and meta-labeling — 11_meta_labeling_triple_barrier.ipynb, primary vs meta-labeled bets in purged k-fold, net of costs, deflated by a trial registry, on SYNTHETIC paths with a planted signal and a no-signal control.
  • CPCV backtest with PSR and deflated Sharpe — 12_cpcv_deflated_sharpe.ipynb, best-of-74 strategy selection judged by CPCV, PSR and DSR on a SYNTHETIC no-signal control and a planted signal.
  • Bet sizing from predicted probabilities — 13_bet_sizing_from_probabilities.ipynb, the pre-registered test of runbook 11’s post hoc finding: AFML Snippets 10.1-10.3 probability sizing against a flat 0.5 meta filter, with every sizing choice registered as a trial, on SYNTHETIC planted-signal paths and no-signal controls.
  • Fracdiff features against returns in a classifier — 14_fracdiff_features_classifier.ipynb, runbook 09’s open question: FFD features against returns and integer differences as purged-CV classifier inputs, net of costs, deflated by a trial registry, on SYNTHETIC paths with a planted signal and no-signal controls.

Worked example: cleaning a messy OHLCV file

Section titled “Worked example: cleaning a messy OHLCV file”

The repository ships a deliberately awful CSV at python/tests/fixtures/ohlcv_us_equities.csv — non-canonical column names, two symbols interleaved, rows out of chronological order, and a duplicated 2024-01-02 bar for AAPL:

Date,Ticker,Open,High,Low,Close,Volume,Adj Close
2024-01-03,AAPL,186.10,187.00,185.50,186.30,5000,186.10
2024-01-01,AAPL,184.00,185.00,183.50,184.80,8000,184.70
2024-01-02,AAPL,185.00,186.20,184.70,185.90,7000,185.80
2024-01-02,AAPL,185.05,186.30,184.60,186.00,7100,185.90
2024-01-01,MSFT,370.10,372.00,369.90,371.50,6000,371.30
2024-01-03,MSFT,372.20,373.10,371.40,372.00,5500,371.90

load_ohlcv canonicalises the header (Date → ts, Ticker → symbol, Adj Close → adj_close), sorts by symbol and timestamp, and drops the duplicate — keeping the last occurrence by default, which is the convention you want when a vendor restates a bar:

from openquant import data
frame, report = data.load_ohlcv(
"python/tests/fixtures/ohlcv_us_equities.csv",
return_report=True,
)
print(frame)
print(report)

Ask for the report whenever the data is not yours. Silent deduplication is how a survivorship or restatement bug gets into a backtest without anyone noticing.

The end-to-end loops are long enough to deserve their own pages, with the stages explained rather than just listed:

If you want to…Go here
See OpenQuant produce a number, onceQuickstart
Understand the Rust APIRust Core Workflow
Understand the Python APIPython Core Workflow
Look up one moduleModules by AFML chapter
Build and test the repoLocal Build Setup

This page works two examples itself. The others live next to the method they exercise, where their output is checked by the docs gates: