run.py
-> cli/
-> services/
-> single_asset/
-> portfolio_layer/
-> analytics/
-> data/
runtime/terminal_ui/
-> services/
-> analytics/shared/
-> static/charts_shared.js
- Canonical home for runtime settings models.
- Split by bounded concern:
backtest.pyfor engine/data/execution/batch settingsterminal_ui.pyfor runtime UI settingsscenario.pyfor scenario-engine defaults
- Shared execution kernel.
- Owns
Order,Fill,Trade,ExecutionHandler,OrderBook, spread logic, and time/session controls. - Used by the single-asset engine directly and by the portfolio engine through bridge semantics.
- Canonical single-strategy, single-primary-symbol event loop.
- Used by standard backtests and walk-forward runs.
- Shared-capital, multi-slot portfolio engine.
- Owns allocation, scheduling, portfolio book, bridge execution flow, and portfolio artifact generation.
- This package is a separate bounded context, not an extension method on the single engine.
- Canonical orchestration layer between CLI/runtime adapters and engines.
- Safe place for artifact lookup, scenario metadata handling, workflow assembly, and run-service composition.
- Metrics, reports, artifact exporters, and shared analytics transforms.
- The terminal UI consumes analytics outputs and saved artifacts; it is not the analytics source of truth.
- Runtime-facing delivery surfaces.
runtime/terminal_ui/is the active FastAPI analytics runtime for saved artifacts.- Keep runtime code focused on HTTP, rendering, and dependency composition.
- Walk-forward optimization and Optuna orchestration.
- Depends on the single-asset engine and service-layer workflows, not on the terminal UI.
| Caller | Can Import | Should Not Import |
|---|---|---|
run.py, cli/ |
services.*, dashboard launcher helpers |
engine internals, analytics implementation details |
services/ |
engines, analytics exporters, data, config | HTTP handlers, templates, CLI parsing |
runtime/terminal_ui/ |
services.*, analytics.shared.*, config |
CLI modules, engine event-loop internals |
| engines | config, data, strategies, analytics exporters, execution | HTTP, templates, CLI |
- A service launches an engine workflow.
- The engine writes artifacts to disk.
services/artifact_service.pyinspects bundles and loads metadata.services/paths.pyresolves results roots and scenario paths.- The terminal UI loads artifacts through service-layer helpers.
- No-lookahead execution: strategy sees
bar[t], execution starts ont + 1. - Shared-capital portfolio accounting: total equity is cash plus marked-to-market open exposure.
- Strategy constructor contract is still legacy: strategies receive an engine instance.
- We want clean separation, not framework theater.
- Practical shape:
- strategies / alpha in
src/strategies/ - execution and engine physics in
src/backtest_engine/execution/,single_asset/, andportfolio_layer/ - analysis and artifact consumers in
src/backtest_engine/analytics/andruntime/
- strategies / alpha in
- Refactors should preserve behavioral contracts first, then improve folder and import clarity.