Skip to content

BaselineComparison

What it does

Rolling N-sample baseline with delta and z-score over any f64 scalar series.

rust
let mut baseline = BaselineComparison::new(20);
let sample = baseline.admit(today_volume);
// `sample` is a `BaselineSample` carrying value / baseline_mean /
// baseline_stddev / delta / z_score / count — every comparison is
// returned alongside the admitted value, never recomputed via a
// separate accessor.
let z          = sample.z_score;
let mean       = sample.baseline_mean;
let history    = baseline.history_len();

Implementation

  • Backing store is a RollingWindow with a one-sample-per-day cadence.
  • Mean and variance accumulators are Neumaier-compensated; the rolled-up totals are bit-identical regardless of per-sample admission order at the recovered scale.

Consumers

  • VolumeAnomaly — daily-volume z-score against the rolling baseline.
  • Any future analytic that fires alerts on a rolling-baseline deviation lands on this primitive directly.

Replay parity

Insertion-order traversal guarantees replay-stable output. The underlying RollingWindow's Neumaier accumulator makes the running mean and variance independent of admission order at the recovered scale.

Why a primitive

The "rolling baseline + z-score + multiple" pattern is generic across volume, dollar-volume, IV, and any windowed scalar. Factoring it out keeps the per-analytic math focused on the trigger logic.

Proprietary. All rights reserved.