pub struct RunningDrawdown { /* private fields */ }Expand description
Since-inception maximum drawdown, with the current drawdown and running peak.
The input is treated as an equity-curve sample (or any non-negative value
series). Unlike MaxDrawdown, which looks at a
trailing period-bar window, this indicator never forgets: it folds every
value since construction (or the last reset) into three numbers and keeps
them in O(1) memory:
peak_t = max(input over [0..=t])
current_t = (peak_t − input_t) / peak_t (0 while peak_t ≤ 0)
max_t = max(current over [0..=t])update returns the maximum drawdown so far as a non-negative fraction
(0.20 = 20 % drop from peak), the same convention as
MaxDrawdown. A monotonically rising equity curve
has a maximum drawdown of 0. The result equals MaxDrawdown with a
period at least as long as the stream.
There are no parameters and no warmup: a value is emitted from the first
finite input on, and each update is O(1).
§Example
use wickra_core::{Indicator, RunningDrawdown};
let mut dd = RunningDrawdown::new();
assert_eq!(dd.update(100.0), Some(0.0));
// Equity peaks at 110 then drops to 88 — a 20% drawdown.
assert_eq!(dd.update(110.0), Some(0.0));
assert!((dd.update(88.0).unwrap() - 0.20).abs() < 1e-9);
// Recovering shrinks the current drawdown but not the maximum.
dd.update(99.0);
assert!((dd.max_drawdown().unwrap() - 0.20).abs() < 1e-9);
assert!((dd.current_drawdown().unwrap() - 0.10).abs() < 1e-9);
assert_eq!(dd.peak(), Some(110.0));Implementations§
Source§impl RunningDrawdown
impl RunningDrawdown
Sourcepub const fn max_drawdown(&self) -> Option<f64>
pub const fn max_drawdown(&self) -> Option<f64>
Maximum drawdown since the first value, as a non-negative fraction.
Sourcepub const fn current_drawdown(&self) -> Option<f64>
pub const fn current_drawdown(&self) -> Option<f64>
Drawdown of the latest value from the running peak, as a non-negative
fraction (0 at a new peak).
Trait Implementations§
Source§impl Clone for RunningDrawdown
impl Clone for RunningDrawdown
Source§impl Debug for RunningDrawdown
impl Debug for RunningDrawdown
Source§impl Default for RunningDrawdown
impl Default for RunningDrawdown
Source§impl Indicator for RunningDrawdown
impl Indicator for RunningDrawdown
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: f64) -> Option<f64>
None if there is no value for this input. Read moreSource§fn reset(&mut self)
fn reset(&mut self)
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
None output can be produced.Source§fn is_ready(&self) -> bool
fn is_ready(&self) -> bool
Source§fn name(&self) -> &'static str
fn name(&self) -> &'static str
Source§fn batch_nan_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
fn batch_nan_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
Source§fn batch_fast_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
fn batch_fast_into(&mut self, inputs: &[Self::Input], out: &mut [f64])
batch_nan_into, but
an indicator with a vectorised kernel may reassociate its arithmetic to
run it in SIMD lanes. Each value then agrees with the exact batch to within
the tolerance the indicator documents (a few units in the last place), not
bit for bit; warmup positions, NaN placement and the output length are
identical. The kernels are deterministic: the same input produces the same
bits on every platform, with or without SIMD hardware. Read moreAuto Trait Implementations§
impl Freeze for RunningDrawdown
impl RefUnwindSafe for RunningDrawdown
impl Send for RunningDrawdown
impl Sync for RunningDrawdown
impl Unpin for RunningDrawdown
impl UnsafeUnpin for RunningDrawdown
impl UnwindSafe for RunningDrawdown
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§fn batch_nan(&mut self, inputs: &[f64]) -> Vec<f64>
fn batch_nan(&mut self, inputs: &[f64]) -> Vec<f64>
f64 per input, warmup positions filled with NaN, bit-for-bit equal
to replaying update.Source§fn batch_fast(&mut self, inputs: &[f64]) -> Vec<f64>
fn batch_fast(&mut self, inputs: &[f64]) -> Vec<f64>
Indicator::batch_fast_into) into a fresh
vector: within the indicator’s documented tolerance of
batch_nan, deterministic across platforms.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