Skip to main content

BacktestConfig

Struct BacktestConfig 

Source
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: f64

Starting cash balance in quote currency. Shared across all symbols — there’s a single equity curve.

§sizing: SizingConfig

Sizing config — how the brain’s Decision becomes a contract count. Same struct used by the live ExecutionService.

§slippage: SlippageModel

Slippage policy applied to every fill.

§fees: FeeModel

Fee schedule applied to every fill.

§contract_value: f64

Base-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: f64

Per-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: u32

Annualisation 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

Source

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

Trait Implementations§

Source§

impl Clone for BacktestConfig

Source§

fn clone(&self) -> BacktestConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BacktestConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more