#[non_exhaustive]pub struct BacktestConfig {
pub initial_capital: f64,
pub commission: f64,
pub commission_pct: f64,
pub slippage_pct: f64,
pub position_size_pct: f64,
pub max_positions: Option<usize>,
pub allow_short: bool,
pub min_signal_strength: f64,
pub stop_loss_pct: Option<f64>,
pub take_profit_pct: Option<f64>,
pub close_at_end: bool,
}Expand description
Configuration for backtest execution.
Use BacktestConfig::builder() to construct with the builder pattern.
§Example
use finance_query::backtesting::BacktestConfig;
let config = BacktestConfig::builder()
.initial_capital(50_000.0)
.commission_pct(0.001)
.slippage_pct(0.0005)
.allow_short(true)
.stop_loss_pct(0.05)
.take_profit_pct(0.10)
.build()
.unwrap();Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.initial_capital: f64Initial portfolio capital in base currency
commission: f64Commission per trade (flat fee)
commission_pct: f64Commission as percentage of trade value (0.0 - 1.0)
slippage_pct: f64Slippage as percentage of price (0.0 - 1.0)
position_size_pct: f64Position sizing: fraction of equity per trade (0.0 - 1.0)
max_positions: Option<usize>Maximum number of concurrent positions (None = unlimited)
allow_short: boolAllow short selling
min_signal_strength: f64Require signal strength threshold to trigger trades (0.0 - 1.0)
stop_loss_pct: Option<f64>Stop-loss percentage (0.0 - 1.0). Auto-exit if loss exceeds this.
take_profit_pct: Option<f64>Take-profit percentage (0.0 - 1.0). Auto-exit if profit exceeds this.
close_at_end: boolClose any open position at end of backtest
Implementations§
Source§impl BacktestConfig
impl BacktestConfig
Sourcepub fn builder() -> BacktestConfigBuilder
pub fn builder() -> BacktestConfigBuilder
Create a new builder
Sourcepub fn calculate_commission(&self, trade_value: f64) -> f64
pub fn calculate_commission(&self, trade_value: f64) -> f64
Calculate commission for a trade value
Sourcepub fn apply_entry_slippage(&self, price: f64, is_long: bool) -> f64
pub fn apply_entry_slippage(&self, price: f64, is_long: bool) -> f64
Apply slippage to a price (for entry)
Sourcepub fn apply_exit_slippage(&self, price: f64, is_long: bool) -> f64
pub fn apply_exit_slippage(&self, price: f64, is_long: bool) -> f64
Apply slippage to a price (for exit)
Sourcepub fn calculate_position_size(&self, available_capital: f64, price: f64) -> f64
pub fn calculate_position_size(&self, available_capital: f64, price: f64) -> f64
Calculate position size based on available capital
Trait Implementations§
Source§impl Clone for BacktestConfig
impl Clone for BacktestConfig
Source§fn clone(&self) -> BacktestConfig
fn clone(&self) -> BacktestConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BacktestConfig
impl Debug for BacktestConfig
Source§impl Default for BacktestConfig
impl Default for BacktestConfig
Source§impl<'de> Deserialize<'de> for BacktestConfig
impl<'de> Deserialize<'de> for BacktestConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for BacktestConfig
impl RefUnwindSafe for BacktestConfig
impl Send for BacktestConfig
impl Sync for BacktestConfig
impl Unpin for BacktestConfig
impl UnsafeUnpin for BacktestConfig
impl UnwindSafe for BacktestConfig
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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