Skip to main content

BacktestConfigBuilder

Struct BacktestConfigBuilder 

Source
pub struct BacktestConfigBuilder { /* private fields */ }
Expand description

Builder for BacktestConfig

Implementations§

Source§

impl BacktestConfigBuilder

Source

pub fn initial_capital(self, capital: f64) -> Self

Set initial capital

Source

pub fn commission(self, fee: f64) -> Self

Set flat commission per trade

Source

pub fn commission_pct(self, pct: f64) -> Self

Set commission as percentage of trade value

Source

pub fn slippage_pct(self, pct: f64) -> Self

Set slippage as percentage of price

Source

pub fn position_size_pct(self, pct: f64) -> Self

Set position size as fraction of available equity

Source

pub fn max_positions(self, max: usize) -> Self

Set maximum concurrent positions

Source

pub fn unlimited_positions(self) -> Self

Allow unlimited concurrent positions

Source

pub fn allow_short(self, allow: bool) -> Self

Allow or disallow short selling

Source

pub fn min_signal_strength(self, threshold: f64) -> Self

Set minimum signal strength threshold

Source

pub fn stop_loss_pct(self, pct: f64) -> Self

Set stop-loss percentage (auto-exit if loss exceeds this)

Source

pub fn take_profit_pct(self, pct: f64) -> Self

Set take-profit percentage (auto-exit if profit exceeds this)

Source

pub fn close_at_end(self, close: bool) -> Self

Set whether to close open positions at end of backtest

Source

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%).

Source

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.

Source

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).

Source

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 equity
  • 52.0 — weekly
  • 12.0 — monthly
  • 252.0 * 6.5 (≈ 1638) — hourly (6.5-hour trading day)
Source

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).

Source

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.

Source

pub fn commission_fn<F>(self, f: F) -> Self
where F: Fn(f64, f64) -> f64 + Send + Sync + 'static,

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();
Source

pub fn build(self) -> Result<BacktestConfig>

Build and validate the configuration

Trait Implementations§

Source§

impl Default for BacktestConfigBuilder

Source§

fn default() -> BacktestConfigBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> PlanCallbackArgs for T

Source§

impl<T> PlanCallbackOut for T