pub struct BacktestEngine { /* private fields */ }
Expand description
Core backtesting engine for running event-driven strategy backtests on historical data.
The BacktestEngine
provides a high-fidelity simulation environment that processes
historical market data chronologically through an event-driven architecture. It maintains
simulated exchanges with realistic order matching and execution, allowing strategies
to be tested exactly as they would run in live trading:
- Event-driven data replay with configurable latency models.
- Multi-venue and multi-asset support.
- Realistic order matching and execution simulation.
- Strategy and portfolio performance analysis.
- Seamless transition from backtesting to live trading.
Implementations§
Source§impl BacktestEngine
impl BacktestEngine
Sourcepub fn new(config: BacktestEngineConfig) -> Result<Self>
pub fn new(config: BacktestEngineConfig) -> Result<Self>
Create a new BacktestEngine
instance.
§Errors
Returns an error if the core NautilusKernel
fails to initialize.
Sourcepub fn add_venue(
&mut self,
venue: Venue,
oms_type: OmsType,
account_type: AccountType,
book_type: BookType,
starting_balances: Vec<Money>,
base_currency: Option<Currency>,
default_leverage: Option<Decimal>,
leverages: HashMap<InstrumentId, Decimal>,
modules: Vec<Box<dyn SimulationModule>>,
fill_model: FillModel,
fee_model: FeeModelAny,
latency_model: Option<LatencyModel>,
routing: Option<bool>,
frozen_account: Option<bool>,
reject_stop_orders: Option<bool>,
support_gtd_orders: Option<bool>,
support_contingent_orders: Option<bool>,
use_position_ids: Option<bool>,
use_random_ids: Option<bool>,
use_reduce_only: Option<bool>,
use_message_queue: Option<bool>,
bar_execution: Option<bool>,
bar_adaptive_high_low_ordering: Option<bool>,
trade_execution: Option<bool>,
) -> Result<()>
pub fn add_venue( &mut self, venue: Venue, oms_type: OmsType, account_type: AccountType, book_type: BookType, starting_balances: Vec<Money>, base_currency: Option<Currency>, default_leverage: Option<Decimal>, leverages: HashMap<InstrumentId, Decimal>, modules: Vec<Box<dyn SimulationModule>>, fill_model: FillModel, fee_model: FeeModelAny, latency_model: Option<LatencyModel>, routing: Option<bool>, frozen_account: Option<bool>, reject_stop_orders: Option<bool>, support_gtd_orders: Option<bool>, support_contingent_orders: Option<bool>, use_position_ids: Option<bool>, use_random_ids: Option<bool>, use_reduce_only: Option<bool>, use_message_queue: Option<bool>, bar_execution: Option<bool>, bar_adaptive_high_low_ordering: Option<bool>, trade_execution: Option<bool>, ) -> Result<()>
§Errors
Returns an error if initializing the simulated exchange for the venue fails.
pub fn change_fill_model(&mut self, venue: Venue, fill_model: FillModel)
Sourcepub fn add_instrument(&mut self, instrument: InstrumentAny) -> Result<()>
pub fn add_instrument(&mut self, instrument: InstrumentAny) -> Result<()>
Adds an instrument to the backtest engine for the specified venue.
§Errors
Returns an error if:
- The instrument’s associated venue has not been added via
add_venue
. - Attempting to add a
CurrencyPair
instrument for a single-currency CASH account.
§Panics
Panics if adding the instrument to the simulated exchange fails.
pub fn add_data( &mut self, data: Vec<Data>, client_id: Option<ClientId>, validate: bool, sort: bool, )
pub fn add_actor(&mut self)
pub fn add_actors(&mut self)
pub fn add_strategy(&mut self)
pub fn add_strategies(&mut self)
pub fn add_exec_algorithm(&mut self)
pub fn add_exec_algorithms(&mut self)
pub fn reset(&mut self)
pub fn clear_data(&mut self)
pub fn clear_strategies(&mut self)
pub fn clear_exec_algorithms(&mut self)
pub fn dispose(&mut self)
pub fn run(&mut self)
pub fn end(&mut self)
pub fn get_result(&self)
pub fn next(&mut self)
pub fn advance_time(&mut self)
pub fn process_raw_time_event_handlers(&mut self)
pub fn log_pre_run(&self)
pub fn log_run(&self)
pub fn log_post_run(&self)
pub fn add_data_client_if_not_exists(&mut self)
pub fn add_market_data_client_if_not_exists(&mut self, venue: Venue)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BacktestEngine
impl !RefUnwindSafe for BacktestEngine
impl !Send for BacktestEngine
impl !Sync for BacktestEngine
impl Unpin 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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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