> ## Documentation Index
> Fetch the complete documentation index at: https://raymondchang.me/llms.txt
> Use this file to discover all available pages before exploring further.

# Tick-level simulation and fills

> Fill models, latency, and market-data requirements for tick-level backtests of passive and aggressive orders.

> [!NOTE]
>
> **Status of this page:** P0 draft. Design guidance. Any claim that a specific fill rule is conservative should be tested against live fills.

## 1. Data requirements

* **Level of detail:** trades and top-of-book quotes support aggressive-order simulation. Passive-order simulation needs depth and, ideally, order-level events.
* **Timestamps:** keep exchange timestamp and local receive timestamp separately; the difference is your latency to the feed.
* **Sequencing:** ensure the sequence number is monotone and gaps are detected.
* **Phases:** include opening and closing auction phases and their rules ([auction mechanisms](https://raymondchang.me/quantitative-research/microstructure/auction-mechanisms.md)).

## 2. Aggressive (marketable) orders

* Fill against displayed depth at the simulated arrival time (event time plus latency), walking the book.
* Use the book as of arrival, not as of decision; the book may have changed in the latency window.
* Add impact for orders above displayed depth, using a fitted impact curve ([market impact and TCA](https://raymondchang.me/quantitative-research/microstructure/market-impact-tca.md)).

## 3. Passive orders

Three rule families, in increasing realism:

| Rule | Fill when | Bias |
| - | - | - |
| Touch | Price reaches the limit | Strongly optimistic: ignores queue |
| Trade-through | A trade prints strictly through the limit price | Pessimistic: misses fills at the limit |
| Queue-aware | Cumulative volume at the price exceeds the shares ahead | Realistic if queue position is well estimated |

For queue-aware simulation, set the initial position from displayed depth at arrival, and decide a cancellation assumption (none ahead cancels, or a proportional share). Report results under at least a conservative and an optimistic assumption. See [queue position and fills](https://raymondchang.me/quantitative-research/microstructure/queue-position-fill.md).

## 3.1 Adverse selection in simulation

A simulator that fills by random arrival will not reproduce adverse selection. Use real historical trades so that fills coincide with actual price moves, and measure P\&L using the mid some interval after the fill.

## 4. Latency

Model three components: market data latency, strategy compute time, and order entry latency. Apply them as delays on events. Run the same strategy under several latency settings; the P\&L-versus-latency curve shows how latency-sensitive the strategy is.

## 5. Own-order impact

Historical data does not contain your orders. Common approximations: reduce displayed depth by your own size after a fill, apply a decay impact model for aggressive orders, and cap participation as a fraction of the observed volume.

## 6. Validation against live

1. Run the simulator over a period with live fills.
2. Compare simulated and actual fill rates, fill times, and realised spread.
3. Adjust only the fill-model parameters (queue assumption, cancellation share), not the strategy.
4. Keep the live-versus-sim gap as a standing diagnostic.

## Points to verify

* Which HKEX data products carry order-level queue information and the conventions for broker queue data.
* Latency figures for the specific co-location or access setup used.

## Sources

* Moallemi and Yuan (2016), A Model for Queue Position Valuation in a Limit Order Book. [PDF](https://drupalgsb-test.paas.cc.columbia.edu/sites/default/files-efs/pubfiles/25461/queue-value-2016.pdf)
* Methodological synthesis for the remaining points.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.