Skip to content
All library documents

Local Paper Trading with Quote-Based Fills and Persistent Positions

Article Quant course library

Summary

The document explains a local simulator that routes orders and cancellations to a paper-trading engine instead of sending them to an external trading server. It supports limit, market, and stop orders, and uses quote-triggered matching: for example, a buy limit can fill when the best ask reaches or falls below its limit. Orders are filled in full without accounting for displayed book size, and the simulator sends an order update before the corresponding trade update.

The module maintains position records, calculates opening cost using a weighted average, and periodically marks profit and loss using the latest trade price. It freezes quantities for closing orders in long-short position mode and rejects closes beyond available holdings. Position changes are saved to disk, while order and trade records disappear on shutdown. Matching slippage and update frequency are configurable, but the simplified all-at-once fills and dependence on subscribed live quotes limit how closely results can represent real execution.

Key ideas

  • The simulator intercepts orders locally and supports limit, market, and stop order types.
  • Matching is triggered by quote prices and ignores available displayed quantity.
  • Opening trades update position cost using a weighted average, while closing trades leave that cost unchanged.
  • Position changes persist across restarts, but order and trade history does not.
  • Slippage, profit and loss update frequency, and immediate quote matching are configurable.

Tags

From a private course collection; the original is not published.