pub struct StandardError { /* private fields */ }Expand description
Standard Error of the regression line fit over the last period inputs.
Over the trailing window indexed x = 0, 1, …, period − 1 the OLS line
y = a + b·x is fitted, then:
slope = (n·Σxy − Σx·Σy) / (n·Σxx − (Σx)²)
SS_total = Σy² − n·ȳ² // total sum of squares
RSS = SS_total − slope² · S_xx // residual sum of squares
StdErr = √( RSS / (n − 2) ) // n − 2 residual d.o.f.where S_xx = (n·Σxx − (Σx)²) / n is the centred sum of squares of the
design.
This is the textbook standard error of estimate of OLS: it measures
the typical distance between the observed prices and the fitted line,
using the residual degrees of freedom n − 2. It is the spread that
drives crate::BollingerBands-style bands around a regression instead of
around an SMA — when the price hugs its trend, StdErr is small.
Each update is O(1): the Σx and Σxx terms depend only on period
and are precomputed once, while Σy, Σxy, and Σy² are maintained
incrementally as the window slides. Tiny floating-point cancellation
noise that could drive the residual sum of squares slightly negative is
clamped to zero before the square root.
§Example
use wickra_core::{Indicator, StandardError};
let mut indicator = StandardError::new(14).unwrap();
let mut last = None;
for i in 0..40 {
last = indicator.update(100.0 + f64::from(i) + (f64::from(i) * 0.5).sin());
}
assert!(last.is_some());Implementations§
Trait Implementations§
Source§impl Clone for StandardError
impl Clone for StandardError
Source§fn clone(&self) -> StandardError
fn clone(&self) -> StandardError
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 StandardError
impl Debug for StandardError
Source§impl Indicator for StandardError
impl Indicator for StandardError
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 StandardError
impl RefUnwindSafe for StandardError
impl Send for StandardError
impl Sync for StandardError
impl Unpin for StandardError
impl UnsafeUnpin for StandardError
impl UnwindSafe for StandardError
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