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: StringSymbol the backtest was configured for. For multi-symbol backtests this is a comma-separated list in config order.
initial_cash: f64Initial cash balance.
final_cash: f64Final cash balance (= initial + net realised PnL).
net_pnl: f64Total realised PnL net of fees.
total_fees: f64Sum of fees charged across every fill.
candles_processed: usizeNumber of candles fed to the brain.
signals_emitted: usizeNumber of non-Hold decisions emitted by the brain.
orders_filled: usizeNumber of orders the engine placed (may be < signals_emitted
if the sizer returned 0 for some signals).
orders_blocked: usizeNumber 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: f64Maximum 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: f64Per-period risk-free rate used by Self::sharpe_ratio and
Self::sortino_ratio. See crate::BacktestConfig::risk_free_rate.
periods_per_year: u32Annualisation factor for the Sharpe and Sortino ratios. See
crate::BacktestConfig::periods_per_year.
Implementations§
Source§impl BacktestResult
impl BacktestResult
Sourcepub fn total_return_pct(&self) -> f64
pub fn total_return_pct(&self) -> f64
Total return as a percentage of initial cash.
Sourcepub fn breakevens(&self) -> usize
pub fn breakevens(&self) -> usize
Count of trades with net PnL == 0.
Sourcepub fn profit_factor(&self) -> Option<f64>
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.
Sourcepub fn sharpe_ratio(&self) -> Option<f64>
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).
Sourcepub fn sortino_ratio(&self) -> Option<f64>
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.
Trait Implementations§
Source§impl Clone for BacktestResult
impl Clone for BacktestResult
Source§fn clone(&self) -> BacktestResult
fn clone(&self) -> BacktestResult
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more