Skip to content

Pctl

What it does

Rolling N-day percentile ranker. Pctl<f64> holds the most recent window_days observations in insertion order. percentile_of(v) returns the percentile rank of v against the current window.

rust
let mut p = Pctl::new(252); // one rolling year
p.admit_daily(20260516, today_iv); // (date_yyyymmdd, value)
let rank = p.percentile_of(latest_iv); // 0.0 .. 1.0

NaN rejection

Pctl::admit_daily rejects NaN values. The <= value predicate in percentile_of returns false on any side of a NaN comparison; a silent admission would have counted toward n but never toward le, understating every subsequent percentile rank. The rejection path increments Pctl::nan_admits_rejected() so upstream callers can surface IV-provider / Greek-provider misconfiguration explicitly.

Replay parity

Insertion-order traversal is the load-bearing invariant; the rank computation walks the window linearly and emits identical results under any deterministic input order.

Consumers

Future analytics that need a per-symbol IV percentile baseline land on this primitive directly. The crate does not currently ship a percentile-driven analytic; Pctl is exposed as a building block.

Why a primitive

The rank-against-window pattern is generic across IV percentile, realised-vol percentile, dollar-volume percentile, and any future windowed-scalar rank. One implementation, one set of correctness tests, one NaN-rejection contract.

Proprietary. All rights reserved.