pub struct BacktestConfig {
pub symbols: Vec<Symbol>,
pub initial_cash: f64,
pub sizing: SizingConfig,
pub slippage: SlippageModel,
pub fees: FeeModel,
pub contract_value: f64,
pub risk_free_rate: f64,
pub periods_per_year: u32,
pub session_pnl: Option<SessionPnlConfig>,
pub circuit_breaker: Option<CircuitBreakerConfig>,
}Expand description
Configuration for a crate::Backtest.
§Example
use rustrade_backtest::{BacktestConfig, FeeModel, SlippageModel};
let config = BacktestConfig::builder()
.symbol("BTCUSDT")
.initial_cash(10_000.0)
.slippage(SlippageModel::FixedBps(5.0))
.fees(FeeModel::Flat(0.001))
.periods_per_year(252 * 24 * 60) // per-minute Sharpe
.build()
.unwrap();
assert_eq!(config.initial_cash, 10_000.0);
assert_eq!(config.periods_per_year, 252 * 24 * 60);Fields§
§symbols: Vec<Symbol>Symbols the brain trades. For single-symbol backtests this is a
one-element vector; events whose symbol is not in the list are
silently ignored. The engine routes each MarketDataEvent to the
brain with the current position for that symbol.
initial_cash: f64Starting cash balance in quote currency. Shared across all symbols — there’s a single equity curve.
sizing: SizingConfigSizing config — how the brain’s Decision becomes a contract
count. Same struct used by the live ExecutionService.
slippage: SlippageModelSlippage policy applied to every fill.
fees: FeeModelFee schedule applied to every fill.
contract_value: f64Base-asset units per contract. For spot adapters this is 1.0;
futures adapters override per symbol. Multi-symbol backtests
share a single multiplier — for mixed spot/futures portfolios
run each symbol in its own Backtest instance.
risk_free_rate: f64Per-period risk-free rate used by crate::BacktestResult::sharpe_ratio
and crate::BacktestResult::sortino_ratio. Expressed in the same
cadence as the candles — e.g. for daily candles with a 2 % annual
rate set this to 0.02 / 252 ≈ 7.94e-5. Defaults to 0.0.
periods_per_year: u32Annualisation factor for the Sharpe and Sortino ratios. For daily
candles use 252 (trading days), for hourly 24 * 252, for
minute 60 * 24 * 365, etc. Defaults to 252.
session_pnl: Option<SessionPnlConfig>Per-symbol session-PnL halt applied during replay — the same gate
the live ExecutionService checks first. When set, each symbol
gets its own SessionPnl driven by candle time (so the daily
halt rolls over at 00:00 UTC in replay time, not wall time), fed
from every emitted TradeOutcome. Once the net session PnL hits
loss_limit, further non-Hold decisions for that symbol are
blocked (counted in BacktestResult::orders_blocked) until the
next UTC day. None (the default) disables the gate — existing
backtests are unaffected.
circuit_breaker: Option<CircuitBreakerConfig>Per-symbol circuit breaker applied during replay — the live
execution path’s second gate. Sliding-window loss counting and the
cooldown both run on candle time. None (the default)
disables the gate.
Implementations§
Source§impl BacktestConfig
impl BacktestConfig
Sourcepub fn symbol(&self) -> &Symbol
pub fn symbol(&self) -> &Symbol
Convenience accessor for single-symbol configs.
Returns the first (and only) symbol when Self::symbols is a
one-element vector. Panics on empty or multi-symbol configs —
callers that mix scopes should use Self::symbols directly.
Source§impl BacktestConfig
impl BacktestConfig
Sourcepub fn builder() -> BacktestConfigBuilder
pub fn builder() -> BacktestConfigBuilder
Start a BacktestConfigBuilder.
Trait Implementations§
Source§impl Clone for BacktestConfig
impl Clone for BacktestConfig
Source§fn clone(&self) -> BacktestConfig
fn clone(&self) -> BacktestConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more