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