Skip to main content

StrategyPerformance

Struct StrategyPerformance 

Source
#[non_exhaustive]
pub struct StrategyPerformance {
Show 23 fields pub closed_trades: usize, pub open_trades: usize, pub winning_trades: usize, pub losing_trades: usize, pub net_profit: f64, pub net_profit_fraction: Option<f64>, pub gross_profit: f64, pub gross_loss: f64, pub total_fees: f64, pub profit_factor: Option<f64>, pub win_rate: Option<f64>, pub average_trade: Option<f64>, pub largest_winning_trade: Option<f64>, pub largest_losing_trade: Option<f64>, pub max_consecutive_wins: usize, pub max_consecutive_losses: usize, pub max_drawdown: Option<f64>, pub max_drawdown_fraction: Option<f64>, pub sharpe_ratio: Option<f64>, pub sortino_ratio: Option<f64>, pub periods_per_year: Option<f64>, pub skipped_trades: usize, pub skipped_equity_points: usize,
}
Expand description

Metrics of a StrategyReport, from StrategyReport::performance.

Fractions throughout: 0.4 is a 40% win rate. A metric that is undefined for the run is None, never 0 or infinity, and no Option metric is ever NaN or infinite. The sums add finite values and are finite unless they exceed the range of f64.

Trade metrics use the closed valid trades, with p the net profit of each. Curve metrics use the usable equity curve: the points with a finite value, provided they are in strictly increasing time order. A curve out of order is unusable as a whole, so the curve metrics are None rather than computed on part of it.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§closed_trades: usize

Valid trades with an exit.

§open_trades: usize

Valid trades without an exit. They enter no trade metric; their value is in the equity curve.

§winning_trades: usize

Closed trades with p > 0.

§losing_trades: usize

Closed trades with p < 0. A breakeven trade is neither a winner nor a loser.

§net_profit: f64

Sum of p; 0 without closed trades.

§net_profit_fraction: Option<f64>

net_profit / initial_capital. None when the initial capital is not positive and finite.

§gross_profit: f64

Sum of p over the winners.

§gross_loss: f64

Sum of -p over the losers, a positive number.

§total_fees: f64

Sum of the fees of the closed trades, already included in net_profit.

§profit_factor: Option<f64>

gross_profit / gross_loss. None without a losing trade.

§win_rate: Option<f64>

winning_trades / closed_trades, breakeven trades included in the denominator. None without closed trades.

§average_trade: Option<f64>

net_profit / closed_trades. None without closed trades.

§largest_winning_trade: Option<f64>

Largest positive net profit, or None without a winning trade.

§largest_losing_trade: Option<f64>

Most negative net profit, or None without a losing trade.

§max_consecutive_wins: usize

Longest winning run in exit-time order; ties keep input order. Breakeven trades break runs; open and invalid trades do not participate.

§max_consecutive_losses: usize

Longest losing run, with the same ordering and breaks as max_consecutive_wins.

§max_drawdown: Option<f64>

The largest fall of equity from its highest earlier point, in money, over the curve from its first point. None without a usable equity point.

§max_drawdown_fraction: Option<f64>

The largest fall of equity as a fraction of its highest earlier point, found separately from max_drawdown, so the two can come from different points. Above 1 when equity falls below zero. None without a usable equity point or when the first point is not positive.

§sharpe_ratio: Option<f64>

Annualised Sharpe ratio: the mean excess return per step of the curve over the sample standard deviation of the returns, times the square root of periods_per_year. Returns are simple returns between consecutive usable points, and the excess is over the risk-free rate per step, (1 + risk_free_rate)^(1 / periods_per_year) - 1. None when periods_per_year is, with fewer than 2 returns, when the returns do not vary beyond rounding (a deviation of at most 16 machine epsilons, as for a curve growing at a constant rate), when equity before the last point is not positive, or when the risk-free rate is not finite or not above -1.

§sortino_ratio: Option<f64>

Annualised Sortino ratio: as sharpe_ratio, over the downside deviation instead, the root mean square of the shortfalls of the returns below the risk-free rate per step, taken over all returns. None when sharpe_ratio is, or when no return falls short.

§periods_per_year: Option<f64>

Steps of the usable curve per year: the number of returns over the span from the first to the last point, in years of 365.25 days. Counting the bars a run actually contains follows the interval and the market’s sessions without configuration.

None unless the curve spans at least 13 weeks. The span leaves out the closed time before the first point and after the last, so a short run overstates the periods per year of a market with sessions: two sessions of 1-minute bars of a stock count about 224,000 a year instead of about 98,000, and the ratios come out about 1.5 times too high. Thirteen weeks contain every weekly closed period (nights, weekends) many times over, so from 13 weeks on the estimate is at most about 6% high, and the ratios about 3%, a small fraction of the sampling error of a ratio measured over a quarter.

§skipped_trades: usize

Invalid trades, left out of every metric (see StrategyTrade).

§skipped_equity_points: usize

Equity points with a non-finite value, or every point when the curve is not in strictly increasing time order.

Trait Implementations§

Source§

impl Clone for StrategyPerformance

Source§

fn clone(&self) -> StrategyPerformance

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StrategyPerformance

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StrategyPerformance

Source§

fn default() -> StrategyPerformance

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

impl PartialEq for StrategyPerformance

Source§

fn eq(&self, other: &StrategyPerformance) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for StrategyPerformance

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> MaybeSend for T
where T: Send + Sync + ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.