pub struct DetrendedStdDev { /* private fields */ }Expand description
Detrended (residual) standard deviation over the last period inputs.
Over the trailing window indexed x = 0, 1, …, period − 1 the OLS line
y = a + b·x is fitted and the residual sum of squares is then divided
by n (population convention):
slope = (n·Σxy − Σx·Σy) / (n·Σxx − (Σx)²)
SS_total = Σy² − n·ȳ²
RSS = SS_total − slope² · ( denom / n )
DetrendedStdDev = √( RSS / n )Unlike crate::StdDev, which measures dispersion around the rolling
mean, DetrendedStdDev measures dispersion around the rolling
linear trend — the portion of the price action that is not
explained by the local slope. On a strongly trending series this is
much smaller than StdDev; on a sideways, mean-reverting series the
two converge.
The divisor is n (population), matching the convention of
crate::StdDev; use crate::StandardError when you want the
textbook standard error of estimate with n − 2 residual degrees of
freedom.
Each update is O(1) via the same rolling sums as
crate::LinearRegression, plus a running Σy². Floating-point
cancellation noise in the residual is clamped to zero before the square
root.
§Example
use wickra_core::{DetrendedStdDev, Indicator};
let mut indicator = DetrendedStdDev::new(14).unwrap();
let mut last = None;
for i in 0..40 {
last = indicator.update(100.0 + f64::from(i) + (f64::from(i) * 0.3).sin());
}
assert!(last.is_some());Implementations§
Trait Implementations§
Source§impl Clone for DetrendedStdDev
impl Clone for DetrendedStdDev
Source§fn clone(&self) -> DetrendedStdDev
fn clone(&self) -> DetrendedStdDev
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 DetrendedStdDev
impl Debug for DetrendedStdDev
Source§impl Indicator for DetrendedStdDev
impl Indicator for DetrendedStdDev
Source§fn update(&mut self, value: f64) -> Option<f64>
fn update(&mut self, value: 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 DetrendedStdDev
impl RefUnwindSafe for DetrendedStdDev
impl Send for DetrendedStdDev
impl Sync for DetrendedStdDev
impl Unpin for DetrendedStdDev
impl UnsafeUnpin for DetrendedStdDev
impl UnwindSafe for DetrendedStdDev
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