of_analytics
of_analytics contains additive advanced market microstructure analytics for
Orderflow. The crate exists so heavier analytics can evolve outside of_core
without breaking existing AnalyticsAccumulator, runtime, C ABI, Python, or
Java APIs.
of_analytics starts at 0.1.0 in the broader Orderflow 0.5.0 development
line because it is a new public Rust surface.
The first foundation is dependency-light:
- market-quality/TCA primitives for quoted spread, effective spread, realized spread, price improvement, quote freshness, and side-aware slippage,
- execution-quality/TCA primitives for implementation shortfall, arrival and decision slippage, adverse selection, trade-through, and fill-quality score,
- liquidity/depth primitives for top-of-book depth, multi-level depth, proportional imbalance, order-flow imbalance, depth slope, depth convexity, book pressure, replenishment/depletion rates, drought detection, and sweepability,
- market-impact primitives for Kyle-style lambda, Amihud-style illiquidity, calibrated expected impact, square-root impact, temporary/permanent impact, impact decay, and child-order attribution,
- VPIN-style fixed-bucket toxicity primitives plus post-trade markout, adverse-selection, quote-fade, toxic-burst, and informed-flow proxy signals,
- fixed-window volatility/noise primitives with bipower variation, jump variation, OHLC range estimators, signature-plot points, and intraday seasonality buckets,
- threshold-based market regime classification plus composite trend/range/chop, liquidity, spread, session, hidden-liquidity, and transition-confidence labels,
- feed-quality primitives for sequence gaps, out-of-order events, duplicates, stale events, locked/crossed books, timestamp skew, resets, health scoring, replay usability, primary issue selection, and operator review reports,
- feature-vector primitives for stable feature ids, ordered schemas, schema hashes, missing-value policy, quality labels, and reusable fixed-capacity writers,
- resiliency primitives for threshold-based spread/depth shock detection, recovery timing, and liquidity resiliency scoring,
- queue/fill primitives for passive queue position estimates, fill probability, expected time-to-fill, amend queue loss, top-level survival, cancel/replace cost, and maker/taker decision scoring,
- pattern-risk primitives for spoofing/layering, quote-stuffing, stop-run, absorption, momentum-ignition, iceberg, hidden accumulation/distribution, stacked-imbalance, and failed-breakout risk indicators,
- venue/route primitives for fill, reject, cancel, latency, route-health, venue-liquidity, toxicity, fill-quality, reliability, route-quality, drift, and degradation diagnostics,
- cross-asset primitives for rolling correlation, beta, pair divergence, thresholded basis pressure, latency-adjusted correlation, cross-venue divergence, ETF/component imbalance, and relationship-degradation diagnostics,
- derivatives primitives for put/call pressure, volume/open-interest anomaly, implied-volatility flow, gamma exposure, IV skew, term structure, implied-versus-realized richness, gamma pressure, futures basis, roll pressure, funding divergence, and aggregate derivatives stress,
- explicit feature profiles so users can opt into future impact, toxicity, volatility, regime, data-quality, feature-vector, resiliency, queue-fill, cross-asset, pattern, derivatives, institutional, and ML feature modules without forcing all downstream users to compile them.
The crate does not submit orders, manage runtime state, own persistence, or
replace existing of_core APIs. It consumes normalized market data and returns
typed snapshots that hosts can wire into runtime, research, or execution
systems.
Feature Profiles
Default features:
market-qualityliquidity
Reserved additive profiles:
impacttoxicityvolatilityregimedata-qualityfeature-vectorresiliencyqueue-fillcross-assetpatternsderivativesinstitutionalml-featuresall
Public API Meaning
The analytics types are typed calculators and snapshots, not hidden strategy decisions. Context types such as quote, trade, depth, route, derivative, and feature inputs carry normalized observations and timestamps. Tracker or calculator types accumulate a bounded window; snapshot types expose the result without mutating the input observation. Constructors validate units, capacities, thresholds, and required metadata before a tracker is used.
The market-quality and execution-quality surfaces explain spread, slippage, impact, adverse selection, and fill outcomes. Liquidity, queue, resiliency, toxicity, pattern-risk, volatility, regime, cross-asset, and derivatives surfaces answer distinct analytical questions rather than producing one universal signal. Feature vectors and model metadata define stable input ordering and quality/missing-value semantics for downstream models.
All profiles are additive feature boundaries. A feature flag controls compile
cost and dependency inclusion; it does not silently change the meaning of
existing of_core snapshots. These calculations do not place orders, own
persistence, or override DataQualityFlags; hosts remain responsible for
quality gating, replay validation, and execution risk.
Market Quality Example
use ;
use Side;
let mut tracker = new;
tracker.on_quote;
let snapshot = tracker.evaluate_trade?;
assert_eq!;
assert!;
# Ok::
Execution Quality Example
use ;
use Side;
let trade = new?;
let benchmark = new?;
let snapshot = evaluate;
assert!;
assert!;
# Ok::
Liquidity Example
use ;
use BookLevel;
use Side;
let bids = ;
let asks = ;
let snapshot = new.analyze?;
assert_eq!;
assert_eq!;
assert!;
assert!;
let mut flow = new;
flow.on_event;
flow.on_event;
assert!;
# Ok::
Impact And Toxicity Example
use ;
use Side;
let mut impact = new;
impact.on_sample;
assert!;
let calibration = new?;
let estimate = estimate;
assert!;
let mut vpin = new?;
vpin.on_trade;
vpin.on_trade;
assert_eq!;
let toxicity = new.evaluate;
assert!;
# Ok::
Volatility And Regime Example
use ;
let mut vol = new?;
vol.on_price?;
vol.on_price?;
vol.on_price?;
let snapshot = vol.snapshot;
assert!;
let regime = default.classify;
assert!;
let composite = default.classify;
assert_eq!;
assert_eq!;
let ohlc = estimate;
assert!;
let signature = estimate?;
assert_eq!;
let mut seasonality = new?;
seasonality.on_return?;
seasonality.on_return?;
assert_eq!;
# Ok::
Data Quality Example
use ;
let config = new?;
let mut tracker = new;
tracker.on_event;
let flags = tracker.on_event;
assert!;
assert!;
assert!;
let report = default.evaluate;
assert!;
# Ok::
Feature Vector Example
use ;
let mut schema = new?;
let spread = schema.register?;
schema.register?;
let mut writer = new;
writer.set?;
let vector = writer.finish;
assert_eq!;
assert_eq!;
# Ok::
Resiliency Example
use ;
let config = new?;
let mut tracker = new;
tracker.on_sample;
let shock = tracker.on_sample;
let recovered = tracker.on_sample;
assert!;
assert_eq!;
assert_eq!;
# Ok::
Queue And Fill Example
use ;
let config = new?;
let estimate = new?;
let mut tracker = new;
let snapshot = tracker.on_update;
assert_eq!;
assert!;
let decision = new
.evaluate;
assert!;
# Ok::
Pattern Risk Example
use ;
let classifier = default;
let snapshot = classifier.classify;
assert!;
assert!;
let detail = default.evaluate;
assert!;
assert!;
# Ok::
Venue Route Example
use ;
let mut tracker = new;
tracker.on_event;
tracker.on_event;
let snapshot = tracker.snapshot;
let quality = default.evaluate;
assert_eq!;
assert_eq!;
assert_eq!;
assert!;
# Ok::
Cross-Asset Example
use ;
let mut tracker = new?;
tracker.on_sample;
tracker.on_sample;
tracker.on_sample;
let snapshot = tracker.snapshot;
let diagnostic = default.evaluate;
assert!;
assert!;
assert!;
# Ok::
Derivatives Example
use ;
let mut options = new;
options.on_sample;
options.on_sample;
assert!;
let basis = analyze;
let diagnostic = default.evaluate;
assert!;
assert!;
# Ok::
Low-Latency Principles
- No async runtime dependency.
- No heap allocation in hot update/evaluate methods.
- Borrow existing
of_corebook levels instead of copying snapshots. - Use integer arithmetic for prices, quantities, spreads, and basis points.
- Keep batch/research features separate from live hot-path trackers.