pub struct Expectancy { /* private fields */ }Expand description
Expectancy — the expected return per trade expressed in units of average
loss (the “R-multiple” expectancy) over the last period returns.
mean = average of the `period` returns
avgLoss = average of the absolute losing returns (rᵢ < 0)
E = mean / avgLoss (0 when there are no losing returns)Feed a stream of per-trade or per-bar returns. Expectancy answers “how much
do I make per trade for every unit I typically risk”: E = 0.3 means the
system nets 0.3R per trade on average, where R is the average loss.
Dividing the mean return by the average loss makes the figure comparable
across systems with different bet sizes — unlike the raw mean return (which
is just an SMA of the series). A positive E is a profitable edge, a
negative E a losing one.
When the window contains no losing returns there is no risk reference to
normalise against, so the indicator returns 0 (undefined R-multiple)
rather than dividing by zero.
Each update is O(1): the running sum and the loss aggregates are
maintained incrementally.
§Example
use wickra_core::{BatchExt, Indicator, Expectancy};
let mut indicator = Expectancy::new(4).unwrap();
// returns +2, -1, +2, -1: mean 0.5, avg loss 1 -> E = 0.5.
let out = indicator.batch(&[2.0, -1.0, 2.0, -1.0]);
assert_eq!(out[3], Some(0.5));Implementations§
Trait Implementations§
Source§impl Clone for Expectancy
impl Clone for Expectancy
Source§fn clone(&self) -> Expectancy
fn clone(&self) -> Expectancy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Expectancy
impl Debug for Expectancy
Source§impl Indicator for Expectancy
impl Indicator for Expectancy
Source§fn update(&mut self, ret: f64) -> Option<f64>
fn update(&mut self, ret: f64) -> Option<f64>
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
None output can be produced.Auto Trait Implementations§
impl Freeze for Expectancy
impl RefUnwindSafe for Expectancy
impl Send for Expectancy
impl Sync for Expectancy
impl Unpin for Expectancy
impl UnsafeUnpin for Expectancy
impl UnwindSafe for Expectancy
Blanket Implementations§
Source§impl<T> BatchExt for Twhere
T: Indicator,
impl<T> BatchExt for Twhere
T: Indicator,
Source§fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
fn batch(&mut self, inputs: &[Self::Input]) -> Vec<Option<Self::Output>>
None during warmup) per input.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> 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