How ceta-research/strategy-backtester works
Purpose and Entry Points
A Python position-level trading research/backtesting system. It runs YAML-configured daily strategies, parameter sweeps, intraday simulations, ensemble evaluation, and selected production trading runners. Primary entry points are run.py (pipeline strategy execution), run_global.py (broader execution), run_remote.py (remote execution), and research drivers such as scripts/backtest_main.py and scripts/cloud_main.py.
Configuration-Driven Strategy Boundary
Strategy behavior is primarily data/configuration rather than bespoke scripts: YAML files select a signal, universe/data settings, ranking, exits, sizing, and sweep dimensions. The engine loads and expands these definitions through engine/config_loader.py and engine/config_sweep.py. Active strategy configurations live under paths such as strategies/eod_breakout/config_champion.yaml, strategies/eod_technical/config_champion.yaml, and strategies/quality_dip_buy/config_champion.yaml; retired strategies are explicitly isolated under strategies/retired/.
Daily Backtest Pipeline
The central control flow is implemented by engine/pipeline.py: load config → retrieve market/fundamental data → generate candidates → scan/filter/rank them → create orders → simulate positions and exits → emit standardized results. Its major stages are separated into engine/data_provider.py, engine/scanner.py, engine/ranking.py, engine/order_generator.py, and engine/simulator.py. This separation makes signal logic independent of capital allocation and execution simulation.
Signal Plugin Layer
Each strategy is represented by a pluggable signal generator, sharing an interface in engine/signals/base.py. Implementations in engine/signals/ encode entry conditions and strategy-specific features, while the common pipeline handles downstream decisions. Representative active implementations include engine/signals/eod_breakout.py, engine/signals/eod_technical.py, and engine/signals/momentum_cascade.py. This is the primary extension boundary for adding a strategy.
Execution, Risk, and Accounting
The simulator operates at position/order level, applying order lifecycle, holding rules, exits, charges, and deterministic identity handling. Core boundaries are engine/simulator.py, engine/exits.py, engine/charges.py, and engine/order_key.py. Internal market-regime logic is encapsulated in engine/internal_regime.py, allowing entry/exposure behavior to change without embedding regime policy in every signal.
Data, Results, and External Infrastructure
Market-data acquisition is abstracted behind engine/data_provider.py and shared fetch/client code in lib/data_fetchers.py and lib/cr_client.py. The documented primary external dependency is the Ceta Research API, authenticated by CR_API_KEY; configurations indicate research across multiple exchanges and alternative data-source comparisons. Results are normalized through lib/backtest_result.py, with equity curves and performance analysis in lib/equity_curve.py, lib/metrics.py, and lib/ensemble_curve.py. Cloud execution is orchestrated through lib/cloud_orchestrator.py and scripts such as scripts/cloud_sweep.py.
Intraday, Ensembles, and Production Paths
Intraday workflows are distinct from the daily pipeline, with dedicated SQL/data construction and simulators in engine/intraday_pipeline.py, engine/intraday_sql_builder.py, and engine/intraday_simulator_v2.py. Ensemble research combines strategy curves according to independent YAML definitions, e.g. strategies/ensembles/convex_max_sharpe_quarterly/config.yaml, executed via scripts/run_ensemble.py. Operational trading runners are separate from research backtests in prod_runner/intraday_breakout_prod.py and prod_runner/open_low_meanrev_prod.py, preserving a boundary between simulation infrastructure and live integration.
Main entry points: pipeline.py Daily pipeline · config_loader.py Config loader · backtest_result.py Normalized results · simulator.py Position simulator
Components 22
Strategy Configuration
YAML definitions drive strategy selection and sweep dimensions.
- Active strategy YAML · Selects signal, universe, ranking, exits, sizing, and sweeps.
strategies/eod_breakout/config_champion.yaml - Retired strategies · Inactive strategies are isolated from active definitions.
- Config loader
engine/config_loader.py - Sweep expansion
engine/config_sweep.py
Daily Backtest Engine
Configurable position-level research pipeline.
- Daily pipeline · Coordinates data, signals, allocation, simulation, and results.
engine/pipeline.py - Data provider
engine/data_provider.py - Data fetchers and CR client · Accesses Ceta Research API and shared market-data fetches.
lib/data_fetchers.py - Signal interface
engine/signals/base.py - Signal plugins · Strategy-specific entry conditions and features.
engine/signals/eod_breakout.py - Scanner
engine/scanner.py - Ranking
engine/ranking.py - Order generator
engine/order_generator.py - Position simulator · Applies order lifecycle, holdings, exits, and charges.
engine/simulator.py - Exits, charges, order identity · Shared position exit, cost, and deterministic order-key rules.
engine/exits.py - Internal regime · Changes entry and exposure behavior independently of signals.
engine/internal_regime.py
Research Variants
Intraday, ensemble, and cloud workflows.
- Intraday pipeline · Dedicated SQL construction and intraday simulator workflow.
engine/intraday_pipeline.py - Ensemble runner · Combines strategy curves from independent ensemble YAML.
scripts/run_ensemble.py - Cloud sweeps
lib/cloud_orchestrator.py
Production Runners
Live execution is separated from backtest infrastructure.
- Production trading runners · Operational runners remain separate from research simulation.
prod_runner/intraday_breakout_prod.py
Other components
- Research entry points · Pipeline, global, remote, and research drivers launch workflows.
run.py - Normalized results
lib/backtest_result.py - Curves and metrics · Builds equity curves, metrics, and ensemble curves.
lib/equity_curve.py
Connections 21
- Research entry points → Config loader: loads
- Active strategy YAML → Config loader: defines strategies
- Config loader → Sweep expansion: expands
- Config loader → Daily pipeline: configures
- Sweep expansion → Daily pipeline: runs variants
- Daily pipeline → Data provider: retrieves data
- Data provider → Data fetchers and CR client: fetches via
- Daily pipeline → Signal plugins: generates candidates
- Signal plugins → Signal interface: implements
- Daily pipeline → Scanner: filters
- Scanner → Ranking: passes candidates
- Ranking → Order generator: prioritizes
- Order generator → Position simulator: creates orders
- Internal regime → Position simulator: adjusts exposure
- Exits, charges, order identity → Position simulator: applies controls
- Position simulator → Normalized results: emits
- Normalized results → Curves and metrics: analyzes
- Research entry points → Cloud sweeps: remote execution
- Normalized results → Ensemble runner: combines curves
- Intraday pipeline → Normalized results: emits results
- Production trading runners → Data provider: separate live data use