pub struct BacktestEngine { /* private fields */ }Expand description
Backtest execution engine.
Handles indicator pre-computation, position management, and trade execution.
Implementations§
Source§impl BacktestEngine
impl BacktestEngine
Sourcepub fn new(config: BacktestConfig) -> Self
pub fn new(config: BacktestConfig) -> Self
Create a new backtest engine with the given configuration
Sourcepub fn run<S: Strategy>(
&self,
symbol: &str,
candles: &[Candle],
strategy: S,
) -> Result<BacktestResult>
pub fn run<S: Strategy>( &self, symbol: &str, candles: &[Candle], strategy: S, ) -> Result<BacktestResult>
Run a backtest with the given strategy on historical candle data.
Dividend income is not included. Use run_with_dividends to account
for dividend payments during holding periods.
Sourcepub fn run_with_dividends<S: Strategy>(
&self,
symbol: &str,
candles: &[Candle],
strategy: S,
dividends: &[Dividend],
) -> Result<BacktestResult>
pub fn run_with_dividends<S: Strategy>( &self, symbol: &str, candles: &[Candle], strategy: S, dividends: &[Dividend], ) -> Result<BacktestResult>
Run a backtest and credit dividend income for any dividends paid while a position is open.
dividends should be sorted by timestamp (ascending). The engine credits
each dividend whose ex-date falls on or before the current candle bar.
When BacktestConfig::reinvest_dividends is true, the income is also
used to notionally purchase additional shares at the ex-date close price.
Sourcepub fn run_with_benchmark<S: Strategy>(
&self,
symbol: &str,
candles: &[Candle],
strategy: S,
dividends: &[Dividend],
benchmark_symbol: &str,
benchmark_candles: &[Candle],
) -> Result<BacktestResult>
pub fn run_with_benchmark<S: Strategy>( &self, symbol: &str, candles: &[Candle], strategy: S, dividends: &[Dividend], benchmark_symbol: &str, benchmark_candles: &[Candle], ) -> Result<BacktestResult>
Run a backtest and compare against a benchmark, optionally crediting dividends.
The result’s benchmark field is populated with buy-and-hold comparison
metrics including alpha, beta, and information ratio. The benchmark candle
slice should cover the same time period as candles but need not be the
same length.
dividends must be sorted ascending by timestamp. Pass &[] to omit
dividend processing.
Auto Trait Implementations§
impl Freeze for BacktestEngine
impl !RefUnwindSafe for BacktestEngine
impl Send for BacktestEngine
impl Sync for BacktestEngine
impl Unpin for BacktestEngine
impl UnsafeUnpin for BacktestEngine
impl !UnwindSafe for BacktestEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more