Compact project context for LLMs and automation agents working in this repository.
This repository is a research-oriented futures backtesting platform with three main workflows:
- single-strategy backtests
- walk-forward optimization
- portfolio backtests with shared capital
The active analytics UI is the FastAPI terminal UI in src/backtest_engine/runtime/terminal_ui/.
Read these first:
README.mddocs/ARCHITECTURE.mddocs/MODULE_MAP.md
Read USAGE.md only when the task touches CLI help text, command examples, or onboarding docs.
If dev_context/ exists locally and the task touches architecture, data
pipelines, strategy design, optimization, risk modeling, runtime safety,
observability, or project bootstrap work, read dev_context/README.md first
and then only the relevant documents it points to.
dev_context/CLEAN_CODE_MCP.md and dev_context/QUANT_FRAMEWORK_MCP.md are the
main universal references. Use topic-specific files from dev_context/ only
when they match the task.
- strategy observes
bar[t] - generated orders fill at
open[t+1] - do not introduce lookahead through manual shifts or future-index access
run.pyparses argsrun.pystays thin and delegates parser/runtime helpers intocli/cli/adapts args to servicesservices/orchestrates use cases- engines execute bar-by-bar logic
runtime/terminal_ui/serves artifacts and analytics views
- canonical shared runtime configuration lives in
src/backtest_engine/config/ - do not scatter new magic numbers through engines or services
There are two different engines:
BacktestEngine- single strategy, single primary symbol
- used by standard backtests and by WFO
PortfolioBacktestEngine- multiple slots, multiple symbols, shared capital, allocator, scheduler, portfolio book
- used by portfolio runs and scenario reruns
If a change depends on allocation, rebalancing, slot coordination, or unified timelines, it belongs in the portfolio layer, not in the single engine.
The active UI/runtime is src/backtest_engine/runtime/terminal_ui/.
Rules:
service.pyis the runtime-facing data and artifact layerroutes_*.pystay thin- builders return payloads, not app-level orchestration
- templates and static assets are terminal UI specific
- shared chart/request helpers live in
static/charts_shared.js
Do not reintroduce legacy dashboard assumptions into docs or code.
Canonical strategy IDs and aliases live in src/strategies/registry.py; only strategies registered there are exposed to the CLI and portfolio YAML loaders.
Strategies still follow a legacy contract:
class BaseStrategy:
def __init__(self, engine): ...Implications:
- indicators should be precomputed in
__init__ on_bar()should stay lightweight- portfolio mode uses adapters to support this contract
- reusable strategy filters live under
src/strategies/filters/
- new CLI mode or CLI adapter behavior ->
run.py,cli/ - CLI examples / help text / onboarding commands ->
USAGE.md,cli/main_parser.py - reusable workflow logic ->
src/backtest_engine/services/ - execution semantics ->
src/backtest_engine/execution/,single_asset/, orportfolio_layer/ - artifacts, metrics, report serialization ->
src/backtest_engine/analytics/ - strategy implementations ->
src/strategies/ - UI payloads or routes ->
src/backtest_engine/runtime/terminal_ui/ - cross-cutting repo docs ->
README.md,CONTRIBUTING.md,docs/
- Prefer small, local changes.
- Add tests when behavior changes.
- Update nearby docs when public behavior or module ownership changes.
- Keep comments and docs in English.
- Avoid speculative abstractions.
src/backtest_engine/config/README.mdsrc/backtest_engine/execution/README.mdsrc/backtest_engine/single_asset/README.mdsrc/backtest_engine/analytics/README.mdsrc/backtest_engine/optimization/README.mdsrc/backtest_engine/portfolio_layer/README.mdsrc/backtest_engine/runtime/README.mdtests/README.mdUSAGE.md