microprice-sandbox · v0.1

The market-maker that
knows when it is long.

Reproducing Sasson, Ho & Samson (Stanford MSE448) inside an Islo sandbox — one shell command, two thousand simulated trading sessions, no local Python.

The 2018 MSE448 paper "High Frequency Trading Strategies" compares two limit-order strategies: the Avellaneda–Stoikov optimal market-maker, which steers its quotes around its current inventory, and a symmetric control that always quotes around the mid. Cleanly separating these two strategies needs a clean environment — every parameter sweep, a fresh process, no Jupyter kernel leakage, matplotlib at a known version, no host pollution.

§

An Islo sandbox is a Linux microVM you can lease, run a thing inside, and throw away. The reproduction below was computed in one — pip-installed matplotlib, ran the sweep, streamed the PNGs back over stdout. The whole loop takes about 90 seconds and costs less than a coffee.

§ 01The one-liner

If you have crabbox and an Islo API key, the entire reproduction below is:

terminal
# lease an isolated python sandbox, run the sweep, release it
export ISLO_API_KEY=ak_…
git clone https://github.com/zozo123/microprice-sandbox && cd microprice-sandbox
./scripts/run_in_sandbox.sh        # < 90s end-to-end

That script warms an Islo lease, base64-streams scripts/sweep.py into the sandbox, pip install matplotlibs, runs the sweep, and tar-pipes results.json and the PNGs back. The lease is released on trap EXIT.

§ 02What the paper says, briefly

A market-maker quotes a bid and an ask around what it believes the fair price is, and earns the spread when both sides get hit. Two sources of risk: adverse selection (you keep getting hit only on the losing side) and inventory (you accumulate exposure that can move against you). The mid-price ignores both. The microprice corrects for imbalance and spread. The Avellaneda–Stoikov reservation price corrects for inventory.

For exponential order-arrival intensities λ(δ) = A·e−kδ and GBM mid dS = σ·dW, AS derive a closed form:

r(s, q, t) = s − q·γ·σ²·(T−t),     half-spread = γ·σ²·(T−t) + (2/γ)·ln(1 + γ/k)

The reservation price r drifts away from the mid in proportion to how much inventory you are sitting on, in the direction that makes the next trade more likely to flatten you. The control strategy quotes the same half-spread but always around the mid, with no inventory feedback.

§ 03The reproduction

Below: P&L distributions across 3,000 episodes per cell, 200 quote-update steps per episode, GBM mid with the parameters in the paper. Computed inside a fresh python:3.12-slim Islo sandbox.

Two histograms: at γ=0.1 and γ=0.5, AS distribution is visibly narrower than the symmetric control
assets/pnl_hist.png — episode-level P&L for AS (teal) vs. symmetric control (coral). At both risk-aversions the AS distribution is materially tighter; at γ=0.5 it also sits to the right.
strategyγσmean P&Lstd P&Lavg qstd q
AS0.102.043.038.07−0.032.53
control0.102.043.2110.75−0.065.24
AS0.502.027.477.14−0.021.73
control0.502.026.358.01−0.013.76

The number to stare at is std q: AS halves it. That column is the entire point of the strategy.

Two heatmaps over (γ, σ): inventory-stdev reduction ranges from 1.4 to 2.4×; mean P&L delta is mildly negative at low γ and positive at high γ
assets/sweep.png — left: how much tighter AS keeps inventory than the control, across (γ, σ). Right: the cost or premium in mean dollars. AS pays a small P&L tax at low γ and earns a premium at high γ.
AS is not the "more profitable" strategy. It is the strategy whose profit you can plan around. The control wins some episodes by a lot and loses some by a lot; AS wins narrower and loses narrower. That is what risk aversion buys.

§ 04Why an Islo sandbox?

Three things are awkward about reproducing quantitative-finance papers locally:

State leakage

Jupyter kernels carry hidden state across cells. Notebook-driven results don't reproduce unless you restart the kernel between every parameter, which nobody does.

Toolchain drift

matplotlib 3.7 and 3.10 don't render the same charts. The reproduction belongs to a specific image, not "whatever was on the laptop in 2018".

Host pollution

You shouldn't have to pip install matplotlib on the laptop to read a paper. A sandbox is the right granularity: one paper, one sandbox, throw it away.

Parallel parameter sweeps

A 6 × 5 grid is 30 independent runs. Each one in its own sandbox is the natural shape; nothing leaks between cells, and you can fan them out trivially.

§ 05Caveats

This is a synthetic reproduction. The paper fits σ and the arrival decay κ on real AAPL and CVX L1 data (the absolute numbers in Tables 1 and 2 reflect those fits). I use the paper's structural model — GBM mid, exponential arrival rates — with stylized constants. The qualitative result (AS roughly halves inventory variance and tightens P&L variance) reproduces; the absolute dollar magnitudes do not, and shouldn't be expected to. The microprice section of the paper isn't reproduced here, because it requires a real order book.

§ 06What's in the repo