pub struct TrendLabel { /* private fields */ }Expand description
Trend Label — a discrete {−1, 0, +1} classification of the local trend from
the sign of the ordinary-least-squares slope over the last period values.
slope = Σ (tᵢ − t̄)(xᵢ − x̄) / Σ (tᵢ − t̄)² (regress price on bar index)
label = +1 if slope > 0, −1 if slope < 0, 0 if slope == 0The sign of the regression slope is scale-invariant — it does not depend on
the nominal price level — which makes it a clean, comparable trend state
across instruments. +1 marks a rising regression line, −1 a falling one,
and 0 a perfectly flat window. It is the discrete companion to
LinRegSlope (which returns the continuous slope): use
the label when a feature pipeline wants a categorical trend direction and
keys any magnitude / dead-band tuning on the raw slope itself.
Each update is O(period): the slope numerator is recomputed from the
window. The denominator Σ(tᵢ − t̄)² is strictly positive for period ≥ 2,
so the sign is always well-defined.
§Example
use wickra_core::{Indicator, TrendLabel};
let mut indicator = TrendLabel::new(10).unwrap();
let mut last = None;
for i in 0..20 {
last = indicator.update(100.0 + f64::from(i)); // strictly rising
}
assert_eq!(last, Some(1.0));Implementations§
Trait Implementations§
Source§impl Clone for TrendLabel
impl Clone for TrendLabel
Source§fn clone(&self) -> TrendLabel
fn clone(&self) -> TrendLabel
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 TrendLabel
impl Debug for TrendLabel
Source§impl Indicator for TrendLabel
impl Indicator for TrendLabel
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 TrendLabel
impl RefUnwindSafe for TrendLabel
impl Send for TrendLabel
impl Sync for TrendLabel
impl Unpin for TrendLabel
impl UnsafeUnpin for TrendLabel
impl UnwindSafe for TrendLabel
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