pub struct MartinRatio { /* private fields */ }Expand description
Martin Ratio — also called the Ulcer Performance Index (UPI) — over a trailing
window of period returns.
equity_t = Π_{i<=t} (1 + return_i) (compounded curve)
peak_t = max_{s<=t} equity_s
dd_t% = 100 · (peak_t − equity_t) / peak_t (percentage drawdown)
UlcerIdx = sqrt( mean( dd_t%² ) )
Martin = mean(returns) / UlcerIdxThe Martin Ratio divides the average per-period return by the Ulcer Index —
the root-mean-square of the percentage drawdowns. The Ulcer Index, by
construction, measures the depth and duration of the time spent under water:
a long shallow slump and a short deep one can score the same. Compared to
Wickra’s other drawdown ratios, Martin uses the RMS (not the average as in the
SterlingRatio, nor the un-normalised sum-norm as in the
BurkeRatio) and expresses drawdowns in percent, so its
denominator is on a 0..100 scale and its output is numerically smaller than
the fractional-drawdown ratios. A window that never draws down has an Ulcer Index
of zero and the indicator reports 0.0.
The first value lands after period returns; each update rebuilds the equity
curve over the window (O(period)), which is O(1) in the length of the overall
series.
§Example
use wickra_core::{Indicator, MartinRatio};
let mut indicator = MartinRatio::new(14).unwrap();
let mut last = None;
for i in 0..28 {
last = indicator.update((f64::from(i) * 0.5).sin() * 0.05);
}
assert!(last.is_some());Implementations§
Trait Implementations§
Source§impl Clone for MartinRatio
impl Clone for MartinRatio
Source§impl Debug for MartinRatio
impl Debug for MartinRatio
Source§impl Indicator for MartinRatio
impl Indicator for MartinRatio
Source§fn update(&mut self, ret: f64) -> Option<f64>
fn update(&mut self, ret: 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 MartinRatio
impl RefUnwindSafe for MartinRatio
impl Send for MartinRatio
impl Sync for MartinRatio
impl Unpin for MartinRatio
impl UnsafeUnpin for MartinRatio
impl UnwindSafe for MartinRatio
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