pub struct StandardErrorBands { /* private fields */ }Expand description
Standard Error Bands: linear-regression line wrapped by the standard error of the fit.
fit y = a + b·x by OLS over the last `period` closes
residual_i = y_i − (a + b · x_i)
stderr = sqrt( Σ residual_i² / (period − 2) ) // OLS standard error
middle = a + b · (period − 1)
upper = middle + multiplier · stderr
lower = middle − multiplier · stderrStandard Error Bands and LinRegChannel both wrap
an OLS endpoint, but use different denominators for the dispersion
statistic:
- The
LinRegChannel uses the population standard deviation of the residuals (denominatorn). - Standard Error Bands use the OLS standard error (denominator
n − 2, one degree of freedom for the slope and one for the intercept).
The n − 2 divisor produces a slightly wider channel and is the
statistically-correct band-width when the regression is interpreted as a
prediction interval. Jon Andersen’s original publication pairs the bands
with a default multiplier = 2.0 and a 3-bar SMA smoothing of all three
outputs; this implementation reports the raw bands so callers can pipe
them through their own smoother (e.g. Sma::new(3)).
§Example
use wickra_core::{Indicator, StandardErrorBands};
let mut indicator = StandardErrorBands::new(21, 2.0).unwrap();
let mut last = None;
for i in 0..40 {
last = indicator.update(100.0 + f64::from(i));
}
assert!(last.is_some());Implementations§
Source§impl StandardErrorBands
impl StandardErrorBands
Sourcepub fn new(period: usize, multiplier: f64) -> Result<Self>
pub fn new(period: usize, multiplier: f64) -> Result<Self>
§Errors
Returns Error::InvalidPeriod if period < 3 (the n − 2
denominator requires at least 3 points) and
Error::NonPositiveMultiplier if multiplier is not strictly
positive and finite.
Sourcepub const fn multiplier(&self) -> f64
pub const fn multiplier(&self) -> f64
Configured multiplier.
Trait Implementations§
Source§impl Clone for StandardErrorBands
impl Clone for StandardErrorBands
Source§fn clone(&self) -> StandardErrorBands
fn clone(&self) -> StandardErrorBands
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 StandardErrorBands
impl Debug for StandardErrorBands
Source§impl Indicator for StandardErrorBands
impl Indicator for StandardErrorBands
Source§type Output = StandardErrorBandsOutput
type Output = StandardErrorBandsOutput
Source§fn update(&mut self, value: f64) -> Option<StandardErrorBandsOutput>
fn update(&mut self, value: f64) -> Option<StandardErrorBandsOutput>
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 StandardErrorBands
impl RefUnwindSafe for StandardErrorBands
impl Send for StandardErrorBands
impl Sync for StandardErrorBands
impl Unpin for StandardErrorBands
impl UnsafeUnpin for StandardErrorBands
impl UnwindSafe for StandardErrorBands
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