Pro Feature. Requires a Pro or Ultra subscription. Get started at api.mathematicalcompany.com
Full Code
How It Works
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
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
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
- The quoter combines all three:
- Spread = base + VPIN-scaled component
- Fair value is skewed by OFI × lambda
- Size is reduced when toxicity is elevated