pub struct UlcerIndex { /* private fields */ }Expand description
Ulcer Index — Peter Martin’s downside-only volatility / risk measure.
Standard deviation punishes upside and downside moves equally; the Ulcer Index measures only the pain of drawdowns. For each bar it computes the percentage drop from the highest price of the trailing window, squares it, and reports the root-mean-square over the window:
drawdown_t = 100 · (price_t − max(price, period)_t) / max(price, period)_t
UlcerIndex = √( mean( drawdown² over period ) )A pure up-trend never trades below its own running high, so its Ulcer Index
is 0; the deeper and longer the drawdowns, the higher the reading. It is
the volatility measure of choice for risk-adjusted return ratios (the
“Martin ratio” / UPI).
Each update is amortised O(1): the trailing maximum is tracked with a
monotonically-decreasing deque of (index, price) pairs, so the indicator
honours the Indicator trait’s O(1)-per-tick contract even for long
windows.
§Example
use wickra_core::{Indicator, UlcerIndex};
let mut indicator = UlcerIndex::new(14).unwrap();
let mut last = None;
for i in 0..80 {
last = indicator.update(100.0 + (f64::from(i) * 0.3).sin() * 8.0);
}
assert!(last.is_some());Implementations§
Source§impl UlcerIndex
impl UlcerIndex
Trait Implementations§
Source§impl Clone for UlcerIndex
impl Clone for UlcerIndex
Source§fn clone(&self) -> UlcerIndex
fn clone(&self) -> UlcerIndex
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 UlcerIndex
impl Debug for UlcerIndex
Source§impl Indicator for UlcerIndex
impl Indicator for UlcerIndex
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: 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 UlcerIndex
impl RefUnwindSafe for UlcerIndex
impl Send for UlcerIndex
impl Sync for UlcerIndex
impl Unpin for UlcerIndex
impl UnsafeUnpin for UlcerIndex
impl UnwindSafe for UlcerIndex
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