pub struct CommonSenseRatio { /* private fields */ }Expand description
Common Sense Ratio over a trailing window of period returns.
ProfitFactor = Σ gains / Σ |losses| over the window
TailRatio = P95(returns) / |P5(returns)| over the window
CSR = ProfitFactor · TailRatioThe Common Sense Ratio fuses two views of a return series into one number. The
profit factor captures the body of the distribution —
how much you make per unit you lose on the average bar. The
TailRatio captures the extremes — whether the largest
gains outweigh the largest losses. Multiplying them produces a ratio that is
only comfortably above 1.0 when a strategy wins on both fronts: a respectable
profit factor can still hide catastrophic left-tail risk, and a fat right tail
means little if the body bleeds. Above 1.0 the strategy is sound on a
common-sense basis; below 1.0 something — body or tail — is working against it.
Percentiles use linear interpolation over the sorted window. A window with no
losses (zero profit-factor denominator) or no left tail (zero P5) reports 0.0
rather than dividing by zero.
The first value lands after period returns; each update re-sorts the window
(O(period log period)), which is O(1) in the length of the overall series.
§Example
use wickra_core::{Indicator, CommonSenseRatio};
let mut indicator = CommonSenseRatio::new(20).unwrap();
let mut last = None;
for i in 0..40 {
last = indicator.update((f64::from(i) * 0.3).sin() * 0.02);
}
assert!(last.is_some());Implementations§
Trait Implementations§
Source§impl Clone for CommonSenseRatio
impl Clone for CommonSenseRatio
Source§fn clone(&self) -> CommonSenseRatio
fn clone(&self) -> CommonSenseRatio
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 CommonSenseRatio
impl Debug for CommonSenseRatio
Source§impl Indicator for CommonSenseRatio
impl Indicator for CommonSenseRatio
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 CommonSenseRatio
impl RefUnwindSafe for CommonSenseRatio
impl Send for CommonSenseRatio
impl Sync for CommonSenseRatio
impl Unpin for CommonSenseRatio
impl UnsafeUnpin for CommonSenseRatio
impl UnwindSafe for CommonSenseRatio
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> BatchNanExt for T
impl<T> BatchNanExt for T
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