pub struct HoltWinters { /* private fields */ }Expand description
Holt’s linear method — double exponential smoothing with a level and a trend component.
A single Ema tracks only a level and therefore lags any
sustained trend. Holt’s method adds a second smoothed state, the trend, and
reports the one-step-ahead forecast level + trend, which removes that lag
on trending data while still smoothing noise.
level_t = α · price_t + (1 − α) · (level_{t-1} + trend_{t-1})
trend_t = β · (level_t − level_{t-1}) + (1 − β) · trend_{t-1}
output = level_t + trend_t (one-step-ahead forecast)α ∈ (0, 1] is the level smoothing constant and β ∈ (0, 1] the trend
smoothing constant. The state is seeded from the first two inputs
(level = price_1, trend = price_1 − price_0), so the first output lands
on the second input.
On a perfectly linear series the forecast is exact from the second bar
onward (for any α, β): if the level equals the current value and the
trend equals the slope, both invariants are preserved and level + trend
equals the next value.
§Example
use wickra_core::{HoltWinters, Indicator};
let mut indicator = HoltWinters::new(0.2, 0.1).unwrap();
let mut last = None;
for i in 0..80 {
last = indicator.update(100.0 + f64::from(i));
}
assert!(last.is_some());Implementations§
Source§impl HoltWinters
impl HoltWinters
Trait Implementations§
Source§impl Clone for HoltWinters
impl Clone for HoltWinters
Source§fn clone(&self) -> HoltWinters
fn clone(&self) -> HoltWinters
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 HoltWinters
impl Debug for HoltWinters
Source§impl Indicator for HoltWinters
impl Indicator for HoltWinters
Source§fn update(&mut self, price: f64) -> Option<f64>
fn update(&mut self, price: 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 HoltWinters
impl RefUnwindSafe for HoltWinters
impl Send for HoltWinters
impl Sync for HoltWinters
impl Unpin for HoltWinters
impl UnsafeUnpin for HoltWinters
impl UnwindSafe for HoltWinters
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