A zero-dependency C++20 order-flow imbalance engine for lithium stocks, tested on synthetic data and on real IEX and Binance tapes, including the session after Chile's 2023 lithium announcement.
This page shows the project's results. The methodology, the design decisions and the limitations are documented in the repository's README.
Why MAD + Student-t, not a Gaussian EWMA
The curve is why the two fixes are separable. Holding the alert rate fixed at the probability a Gaussian 3-sigma rule accepts, the threshold more than doubles once you stop assuming normality — and it keeps climbing as the assumed tail gets heavier. Picking dof=4 is a stated assumption about the tail, not a tuning knob turned until the alert count looked right; the Gaussian limit of 3.00 is the right-hand asymptote of that same curve.
Results on synthetic data
And "~30x fewer alerts" undersells it, because the two detectors do not even agree on the shock. Splitting the 296 Gaussian alerts by whether they fall inside the true shock window shows that only 2 of them do: the other 294 are false alarms, and the detector misses 8 of the 10 shock windows entirely. The robust detector raises 10 alerts, all 10 inside the shock, none outside. So the robust estimator is not trading sensitivity for fewer false positives — it is better on both axes at once.The timeline is the same fact as a picture. The blue Gaussian trace crosses its own threshold throughout the session on ordinary fat-tailed noise, while the red robust trace sits well below its line until the shock, then spikes to 47.37 — 7.2x its threshold — and drops back immediately. What a monitoring desk cares about is not the peak height but that the red line is quiet the rest of the time; that is the difference between an alert someone acts on and one they learn to dismiss.
Real data: what changes on real tapes
Tape
Empty 500 ms windows
Robust alerts
Gaussian alerts
5 s move after alert vs. any window
Synthetic (SQM)
0%
0.07%
0.66%
90.9 vs. 22.8 bps
BTCUSDT crash, 5 Aug 2024
3%
9.3%
3.1%
4.5 vs. 5.3 bps
BTCUSDT calm, 11 Aug 2024
31%
24.3%
2.8%
1.1 vs. 1.2 bps
SQM on IEX, 21 Apr 2023 (lithium news)
92%
4.2%
2.6%
3.4 vs. 3.7 bps
SQM on IEX, 13 Apr 2023 (ordinary)
98%
1.4%
1.1%
0.5 vs. 0.5 bps
Both detectors target a 0.27% alert rate. On real tapes the robust detector fires more than the Gaussian one, real order flow has tails far heavier than the Student-t(4) it assumes, and alerts do not anticipate price; only the planted synthetic shock does. The data also exposed a bug: with mostly empty lookbacks the old scale floor turned a 10-share print into t = 10,000,000. It is fixed.
The lithium news day was a volume event: SQM traded 12x its usual volume on IEX and fell 13% during the session, but buyers took 45% of volume against 46% on an ordinary day. A signed-volume detector cannot see it; a volume detector would.