
I reconstructed Nasdaq's displayed order book from TotalView-ITCH messages, checked it against a separate implementation, and evaluated two simple microstructure hypotheses on a later holdout. The first result was positive on both holdout days. The second went the wrong way: adding lagged order-flow imbalance increased one-second prediction error.
The second evaluation passed its sample gates. Its governing result was not_supported. I ran the frozen evaluation once and kept the negative result.
This is a retrospective event-time study of Nasdaq data for AAPL and NVDA. It measures midpoint prediction, not executable trading performance. There is no claim of alpha, profitability, production readiness, or executable latency.
1. The problem
Market microstructure research has a long history of studying displayed queue imbalance and order-flow imbalance. Gould and Bonart examined queue imbalance as a predictor of the next midpoint move; Cont, Kukanov and Stoikov studied the relationship between order-flow imbalance and price changes. My test uses a different target and a specific lagged OFI construction, so its estimates are not a direct replication of either paper.
Before interpreting a coefficient, I needed to know whether the book was reconstructed correctly, the features were causal, and the holdout had remained outside model selection.
I wanted to test two deliberately small models:
- H1: Does current queue imbalance improve prediction of the direction of a non-zero future midpoint move over a per-symbol train-prevalence baseline?
- H2: Does adding exactly one-second-lagged, normalized order-flow imbalance reduce the mean squared error of a queue-imbalance-only return model?
Before trusting either model, I wanted to trace each row back to its source messages and check the quote, features and label separately.
2. Official ITCH data
The second evaluation used two historical Nasdaq TotalView-ITCH 5.0 archives, obtained from Nasdaq over HTTPS. Downloads supported resumable Range requests.
| Session | Compressed bytes | Decoded messages | Local SHA-256 |
|---|---|---|---|
| 2021-07-13 | 5,996,745,270 | 459,781,103 | b39b72621a8bc3ff92601701e0e9bd93afbdf30fea2fd68cdbe83c6b0bfb8ccd |
| 2021-08-13 | 4,889,328,604 | 367,986,583 | 64f4f1b076164ee72971d87fb548ae73cb924e2e45a73de059cc77328bcde4e7 |
The source files were July 13 and August 13. Local hashes identify the bytes used in this run. Official checksum sidecars were unavailable in the recorded source verification, so a successful parse and a local hash do not establish publisher-checksum integrity. The artifacts explicitly record source_integrity_passed = false. The data protocol also leaves redistribution terms unverified.
ITCH uses sequenced binary messages and fixed-point prices. The pipeline decodes the feed in source order, tracks the order lifecycle, and exports changes to the best displayed bid and ask for AAPL and NVDA. The result for the two sessions is four Snappy Parquet files containing 2,700,732 top-of-book changes.
3. Rebuilding the book deterministically
A displayed order book is stateful. An add changes the state; later messages can reduce, execute, delete or replace an order. The next quote depends on the complete valid sequence before it, not just the current message.
The primary implementation maintains order state and price levels with lazy heaps for best-price lookup. It processes events in source-message order, preserving the underlying fixed-point price representation. The exported records retain lineage to source messages so that a derived quote can be traced back through the pipeline.
To check the state machine, I replayed the same order events through a second book implementation.
4. Independent reference book
The reference implementation uses bisect-based price-level management; the primary book uses lazy heaps. The two books were compared after 5,576,726 order events across the selected symbols and sessions. The verifier reported zero quote mismatches. The implementations share the ITCH decoder and message field extraction, so the comparison would not necessarily catch a bug common to that shared layer.
The output also retained 2,700,710 complete, 18 one-sided and 4 empty states. There were no reported invalid complete quotes, schema or order violations, or missing lineage in this verification. Keeping the incomplete states visible matters: filtering them away after observing a result would change the sample whose behavior we claim to understand.
The comparison establishes agreement on the recorded top-of-book quotes. The shared decoder and publisher-checksum integrity remain outside that check.
As a separate check, I assembled synthetic ITCH frames directly with Python's struct, without using the decoder's fixture builder. Four checks passed: Add Order and Replace fields matched independently specified wire layouts, while a truncated frame and unknown message type were rejected. This is a targeted wire-format check, not an independent replay of the historical feeds or verification of every message type. The original book comparison still shares its decoder.
5. Causal features and labels
For the best displayed bid and ask sizes, a common queue-imbalance representation is:
QI(t) = (bid_size(t) - ask_size(t)) / (bid_size(t) + ask_size(t))
For each pair of consecutive valid quotes, the pipeline computes a signed top-of-book OFI contribution. Here b and a are best prices, B and A their displayed sizes, and 1[condition] is an indicator:
e(i) = 1[b(i) >= b(i-1)] × B(i) - 1[b(i) <= b(i-1)] × B(i-1)
- 1[a(i) <= a(i-1)] × A(i) + 1[a(i) >= a(i-1)] × A(i-1)
OFI(t) = sum(e(i)) for valid quote events in second t
normalized_OFI(t) = OFI(t) / ((B_last(t) + A_last(t)) / 2)
The candidate receives exactly normalized_ofi_lag1s. A previous available row does not qualify unless it is exactly one second earlier. Independent scalar feature replay reported zero formula mismatches, causality violations, invalid lag links and lineage failures. Of 82,022 observed-second bars in the new holdout, 74,847 had an exact lag-one feature available.
The target is a midpoint return in basis points. To avoid binary half-tick arithmetic, the implementation first represents twice the midpoint as an integer sum of raw best bid and ask prices, then computes the return using Decimal:
mid_x2(t) = bid_raw(t) + ask_raw(t)
return_bps(t, h) = 10,000 × [mid_x2(t+h) - mid_x2(t)] / mid_x2(t)
The endpoint must exist at exactly t + 1 second for the primary horizon or t + 5 seconds for the secondary horizon, in the same session and symbol. A missing endpoint remains missing: there is no forward-fill or substitution with a nearby quote. Classification excludes zero returns; regression retains them. Both candidate and baseline regression models use the same eligible rows, including the lag-availability requirement; the classification comparison also uses this eligibility filter. As a result, H1 describes the eligible non-zero-return subset, not all observed seconds.
These are offsets between observed-second bars, not a guarantee that the endpoint is one second after the last individual source event or one second after a real collector received it. Independent label replay found zero mismatches; it also found zero rows from the old holdout in the new evaluation inputs.
6. Freeze the test before looking at the outcome
The same three 2019 sessions supplied 121,763 training rows. Two other 2019 sessions supplied 69,117 validation rows, used for diagnostics rather than feature, threshold or model selection. The new holdout was July 13 and August 13, 2021, with 82,022 observed-second rows before model eligibility.
The previous EVAL-01 holdout sessions, December 30, 2019 and January 30, 2020, were excluded from EVAL-02 fitting, validation, selection and holdout. Models were fit per symbol using training data only. H1 compares logistic regression on QI against the training up-move prevalence. H2 compares OLS on QI against OLS on QI plus lagged normalized OFI.
The EVAL-02 protocol records a freeze after data and feature acceptance and before label construction or outcome inspection. Its SHA-256 is 1bad5b92d8e75ceac71d699e77f0362db0e1d4d8e5400774de757f440f92c82e. The run manifest records one final holdout evaluation and no post-outcome retuning. These are recorded local chronology and execution claims; the hash alone does not independently timestamp them. EVAL-01 had already been inspected before the EVAL-02 protocol. The later comparison is descriptive, not confirmatory replication.
7. The two holdouts
Both differences below are defined so that positive favors the candidate. H1 is Brier(null) − Brier(QI logistic). H2 is MSE(QI only) − MSE(QI + lagged OFI) in squared basis points.
| Primary one-second diagnostic | EVAL-01 | EVAL-02 |
|---|---|---|
| H1: Brier difference | +0.002138 | +0.007363 |
| H2: MSE difference, bps² | −0.000137 | −0.000895 |
| ROC AUC | 0.5624 | 0.5997 |
| Sample gate | Failed: NVDA 16,570 regression rows | Passed for both symbols |
| Governing status | insufficient_data |
not_supported |
In EVAL-01, H1's daily Brier difference was +0.005241 and −0.000168; H2 was −0.000067 and −0.000195 bps². NVDA did not meet the pre-specified 20,000 eligible regression-row minimum. A positive pooled H1 value could not override that gate.
In EVAL-02, the new sample gate passed: AAPL had 44,151 eligible regression and 17,269 non-zero classification rows; NVDA had 25,147 and 17,724, respectively. Pooled totals were 69,298 regression and 34,993 classification rows.
| EVAL-02 holdout day | H1: Brier difference | H2: MSE difference, bps² |
|---|---|---|
| 2021-07-13 | +0.006877 | −0.000688 |
| 2021-08-13 | +0.007912 | −0.001085 |
H1 was positive pooled and on each day, with positive fitted QI slopes for both symbols. H2 was negative pooled and on each day. Under the frozen joint criteria, the result is not_supported, not a supported pooled claim.
The pooled number also hides a large difference between the symbols:
| EVAL-02 symbol | H1: Brier difference | H2: MSE difference, bps² | QI-only R² | QI + lagged OFI R² |
|---|---|---|---|---|
| AAPL | +0.013485 | −0.000058 | +0.014172 | +0.014050 |
| NVDA | +0.001398 | −0.002365 | −0.002205 | −0.004288 |
Both symbols have positive H1 point estimates. NVDA's H2 deterioration is much larger, and both NVDA regression R² values are negative against the train-mean benchmark. The pooled numbers are row-weighted diagnostics, not evidence that the symbols behave alike.
8. Why the failed OFI result matters
For EVAL-02, pooled one-second MSE was 0.711456 bps² for QI-only OLS and 0.712351 bps² after adding the lagged OFI feature. The candidate's out-of-sample R² dropped from 0.004734 to 0.003481. This is an incremental model comparison: it says that this particular lagged feature did not improve this particular frozen model on this holdout. It does not say OFI has no information in other data, definitions, horizons or models.
The secondary five-second H2 difference was +0.000727 bps². It is useful diagnostic information, but five seconds was not the co-primary inferential gate. Promoting it after seeing the one-second failure would be a new selection decision, not a rescue of the frozen test.
The recorded outcome, alternative and rejection condition give a future researcher a starting point for a different lag or sampling rule. That change would need a new research ID and untouched data.
9. Dependence, bootstrap and Holm
Quotes and returns cluster in time, and the two symbols can share market conditions. The implementation assigns observations to fixed, non-overlapping 60-second bins within each session × symbol stratum. Each of 2,000 bootstrap replicates resamples the observed bins within each stratum with replacement, combines their loss sums and counts, and divides the combined sum by the combined count. The seed is 20261128.
The confidence intervals are percentile intervals. The code computes a two-sided bootstrap sign p-value using the smaller tail probability, doubled, with a +1 correction. Holm adjustment covers the two primary one-second hypotheses. This is not a null-centered bootstrap, and the resulting p-values are not guaranteed to be calibrated under arbitrary dependence.
| EVAL-02 primary metric | Point estimate | 95% bootstrap CI | Holm-adjusted p |
|---|---|---|---|
| H1 Brier difference | +0.007363 | [+0.006513, +0.008261] | 0.001999 |
| H2 MSE difference, bps² | −0.000895 | [−0.002163, −0.000033] | 0.033983 |
The H2 interval is below zero under this procedure, opposite to the pre-specified improvement. The implementation samples symbol strata independently, so common shocks across AAPL and NVDA are not necessarily preserved in each draw. Approximate independence of 60-second blocks was not established, and two holdout sessions are too few to establish regime stability. Treat the intervals and p-values as exploratory diagnostics, not confirmatory inference.
To test sensitivity in a future study, I would freeze several block lengths in advance and resample synchronized time blocks across symbols, then report the number of sessions and blocks as well as row counts. With only two EVAL-02 holdout days, resampling individual days would still give a very weak view of day-to-day uncertainty. No alternative bootstrap or model was run on this holdout after observing the result.
10. Lineage and replay
The run connects source, dataset, feature and label manifests to a frozen protocol, model inputs, code hashes, environment, output hash and acceptance status. The recorded EVAL-02 result hash is 6b07c9769f216a0f6c3cf52b49683942b08306e69292161dae8d4d068896ef71.
I independently checked the local hashes of the protocol, results and run manifest against the recorded values. Hashes establish identity of the checked bytes; without an external immutable anchor they do not by themselves prove when an artifact existed or prevent replacement of an entire chain.
The separate acceptance/lineage verifier rechecked coverage, Holm adjustment, status and hashes without retraining or rerunning the holdout model. Its research_id still says LAB-ITCH-EVAL-01-VERIFICATION: the report attributes this to an unchanged legacy verifier. EVAL-02 identity is linked through protocol, results and run hashes; the metadata inconsistency is a limitation, not something to silently relabel.
The run reports 90 passing regression tests and a clean Ruff check for the Nasdaq slice. Those are recorded results; I did not rerun the full suite. For this article, I separately ran 18 tests covering OFI features, the evaluation models and bootstrap utilities; all 18 passed in the available HFM environment. These tests exercise selected behavior and do not reproduce the full historical evaluation. The run also reported pre-existing missing graphviz and plotly dependencies for CatBoost; this slice did not import them. The artifacts are currently local research records, so this article alone is not a public reproduction package.
11. What the experiment cannot tell us
The data are retrospective Nasdaq event-time records from one venue, not a consolidated NBBO. There is no collector receive-time, so the experiment cannot measure executable latency or reconstruct what a participant received at a particular instant. It does not model crossing the spread, fees, fills, queue priority, market impact or PnL. Two symbols and two non-consecutive holdout sessions cannot establish cross-asset generality or stability across regimes.
For example, a predicted increase in the displayed midpoint does not establish that a buy order could execute at that midpoint: a marketable buy generally faces the ask, and a passive order may not fill. Event timestamps alone also cannot reveal when a trading process would have received, decoded and acted on the message. An execution study would need separately specified order timing, spread and fee assumptions, and a fill or queue model, followed by new untouched evaluation data.
The source-data integrity flag remains false because an official publisher checksum was unavailable. A local checksum, successful parse, zero reference-book mismatches and zero feature/label mismatches answer different questions; none substitutes for that missing source verification.
12. What comes next
The first hypothesis had a positive exploratory result on both EVAL-02 holdout days. The pre-specified OFI addition failed its primary comparison, and the governing status stayed not_supported.
The next useful step is a new research ID and a newly frozen protocol on untouched sessions, with broader symbol/day coverage and explicit sensitivity analysis for dependence and block length. A receive-time-aware dataset and a separately specified execution model would be needed before studying latency or trading outcomes. Neither can be inferred from these midpoint diagnostics.
Sources and scope
- Nasdaq TotalView-ITCH 5.0 interface specification
- Gould and Bonart: Queue Imbalance as a One-Tick-Ahead Price Predictor
- Cont, Kukanov and Stoikov: The Price Impact of Order Book Events
- Local research artifacts:
LAB-ITCH-EVAL-01/report.mdandLAB-ITCH-EVAL-02/{report.md,results.json,experiment-protocol.json,data-verification.json,feature-verification.json,label-verification.json,run-manifest.json,verification.json}. These have not been published as a public reproduction package.