pub struct Backtest { /* private fields */ }Expand description
The replay engine itself. Configure via BacktestConfig, attach a
Brain and one or more candle series, then .run().await for the
result.
§Example
use rustrade_backtest::{Backtest, BacktestConfig, load_csv};
let candles = load_csv("data/btcusdt-1m.csv")?;
let result = Backtest::new(
BacktestConfig::builder()
.symbol("BTCUSDT")
.initial_cash(10_000.0)
.build()?,
brain,
)
.with_candles(candles)
.run()
.await?;
println!("{}", result.summary());Implementations§
Source§impl Backtest
impl Backtest
Sourcepub fn new(config: BacktestConfig, brain: Arc<dyn Brain>) -> Self
pub fn new(config: BacktestConfig, brain: Arc<dyn Brain>) -> Self
Construct with a config + brain. The candle series is attached
separately via Self::with_candles / Self::with_symbol_candles.
Sourcepub fn with_candles(self, candles: Vec<Candle>) -> Self
pub fn with_candles(self, candles: Vec<Candle>) -> Self
Feed a candle series for the (single) symbol on the config.
Convenience wrapper around Self::with_symbol_candles.
Panics if the config has more than one symbol — use
Self::with_symbol_candles for multi-symbol backtests.
Sourcepub fn with_symbol_candles(
self,
symbol: impl Into<Symbol>,
candles: Vec<Candle>,
) -> Self
pub fn with_symbol_candles( self, symbol: impl Into<Symbol>, candles: Vec<Candle>, ) -> Self
Feed a candle series for a specific symbol. Call multiple times for multi-symbol backtests; repeated calls for the same symbol replace the previous series.
The engine merges all series chronologically before replay, so the brain sees the global event stream — not per-symbol blocks.
Sourcepub async fn run(self) -> Result<BacktestResult>
pub async fn run(self) -> Result<BacktestResult>
Run the backtest to completion. Returns the aggregated result.