Skip to main content

BacktestResult

Struct BacktestResult 

Source
pub struct BacktestResult {
Show 15 fields pub symbol: String, pub initial_cash: f64, pub final_cash: f64, pub net_pnl: f64, pub total_fees: f64, pub candles_processed: usize, pub signals_emitted: usize, pub orders_filled: usize, pub orders_blocked: usize, pub trades: Vec<TradeOutcome>, pub max_drawdown: f64, pub equity_curve: Vec<f64>, pub period_returns: Vec<f64>, pub risk_free_rate: f64, pub periods_per_year: u32,
}
Expand description

Final outcome of a crate::Backtest::run call.

Fields§

§symbol: String

Symbol the backtest was configured for. For multi-symbol backtests this is a comma-separated list in config order.

§initial_cash: f64

Initial cash balance.

§final_cash: f64

Final cash balance (= initial + net realised PnL).

§net_pnl: f64

Total realised PnL net of fees.

§total_fees: f64

Sum of fees charged across every fill.

§candles_processed: usize

Number of candles fed to the brain.

§signals_emitted: usize

Number of non-Hold decisions emitted by the brain.

§orders_filled: usize

Number of orders the engine placed (may be < signals_emitted if the sizer returned 0 for some signals).

§orders_blocked: usize

Number of non-Hold decisions blocked by a risk gate (the session-PnL halt or the circuit breaker — see crate::BacktestConfig::session_pnl / crate::BacktestConfig::circuit_breaker). Always 0 when no gate is configured.

§trades: Vec<TradeOutcome>

Per-trade outcomes, in chronological order.

§max_drawdown: f64

Maximum peak-to-trough drawdown of equity (cash) over the run, in quote currency. Always <= 0.

§equity_curve: Vec<f64>

Portfolio equity at each sample point. The first element is Self::initial_cash; one additional sample is appended per candle in the merged event stream.

§period_returns: Vec<f64>

Per-period simple returns derived from Self::equity_curve. Length is equity_curve.len() - 1 for any non-empty run.

§risk_free_rate: f64§periods_per_year: u32

Annualisation factor for the Sharpe and Sortino ratios. See crate::BacktestConfig::periods_per_year.

Implementations§

Source§

impl BacktestResult

Source

pub fn total_return_pct(&self) -> f64

Total return as a percentage of initial cash.

Source

pub fn wins(&self) -> usize

Count of trades with net PnL > 0.

Source

pub fn losses(&self) -> usize

Count of trades with net PnL < 0.

Source

pub fn breakevens(&self) -> usize

Count of trades with net PnL == 0.

Source

pub fn win_rate(&self) -> f64

Win rate over decided trades (excludes breakevens), in [0, 1].

Source

pub fn profit_factor(&self) -> Option<f64>

Sum of winning trades’ net PnL / sum of losing trades’ net PnL (positive). None if there are no losing trades.

Source

pub fn sharpe_ratio(&self) -> Option<f64>

Annualised Sharpe ratio of the per-period returns.

Computed as √P · (mean(rᵢ - rf) / stddev(rᵢ)) where rᵢ is each entry in Self::period_returns, rf is Self::risk_free_rate, stddev is the sample standard deviation (N - 1 denominator), and P is Self::periods_per_year.

Returns None when there are fewer than two return samples, or when the sample stddev is zero (a perfectly flat equity curve — Sharpe is undefined).

Source

pub fn sortino_ratio(&self) -> Option<f64>

Annualised Sortino ratio of the per-period returns.

Same shape as Sharpe but only penalises downside deviation — returns below rf contribute to the denominator, returns above rf don’t. Specifically √P · mean(rᵢ - rf) / downside_dev where downside_dev = √(Σ min(rᵢ - rf, 0)² / N). Returns None if no returns are below rf (no downside to measure) or fewer than two samples exist.

Source

pub fn summary(&self) -> String

Pretty-printed multi-line summary suitable for logging.

Trait Implementations§

Source§

impl Clone for BacktestResult

Source§

fn clone(&self) -> BacktestResult

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 BacktestResult

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for BacktestResult

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for BacktestResult

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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