pub struct UpsidePotentialRatio { /* private fields */ }Expand description
Upside Potential Ratio over a trailing window of period returns, measured
relative to a minimal acceptable return (mar).
upside = mean( max(r − mar, 0) ) over the window
downside = sqrt( mean( min(r − mar, 0)² ) ) over the window
UPR = upside / downsideWhere the SharpeRatio divides excess return by total
volatility (penalising upside and downside symmetrically), the Upside Potential
Ratio rewards only the average outperformance above the threshold while
penalising solely the downside deviation below it. It is the purest expression
of the Sortino philosophy: investors do not dislike upside variance, only
shortfall risk.
mar (minimal acceptable return) is the per-period hurdle the caller supplies
(e.g. 0.0 for break-even, or a target rate matching the return frequency). A
window that never breaches the threshold has zero downside deviation; the
indicator then reports 0.0 rather than dividing by zero.
Each update is O(1) — running sums maintain the upside total and the
downside sum-of-squares as the window slides.
§Example
use wickra_core::{Indicator, UpsidePotentialRatio};
let mut indicator = UpsidePotentialRatio::new(20, 0.0).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§
Source§impl UpsidePotentialRatio
impl UpsidePotentialRatio
Sourcepub fn new(period: usize, mar: f64) -> Result<Self>
pub fn new(period: usize, mar: f64) -> Result<Self>
Construct an Upside Potential Ratio over period returns with minimal
acceptable return mar.
§Errors
Returns Error::InvalidPeriod if period < 2, or
Error::InvalidParameter if mar is not finite.
Trait Implementations§
Source§impl Clone for UpsidePotentialRatio
impl Clone for UpsidePotentialRatio
Source§fn clone(&self) -> UpsidePotentialRatio
fn clone(&self) -> UpsidePotentialRatio
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 UpsidePotentialRatio
impl Debug for UpsidePotentialRatio
Source§impl Indicator for UpsidePotentialRatio
impl Indicator for UpsidePotentialRatio
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 UpsidePotentialRatio
impl RefUnwindSafe for UpsidePotentialRatio
impl Send for UpsidePotentialRatio
impl Sync for UpsidePotentialRatio
impl Unpin for UpsidePotentialRatio
impl UnsafeUnpin for UpsidePotentialRatio
impl UnwindSafe for UpsidePotentialRatio
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