pub struct BacktestConfigBuilder { /* private fields */ }Expand description
Builder for BacktestConfig
Implementations§
Source§impl BacktestConfigBuilder
impl BacktestConfigBuilder
Sourcepub fn initial_capital(self, capital: f64) -> Self
pub fn initial_capital(self, capital: f64) -> Self
Set initial capital
Sourcepub fn commission(self, fee: f64) -> Self
pub fn commission(self, fee: f64) -> Self
Set flat commission per trade
Sourcepub fn commission_pct(self, pct: f64) -> Self
pub fn commission_pct(self, pct: f64) -> Self
Set commission as percentage of trade value
Sourcepub fn slippage_pct(self, pct: f64) -> Self
pub fn slippage_pct(self, pct: f64) -> Self
Set slippage as percentage of price
Sourcepub fn position_size_pct(self, pct: f64) -> Self
pub fn position_size_pct(self, pct: f64) -> Self
Set position size as fraction of available equity
Sourcepub fn max_positions(self, max: usize) -> Self
pub fn max_positions(self, max: usize) -> Self
Set maximum concurrent positions
Sourcepub fn unlimited_positions(self) -> Self
pub fn unlimited_positions(self) -> Self
Allow unlimited concurrent positions
Sourcepub fn allow_short(self, allow: bool) -> Self
pub fn allow_short(self, allow: bool) -> Self
Allow or disallow short selling
Sourcepub fn min_signal_strength(self, threshold: f64) -> Self
pub fn min_signal_strength(self, threshold: f64) -> Self
Set minimum signal strength threshold
Sourcepub fn stop_loss_pct(self, pct: f64) -> Self
pub fn stop_loss_pct(self, pct: f64) -> Self
Set stop-loss percentage (auto-exit if loss exceeds this)
Sourcepub fn take_profit_pct(self, pct: f64) -> Self
pub fn take_profit_pct(self, pct: f64) -> Self
Set take-profit percentage (auto-exit if profit exceeds this)
Sourcepub fn close_at_end(self, close: bool) -> Self
pub fn close_at_end(self, close: bool) -> Self
Set whether to close open positions at end of backtest
Sourcepub fn risk_free_rate(self, rate: f64) -> Self
pub fn risk_free_rate(self, rate: f64) -> Self
Set annual risk-free rate for Sharpe/Sortino/Calmar calculations (0.0 - 1.0)
Use the current T-bill rate for accurate ratios (e.g. 0.05 for 5%).
Sourcepub fn trailing_stop_pct(self, pct: f64) -> Self
pub fn trailing_stop_pct(self, pct: f64) -> Self
Set trailing stop percentage (0.0 - 1.0).
For longs: exits when price drops this fraction below its peak since entry. For shorts: exits when price rises this fraction above its trough since entry.
Sourcepub fn reinvest_dividends(self, reinvest: bool) -> Self
pub fn reinvest_dividends(self, reinvest: bool) -> Self
Enable or disable dividend reinvestment
When true, dividend income is reinvested (added to P&L as additional hypothetical shares).
Sourcepub fn bars_per_year(self, n: f64) -> Self
pub fn bars_per_year(self, n: f64) -> Self
Set the number of bars per calendar year for annualisation.
Defaults to 252.0 (US equity daily bars). Common values:
252.0— daily US equity52.0— weekly12.0— monthly252.0 * 6.5(≈ 1638) — hourly (6.5-hour trading day)
Sourcepub fn spread_pct(self, pct: f64) -> Self
pub fn spread_pct(self, pct: f64) -> Self
Set symmetric bid-ask spread as a fraction of price (0.0 – 1.0).
Half the spread is applied adversely on entry and half on exit,
independent of slippage_pct.
For example, 0.0002 represents a 2-basis-point spread (1 bp per side).
Sourcepub fn transaction_tax_pct(self, pct: f64) -> Self
pub fn transaction_tax_pct(self, pct: f64) -> Self
Set the transaction tax as a fraction of trade value, applied on buys only.
Models purchase taxes such as UK Stamp Duty (0.005 = 0.5 %). Applied on long entries and short covers; not applied on sells.
Sourcepub fn commission_fn<F>(self, f: F) -> Self
pub fn commission_fn<F>(self, f: F) -> Self
Set a custom commission function f(size, price) -> commission.
Replaces the flat commission and
percentage commission_pct fields.
Use this to model broker-specific fee schedules.
§Example
use finance_query::backtesting::BacktestConfig;
// $0.005 per share, minimum $1.00 per order
let config = BacktestConfig::builder()
.commission_fn(|size, price| (size * 0.005_f64).max(1.00))
.build()
.unwrap();Sourcepub fn build(self) -> Result<BacktestConfig>
pub fn build(self) -> Result<BacktestConfig>
Build and validate the configuration
Trait Implementations§
Source§impl Default for BacktestConfigBuilder
impl Default for BacktestConfigBuilder
Source§fn default() -> BacktestConfigBuilder
fn default() -> BacktestConfigBuilder
Auto Trait Implementations§
impl Freeze for BacktestConfigBuilder
impl !RefUnwindSafe for BacktestConfigBuilder
impl Send for BacktestConfigBuilder
impl Sync for BacktestConfigBuilder
impl Unpin for BacktestConfigBuilder
impl UnsafeUnpin for BacktestConfigBuilder
impl !UnwindSafe for BacktestConfigBuilder
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