Skip to main content

Module norm

Module norm 

Source
Expand description

Rolling-window coordinate normalization for financial time series.

§Purpose

Machine-learning pipelines require features in a bounded numeric range. For streaming market data, a global min/max is unavailable; this module maintains a rolling window of the last W observations and maps each new sample into [0.0, 1.0] using the running min and max.

§Formula

Given a window of observations x_1 ... x_W with minimum m and maximum M, the normalized value of a new sample x is:

    x_norm = (x - m) / (M - m)    if M != m
    x_norm = 0.0                  if M == m  (degenerate; single-valued window)

The result is clamped to [0.0, 1.0] to handle the case where x falls outside the current window range.

§Precision

Inputs and window storage use rust_decimal::Decimal to preserve the same exact arithmetic guarantees as the rest of the pipeline (“never use f64 for prices”). The normalized output is f64 because downstream ML models expect floating-point features and the [0, 1] range does not require financial precision.

§Guarantees

  • Non-panicking: construction returns Result; all operations return Result or Option.
  • The window is a fixed-size ring buffer; once full, the oldest value is evicted on each new observation.
  • MinMaxNormalizer is Send but not Sync; wrap in Mutex for shared multi-thread access.

Structs§

MinMaxNormalizer
Rolling min-max normalizer over a sliding window of Decimal observations.
ZScoreNormalizer
Rolling z-score normalizer over a sliding window of Decimal observations.