1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! # rustrade-backtest
//!
//! Deterministic backtest engine for [`rustrade_core::Brain`]s. The same
//! `Brain` trait used by `rustrade` for live trading drives the backtest —
//! no special "backtest-mode" code paths in the strategy, no duplicate
//! decision logic to keep in sync.
//!
//! See the crate-level [`README.md`](https://github.com/nuniesmith/rustrade/blob/main/crates/rustrade-backtest/README.md)
//! for a quickstart.
//!
//! # Determinism
//!
//! Given the same `(Brain, Vec<Candle>, BacktestConfig)` inputs the engine
//! produces the same [`BacktestResult`] every run. There is no random
//! number source and no thread interleaving — the loop is single-threaded
//! and synchronous through every step that affects state.
//!
//! # Risk-gate parity with live
//!
//! The live `ExecutionService` blocks decisions behind a per-symbol
//! session-PnL halt and circuit breaker. Thread the same configs through
//! [`BacktestConfig::session_pnl`] / [`BacktestConfig::circuit_breaker`]
//! and the replay engine applies the same gates — driven by **candle
//! time** (the daily halt rolls over at 00:00 UTC in replay time, the
//! breaker's window and cooldown run on candle timestamps), so a brain
//! that relies on live gating backtests the way it trades. Blocked
//! decisions are counted in [`BacktestResult::orders_blocked`]. Both
//! gates default to off.
//!
//! # Status
//!
//! Phase 4b — adds CSV candle loader, Sharpe/Sortino metrics, and
//! multi-symbol replay. Parquet loaders and book-walk slippage remain
//! deferred. See the workspace `TODO.md`.
pub use ;
pub use Backtest;
pub use ;
pub use FeeModel;
pub use ;
pub use TradeOutcome;
pub use BacktestResult;
pub use SlippageModel;