pub struct TailRatio { /* private fields */ }Expand description
Tail Ratio over a trailing window of period returns.
TailRatio = P95(returns) / |P5(returns)|The Tail Ratio contrasts the magnitude of the best outcomes against the worst:
the 95th percentile of the return distribution divided by the absolute value of
the 5th percentile. A value above 1.0 means the right tail (upside surprises)
is fatter than the left tail (downside surprises); below 1.0 means crashes are
larger than rallies. It is a distribution-shape statistic, distinct from the
average-based SharpeRatio: two series with the same mean
and variance can have very different tail ratios.
Percentiles are computed by linear interpolation over the sorted window
(the same rule NumPy uses by default). A window whose 5th percentile is exactly
zero has no measurable left tail and the indicator 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, TailRatio};
let mut indicator = TailRatio::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 Indicator for TailRatio
impl Indicator for TailRatio
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 TailRatio
impl RefUnwindSafe for TailRatio
impl Send for TailRatio
impl Sync for TailRatio
impl Unpin for TailRatio
impl UnsafeUnpin for TailRatio
impl UnwindSafe for TailRatio
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