pub struct SharpeRatio { /* private fields */ }Expand description
Rolling Sharpe Ratio over period period-returns.
The input is treated as a single period-return (e.g. one day’s percentage
return). Over the trailing window of period returns the indicator
computes:
Sharpe = (mean(returns) − risk_free_per_period) / stddev(returns)stddev is the sample standard deviation with n − 1 in the denominator.
risk_free_per_period is the per-period risk-free rate the caller supplies
(e.g. 0.0 for excess-of-zero or a daily-equivalent rate to match the
return frequency). Wickra does not annualise: feed already-annualised
returns and supply an annual risk-free rate if you want an annualised
Sharpe.
A flat window has zero standard deviation and Sharpe is undefined; the
indicator returns 0.0 in that case rather than producing NaN.
Each update is O(1) — Welford-style running sums maintain Σr, Σr²
as the window slides.
§Example
use wickra_core::{Indicator, SharpeRatio};
let mut sr = SharpeRatio::new(20, 0.0).unwrap();
let mut last = None;
for i in 0..40 {
last = sr.update(0.001 + (f64::from(i) * 0.1).sin() * 0.01);
}
assert!(last.is_some());Implementations§
Source§impl SharpeRatio
impl SharpeRatio
Trait Implementations§
Source§impl Clone for SharpeRatio
impl Clone for SharpeRatio
Source§fn clone(&self) -> SharpeRatio
fn clone(&self) -> SharpeRatio
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 SharpeRatio
impl Debug for SharpeRatio
Source§impl Indicator for SharpeRatio
impl Indicator for SharpeRatio
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 SharpeRatio
impl RefUnwindSafe for SharpeRatio
impl Send for SharpeRatio
impl Sync for SharpeRatio
impl Unpin for SharpeRatio
impl UnsafeUnpin for SharpeRatio
impl UnwindSafe for SharpeRatio
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