pub struct BacktestExecutor {
pub initial_balance: f64,
pub balance: f64,
pub trade_log: Vec<TradeResult>,
/* private fields */
}Expand description
Simulates trade execution and tracks account balance / P&L.
The executor does not own the TradeEngine — instead it receives
effects and a reference to the engine after each price update or action.
Fields§
§initial_balance: f64Starting account balance.
balance: f64Current account balance (initial + realised P&L).
trade_log: Vec<TradeResult>Per-close trade results collected over the backtest.
Implementations§
Source§impl BacktestExecutor
impl BacktestExecutor
Sourcepub fn new(initial_balance: f64, contract_sizes: HashMap<String, f64>) -> Self
pub fn new(initial_balance: f64, contract_sizes: HashMap<String, f64>) -> Self
Create a new executor with the given starting balance and contract sizes.
contract_sizes maps symbol name → contract size (e.g. 100_000 for forex).
Pass an empty map to get the legacy behaviour (multiplier = 1.0).
Sourcepub fn process_effects(
&mut self,
effects: &[Effect],
engine: &TradeEngine,
quote: &PriceQuote,
)
pub fn process_effects( &mut self, effects: &[Effect], engine: &TradeEngine, quote: &PriceQuote, )
Process a batch of effects produced by the engine.
engine is passed by reference so that the executor can look up
position details (e.g. entry price, side) when recording opens.
quote is the current market price used for close-price calculation.
For close effects the executor resolves the position symbol and prefers the engine’s last known quote for that symbol. This prevents cross-symbol quote contamination in merged multi-symbol feeds.
Sourcepub fn realized_pnl(&self) -> f64
pub fn realized_pnl(&self) -> f64
Realised P&L so far.
Sourcepub fn open_count(&self) -> usize
pub fn open_count(&self) -> usize
Number of tracked open entries.
Trait Implementations§
Source§impl Clone for BacktestExecutor
impl Clone for BacktestExecutor
Source§fn clone(&self) -> BacktestExecutor
fn clone(&self) -> BacktestExecutor
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more