Skip to content
Hrishi11572Public

About

'Buy low sell high : An HFT perspective', paper replication with an added novelty

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Buy Low, Sell High on a Real Order Book

Reproducing Cartea, Jaimungal & Ricci (2014), a data-driven fill curve, and a realistic backtest on LOBSTER AAPL data

Course project for Market Microstructure, IIT Kharagpur, by Hrishikesh Tiwari, Kavita Thakur and Avinandan Sharma

Cartea, Á., Jaimungal, S., & Ricci, J. (2014). Buy low, sell high: A high frequency trading perspective. SIAM Journal on Financial Mathematics, 5(1), 415–444. doi:10.1137/130911196


Overview

The paper derives a closed-form optimal market-making strategy for a high-frequency trader who places limit orders around the midprice. The trader adjusts those quotes for:

  • self- and cross-exciting market-order flow: buy and sell intensities $\lambda^\pm_t$ that jump when market orders arrive;
  • a fluctuating limit-order-book shape $\kappa^\pm_t$, which controls how far market orders walk the book;
  • short-term alpha $\alpha_t$: a mean-reverting drift in the midprice that is kicked by influential orders.

This project has three parts:

  1. Reproduction. We implement the model equation by equation, check every closed form against Monte Carlo or quadrature, and replicate the paper's simulation study (Tables 1–3, six trader types).
  2. Novelty: a data-driven fill curve. We replace the paper's exponential fill probability $h(\delta)=e^{-\kappa\delta}$ with a non-parametric curve $h(\delta;\kappa)=g(\kappa\delta)$ estimated from market orders. Because $g$ is a scale family, the paper's closed-form quotes still hold.
  3. Realistic backtest. We calibrate the model walk-forward on one day of NASDAQ AAPL data and replay every message of the day. The replay tracks queue position by order ID and includes tick rounding, latency, fees/rebates, and liquidation at the real bid and ask.

Key results

Finding
Replication 45 of 54 table cells match the paper within 0.08. All of the paper's qualitative conclusions hold. The ρ=1-with-alpha column comes out somewhat lower because the paper does not fully specify that trader; the ranking is unchanged.
Corrections We document and fix typos in the paper's simulation algorithm (Appendix D) and in its log-likelihood (A.2).
Fill curve fit Real normalised depths are far from Exp(1) (KS statistic 0.23). The data-driven curve has a lower out-of-sample Brier score (0.1294 vs 0.1319) and earns more inside the calibrated model (paired t ≈ 51).
Real-data backtest In the paper's setup every strategy loses money. The main cause is flattening inventory across a ~15¢ spread every five minutes.
Alpha Using alpha is never significantly worse than not using it, and is significantly better in 20 of 44 comparisons. A cushion test shows that most of this benefit is protection against adverse selection, not directional prediction.
Better fit ≠ better strategy The better-fitting fill curve is the worse strategy. The extra fills it buys near the touch are adversely selected.
Inventory control Removing the forced 5-minute flatten (rolling horizon, passive unwind, inventory cap) moves the paper's strategy from −$36.7 to +$5.5 per 100-share lot per episode. No result is statistically significant on a single day.

The full write-up is in report.pdf.

Repository structure

.
├── cartea_final_combined.ipynb           # Main notebook: full pipeline (Parts 1–9)
├── cartea_jaimungal_ricci_extension.ipynb # Earlier version: replication + calibration + simple MO-replay backtest
├── report.pdf                            # Project report
├── Presentation6_Project.pptx            # Project presentation slides
├── Buy Low, Sell High Combined Pipeline Results.docx  # Results write-up of the combined pipeline
└── lobster_data/
    └── Archive.zip                       # LOBSTER AAPL 2012-06-21, level-10 message + orderbook files

Main notebook: cartea_final_combined.ipynb

Part Content
1 The model and closed-form optimal quotes (Corollary 4, eqs. 16–17, Prop. 7–8); exact event-by-event simulator
2 Checks of every closed form against Monte Carlo / quadrature
3 Replication of Tables 1–3 (six HFT types)
4 LOBSTER data: full message + order-book replay, order IDs, market-order extraction
5 Novelty: data-driven fill curve $g$, diagnostics (KS, bootstrap, Brier score), in-model test
6 Walk-forward calibration on 30-minute windows (order flow, κ dynamics, alpha, fill curve)
7 Realistic backtest engine: queue position, tick rounding, latency, fees, close at the real bid/ask
8 Experiments: fill curves × alpha, cushion test, inventory penalty φ, fill rule × latency sweep, inventory-control variants
9 Final results table and conclusions

