pub struct RollingMinMaxScaler { /* private fields */ }Expand description
Rolling Min-Max Scaler — maps the current value onto [0, 1] relative to the
minimum and maximum of the trailing window.
scaled = (x − min(window)) / (max(window) − min(window))This is the streaming form of scikit-learn’s MinMaxScaler applied over a
sliding window: 0 means the value is the lowest in the window, 1 the
highest, 0.5 the midpoint of the range. It is the engine behind oscillators
like the Stochastic %K and a handy normaliser for feeding any indicator into a
bounded model input. Because it rescales to the window’s own range it is
scale-free across instruments.
The output is in [0, 1]. A flat window (max == min) has no range to scale
against and returns the neutral 0.5. The first value lands after period
inputs; each update scans the window in O(period).
§Example
use wickra_core::{Indicator, RollingMinMaxScaler};
let mut indicator = RollingMinMaxScaler::new(14).unwrap();
let mut last = None;
for i in 0..40 {
last = indicator.update(100.0 + (f64::from(i) * 0.3).sin() * 5.0);
}
assert!(last.is_some());Implementations§
Source§impl RollingMinMaxScaler
impl RollingMinMaxScaler
Sourcepub fn new(period: usize) -> Result<Self>
pub fn new(period: usize) -> Result<Self>
Construct a rolling min-max scaler over period values.
§Errors
Returns Error::PeriodZero if period == 0 and
Error::InvalidPeriod if period < 2 (a range needs two points).
Trait Implementations§
Source§impl Clone for RollingMinMaxScaler
impl Clone for RollingMinMaxScaler
Source§fn clone(&self) -> RollingMinMaxScaler
fn clone(&self) -> RollingMinMaxScaler
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 RollingMinMaxScaler
impl Debug for RollingMinMaxScaler
Source§impl Indicator for RollingMinMaxScaler
impl Indicator for RollingMinMaxScaler
Source§fn update(&mut self, input: f64) -> Option<f64>
fn update(&mut self, input: 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 RollingMinMaxScaler
impl RefUnwindSafe for RollingMinMaxScaler
impl Send for RollingMinMaxScaler
impl Sync for RollingMinMaxScaler
impl Unpin for RollingMinMaxScaler
impl UnsafeUnpin for RollingMinMaxScaler
impl UnwindSafe for RollingMinMaxScaler
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