Skip to main content
live in the browserL1 / L2 → features → model → signalwalk-forward refitleakage toggle

Order book in, predicted signal out.

A platform user points the pipeline at a parquet of L1/L2 ticks; this page runs the same shape on a synthetic L2 (3 levels)instrument so it fits in a browser tab. Seven microstructure features — including a book-pressure feature that's silent at L1 and comes alive once the ladder has depth — feed a ridge regression refit on5walk-forward folds. OOS Sharpe is, OOS R² , hit rate .Features at t predict the next20ticks — no peeking.

For this strategy's catalog entry — provenance, cited notes, agent-run history — see/strategies/ridge_microstructure_demo.

leakage
sharpe (OOS)
OOS R²
OOS IC
hit rate
max drawdown
flips / 1k
tape · synthetic order book (first 600 ticks shown)
bid / ask quotes with size-weighted micro-price; dots are buyer- (green) and seller-initiated (red) prints.
bid / ask micro buy sell
depth-of-market · L2 ladder over time
rows = price levels from best (top) to deepest (bottom), split bid (left) / ask (right) · cell intensity = size.
bid ask

The top row is best-bid (left) / best-ask (right) — the only data an L1 feed delivers. Rows below are deeper book; their shape feeds the book_pressurefeature, which is silent at L=1.

IC is Pearson correlation of feature against the forward return target on out-of-sample test rows. Sign matters as much as magnitude — features with stable signs across folds are the ones the model leans on.

Each row is one walk-forward fold, fit on the expanding prefix and evaluated on the next contiguous block. Stable weights across rows mean the model is finding repeatable structure, not memorising one fold.

R² > 0 Sharpe > 0

X is the model's predicted forward return (bps); Y is the realised one. A signal worth trading shows a positive slope and most mass in the upper-right and lower-left quadrants.

equity · trading the predicted signal · OOS
strategy walk-forward fold
run_id
code_sha sandbox-microstructure@local
params_hash
data L2 (3 levels)
model ridge(α=1.0)
leakage off
oos_sharpe
oos_r2
features ofi · depth_imb · micro_mom · spread_bps · trade_imb · ret_lag · book_pressure
timestamp
how this is wired

runML() insrc/lib/ml.ts is a single ~400-line module with no I/O and a deterministic RNG.generateBook() emits an order book with 1–5 levels per side; computeFeatures()derives seven features point-in-time; ridgeFit()solves (X'X + αI) w = X'y in closed form; the walk-forward loop refits on each expanding training prefix and scores on the next block.

The features are OFI(Cont-Stoikov order-flow imbalance, depth-normalised),depth imbalance(summed across all levels — collapses to top-of-book at L=1),micro-momentum (lag-k micro-price log-return), spreadin bps, trade imbalance(EWMA of signed prints), return lag, and book pressure(1/(i+1)-weighted imbalance across levels 1..L-1 — zero by construction at L=1, the headline L2-only feature). Mid drift in the synthetic generator is coupled to both top-of-book and deeper-book imbalance, so adding levels genuinely uncovers signal that L1 cannot see.

With leakage off, the feature row at t predicts the forward return over [t, t+H] — no overlap. With leakage on, the feature row shifts ~60% of the way into the prediction window, so the fit sees part of the answer. OOS R² jumps and Sharpe with it; that's why a leakage-safe framework is non-optional.

The model is ridge because it's interpretable and refits in microseconds — the weights heatmap is then a real artifact, not a black box. The same pipeline accepts a GBDT or MLP at the ridgeFit() seam without changing anything upstream or downstream.

deskgdfindgfstrategiesgsfeaturesgepromotionsgpapigabotgbwritinggw

Shortcuts are no-ops while typing in an input or textarea.