pub struct MaxDrawdown { /* private fields */ }Expand description
Rolling Maximum Drawdown — the deepest peak-to-trough decline within the trailing window.
The input is treated as an equity-curve sample (or any non-negative value
series). For each bar the indicator computes the largest fractional decline
from any prior peak inside the trailing period-bar window:
drawdown_t = (equity_t − peak_t) / peak_t (a negative number)
MaxDrawdown = min(drawdown_t over window) (most-negative value)Output is the magnitude of the worst drawdown as a non-negative fraction
(0.20 = 20 % drop from peak). A monotonically rising equity curve has a
max drawdown of 0. Setting period greater than or equal to the number of
bars you will ever feed makes the metric effectively cumulative — the
indicator never forgets the global peak.
Each update is amortised O(1): the running peak is tracked with a
monotonically-decreasing deque.
§Example
use wickra_core::{Indicator, MaxDrawdown};
let mut mdd = MaxDrawdown::new(10).unwrap();
// Equity peaks at 110 then drops to 88 — a 20% drawdown.
for v in [100.0, 110.0, 100.0, 95.0, 88.0, 90.0, 92.0, 95.0, 100.0, 105.0] {
mdd.update(v);
}
assert!((mdd.update(106.0).unwrap() - 0.20).abs() < 1e-9);Implementations§
Source§impl MaxDrawdown
impl MaxDrawdown
Trait Implementations§
Source§impl Clone for MaxDrawdown
impl Clone for MaxDrawdown
Source§fn clone(&self) -> MaxDrawdown
fn clone(&self) -> MaxDrawdown
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MaxDrawdown
impl Debug for MaxDrawdown
Source§impl Indicator for MaxDrawdown
impl Indicator for MaxDrawdown
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: f64) -> Option<f64>
Feed one new data point into the indicator and return the freshly computed
output, or
None if the indicator is still warming up.Source§fn reset(&mut self)
fn reset(&mut self)
Reset all internal state, leaving the indicator equivalent to a freshly
constructed instance with the same parameters.
Source§fn warmup_period(&self) -> usize
fn warmup_period(&self) -> usize
Number of inputs required before the first non-
None output can be produced.Auto Trait Implementations§
impl Freeze for MaxDrawdown
impl RefUnwindSafe for MaxDrawdown
impl Send for MaxDrawdown
impl Sync for MaxDrawdown
impl Unpin for MaxDrawdown
impl UnsafeUnpin for MaxDrawdown
impl UnwindSafe for MaxDrawdown
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>>
Run the indicator over a slice of inputs in order, returning one output (or
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
Mutably borrows from an owned value. Read more
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>
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 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>
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