Method in brief

Optimal quotes (Corollary 4). The sell/buy depths are

$$\delta^{\pm*}=\delta_0^\pm+B\Bigl\lbrace\pm\mathcal S^\pm_\lambda F+\phi\bigl[\pm\mathcal S^\pm_\lambda b_\phi+(1\mp 2q)(T-t)\bigr]\Bigr\rbrace$$

where $F=\mathbb E[\int_t^T\alpha_u\,du]$ is the expected integrated drift and $b_\phi$ is the inventory term.

Data-driven fill curve. For each market order we compute the normalised depth it reached, $X_i=\kappa_{t_i^-}D_i$. Under the paper's assumption, $X\sim\text{Exp}(1)$. Instead of assuming that, we estimate $g(x)=P(X\ge x)$ with a reflected Gaussian kernel. Since $h(\delta;\kappa)=g(\kappa\delta)$ is a scale family, $\delta_0=x^\star/\kappa$ and $h(\delta_0)=g(x^\star)$ is constant, so the closed form survives with

$$x^\star=\arg\max_x\,x\,g(x),\qquad h^\star=g(x^\star),\qquad B=\frac{g'(x^\star)}{2g'(x^\star)+x^\star g''(x^\star)}$$

On AAPL: $x^\star\approx0.80$, $h^\star\approx0.60$, $B\approx0.49$, compared with $1$, $e^{-1}$ and $1$ in the exponential case.

Calibration (ρ = 1, as in the paper's Appendix A):

  • market-order intensities by maximum likelihood with the correct point-process likelihood;
  • κ dynamics by maximum likelihood on the depths market orders reach;
  • alpha (ζ, ε) by regressing future mid changes on the decayed order-flow signal.

Backtest. Parameters fitted on 30-minute window k trade window k+1 (12 windows × 6 episodes of 300 s). Three fill rules are tested (optimistic, queue, conservative), each at latencies of 0, 1 and 10 ms. Confidence intervals come from a moving-block bootstrap (blocks of one 30-minute window) on paired, episode-by-episode differences.

Getting started

Requirements

Python 3.10+ with:

pip install numpy pandas scipy matplotlib jupyter

Data

The notebooks use the free LOBSTER sample for AAPL on 21 June 2012 (level 10). To set it up, either:

  • unzip the bundled archive:
    cd lobster_data && unzip Archive.zip -x "__MACOSX/*"
  • or simply run the notebook. If no files are found it tries to download them from LOBSTER or a Hugging Face mirror, and as a last resort builds a synthetic LOBSTER-format day so that every cell still runs. Synthetic results only test the code; they are not empirical results.

AMZN and GOOG samples also work. Avoid INTC and MSFT: their spread is almost always one tick, so the fill curve degenerates.

Run

jupyter notebook cartea_final_combined.ipynb

Flags at the top of the notebook:

Flag Default Effect
FAST False True uses 1,000 Monte Carlo paths instead of 5,000
RUN_REPLICATION True Full Tables 1–3 replication (~3–4 min)
RUN_SWEEP True Fill-rule × latency robustness sweep (~2–3 min)
N_BOOT 2000 Bootstrap resamples for confidence intervals

A full run takes roughly 15–20 minutes on a laptop; the walk-forward calibration is the slowest step (~8 min).

Limitations

  • One stock and one day. Episodes within the day are correlated, which is why we use block-bootstrap intervals.
  • The queue model ignores hidden orders at our price and our own market impact.
  • ρ is fixed at 1: influential and non-influential orders cannot be told apart in the data.
  • The inventory-control variants were designed after seeing losses on the same day, so their best numbers are optimistic.

Reference

Cartea, Á., Jaimungal, S., & Ricci, J. (2014). Buy low, sell high: A high frequency trading perspective. SIAM Journal on Financial Mathematics, 5(1), 415–444.

Data: LOBSTER, NASDAQ limit order book data.

About

'Buy low sell high : An HFT perspective', paper replication with an added novelty

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages