Architecture
CRITERION System Architecture
Section titled “CRITERION System Architecture”This document describes how CRITERION fits together: its module structure, data flow, and artifact chain.
Module Structure
Section titled “Module Structure”CRITERION is organized into domain modules under src/criterion/:
- cli — Command-line interface; all user-facing commands
- config — Configuration models (
RootConfig, strategy engines, overfitting safeguards) - engines — Strategy engines (expansion, reversion, continuation) implementing doctrine
- io — Input/output models:
RunManifestV1,ExecutionBundleV1,TradeRecordV1,EvaluationResultV1 - audit — Shareability validation (
check_shareability, ShareabilityCheckResultV1) - sharing — Shareable pack creation and loading
- analysis — Complexity budget, OOS validation, walk-forward, parameter inventory
- backtest — Equity curves, risk metrics, attribution, reports
- data — Market data sources, caching, validation
- portfolio — Position sizing, rebalancing, constraints
- live_trading / paper_trading — Execution and broker adapters
Data Flow
Section titled “Data Flow”Configuration flows through engines to artifacts:
- config.yaml — Root config (strategy engines, overfitting safeguards, broker, data sources)
- Run — Execution produces
run_manifest.jsonandexecution_bundle.json - RunManifestV1 — Run metadata, git provenance, artifacts inventory, optional execution records
- ExecutionBundleV1 — Daily state, trade records, evaluation log, data period
- TradeRecordV1 — Per-trade structure with entry, exit, rule_provenance
- ShareablePackV1 — Sanitized bundle + strategy config excerpt for public sharing
Artifact Chain
Section titled “Artifact Chain”config.yaml → RunManifestV1 (run metadata, artifacts) → ExecutionBundleV1 (trades, evaluation_log, data_period) → TradeRecordV1 (with rule_provenance) → ShareablePackV1 (credentials stripped)Live Execution Pipeline
Section titled “Live Execution Pipeline”The criterion run live path produces the same artifact quality as backtest runs:
- Engine execution — Expansion, Reversion, Continuation engines run on market data
- Exit checker — Existing positions in
open_positions.jsonare evaluated for stop/target/max-hold; closed positions becomeTradeRecordV1 - Candidate bridge — New engine candidates are converted to
OpenPositionV1(viacandidate_to_open_position) - Position ledger —
open_positions.jsonis updated with still-open and newly opened positions - Bundle population —
ExecutionBundleV1is populated with trade records (exits + new entries),evaluation_log,data_period - Journal —
trade_journal.mdis rendered and written alongside the bundle
Artifacts produced: run_manifest.json, execution_bundle.json, daily_state.md, run_summary.md, trade_journal.md. The position ledger (open_positions.json) lives in --positions-dir (default: sibling positions/ of the run output directory).
Contract Snapshots
Section titled “Contract Snapshots”Pydantic models that define the public contract are registered in criterion.contracts.snapshot. Schema snapshots live in contracts/snapshots/. Any change to a model requires regenerating snapshots:
python -m criterion.contracts.snapshot --writeCLI Command Surface
Section titled “CLI Command Surface”- run — Execute a backtest or dry run; emits run_manifest.json and execution_bundle.json
- validate-run — Verify schema, run_id consistency, artifact hashes
- audit — Shareability check (schema, integrity, min days/trades, rule provenance, evaluation log)
- backtest — Build equity curve, risk metrics, attribution, trade journal
- share — Create a shareable pack from bundle + config (or
share loadto load) - compare — Compare backtest vs paper/live bundles
- query — “Why this trade?” or “Why not?” (requires evaluation_log)
- oos-validate — In-sample / out-of-sample validation
- walk-forward — Walk-forward validation folds
- sensitivity — Parameter sensitivity analysis
- regime-breakdown — Regime performance breakdown report
- dashboard — Interactive HTML dashboard
- doctor — Environment sanity checks; optional
--bundleand--positions-dirfor live pipeline integrity (warns on empty bundle with open positions from earlier runs)