Skip to main content
Pro Feature. Requires a Pro or Ultra subscription. Get started at api.mathematicalcompany.com
A market maker that uses microstructure signals - toxic flow detection (VPIN), order flow imbalance (OFI + Kyle’s lambda), and structural break detection (CUSUM) - to dynamically adjust its quoting.

Full Code

How It Works

  1. toxic_flow() computes VPIN (Volume-synchronized Probability of Informed Trading):
  • Low VPIN (< 0.3) → mostly retail flow, safe to quote tight
  • High VPIN (> 0.7) → informed traders present, widen spread
  1. microstructure() tracks order flow imbalance (OFI) and Kyle’s lambda:
  • OFI measures net buying/selling pressure
  • Kyle’s lambda estimates the price impact per unit of order flow
  • Combined, they predict the direction and magnitude of short-term moves
  1. change_detector() runs CUSUM on price residuals:
  • When the cumulative sum exceeds the threshold, a structural break is flagged
  • The quoter pauses during breaks to avoid quoting into a regime change
  1. The quoter combines all three:
  • Spread = base + VPIN-scaled component
  • Fair value is skewed by OFI × lambda
  • Size is reduced when toxicity is elevated

Standalone Microstructure Functions

Use the Rust microstructure functions directly for research:

Run It

See Quantitative Methods for the full microstructure reference.