Mattheus Public Preview

Join Waitlist

Mattheus Public Preview

Current Blog

How to Model Opening and Closing Auctions in a Backtest

An auction-aware backtest separates order acceptance, imbalance messages, freeze periods, the single auction match, and any unfilled quantity from continuous trading.

Published Updated
Blue and violet glass order blocks meet inside a warm illuminated circular auction chamber on a dark navy field

By alyc

This article was prepared with AI assistance and checked through automated editorial and source review. No named human review is recorded.

An auction-aware backtest should model the open or close as a discrete matching event. An order must arrive before the applicable venue cutoff, remain eligible through any freeze period, and participate under the exchange's auction rules. The auction price is determined at the match. A nearby continuous-market trade is not a substitute.

Store the venue, symbol, auction type, order type, quantity, limit price, submission and acceptance timestamps, imbalance messages available at the time, cutoff and freeze rules, auction timestamp, auction price, executed quantity, fees, and remaining quantity. This separates evidence from assumptions.

Represent the auction as a state machine

An auction order moves through distinct states. It may be submitted, accepted, frozen against cancellation, paired or unpaired, executed in the auction, rejected, canceled, or left unfilled. Keep each transition instead of assigning the final auction print to every order that existed near the open or close.

Nasdaq's Opening and Closing Cross documentation distinguishes market-on-open, limit-on-open, market-on-close, limit-on-close, and imbalance-only orders. It also states that opening imbalance information begins at 9:25 a.m. Eastern Time and closing imbalance information begins at 3:50 p.m. Eastern Time. A strategy cannot use those messages before their publication.

NYSE auction documentation shows why venue identity matters. It lists venue-specific entry, cancellation, freeze, and auction times, and notes that the NYSE opening can occur after 9:30 a.m. The backtest should load the historical rule set for the selected venue and date.

Keep auction orders separate from continuous orders

A market-on-close order requests execution in the closing auction. A limit-on-close order adds a maximum buy price or minimum sell price. The same distinction applies to market-on-open and limit-on-open orders. Do not send these instructions through an ordinary continuous-book fill function.

A continuous DAY order may be auction eligible on one venue under certain rules and ineligible on another. Its priority and handling can also differ from a dedicated auction order. Record the order designation actually sent. If the historical data only shows a closing print and not the strategy's accepted order, the fill is not proven.

Worked closing-auction example

Consider a synthetic Nasdaq example in Eastern Time. A strategy submits a market-on-close buy for 5,000 shares at 3:49:40 p.m. The venue accepts it before the applicable cutoff. The closing cross executes at $42.18. The model fills 5,000 shares at $42.18, producing gross consideration of $210,900. If modeled fees are $0.003 per share, fees add $15.

Suppose the last eligible continuous trade before the close was $42.10. The $0.08 difference equals $400 for 5,000 shares, but it is not automatically execution slippage against a guaranteed $42.10 fill. The research specification must define its benchmark and timestamp. Spread, fees, and impact remain separate trading-cost fields.

Change the instruction to a limit-on-close buy at $42.15. Because the auction price is $42.18, the order should not fill. It must not receive the last continuous trade or an invented fill at its limit. Send its limit logic through the same price checks used in the limit-order model, while preserving the auction-specific event.

The numbers are illustrative, not empirical results. They assume the order was accepted, remained eligible, the published auction price is correctly identified, and no venue-specific restriction invalidated the order.

Use imbalance data point in time

Indicative match prices, paired quantities, and imbalance quantities change as orders enter, cancel, or become frozen. Save every message with its exchange timestamp, sequence, venue, symbol, and field definition. A later final message cannot be copied backward into an earlier decision.

The NYSE page defines indicative match price, total imbalance, market imbalance, paired quantity, auction collars, and reference price. Nasdaq describes its Net Order Imbalance Indicator as a separate subscribed data product. A backtest without the licensed historical feed should mark the signal unavailable. It should not reconstruct a precise message from the final auction result.

Respect calendars, cutoffs, and delayed opens

Regular closes, early closes, holidays, and exceptional sessions change the valid auction timeline. Use the exchange's historical market calendar and time zone. Treat timestamps as timezone-aware instants and retain the original exchange-local time for audit.

The SEC's Market Activity Report methodology notes that major exchanges conduct open or closing auctions, that auction participation can include several order types, and that openings do not always occur at exactly 9:30 a.m. It also explains why the first minutes can contain special prints and cancellations. A bar labeled 9:30 is not enough to identify an auction event.

Keep an evidence trail for each fill

Store raw order acknowledgements, auction imbalance messages, trade condition codes, official auction prints, rule versions, and transformations in the data-lineage record. If the data vendor changes a condition-code mapping, retain the mapping used in the original run.

Run explicit invariants against the model.

  • No auction fill occurs before an accepted eligible order and the auction event.

  • MOO, LOO, MOC, and LOC instructions use the correct venue and auction.

  • A limit order never fills through its limit.

  • Freeze and cancellation rules use the historical venue rule set.

  • Imbalance messages become visible only at their publication timestamps.

  • The official auction print is distinguished from nearby continuous trades.

  • Partial or missing evidence produces an uncertain result, not an invented complete fill.

  • Quantities, prices, fees, and cash changes reconcile after the match.

Also test an early close, a delayed opening, a rejected late order, a cancel submitted during a freeze, a limit outside the auction price, a missing imbalance message, and a symbol whose primary listing venue changes. The fill is auditable only when the accepted order, applicable rules, auction event, and ledger result can be reconstructed.

Explore Markets with Infinite Context.

Explore Markets with Infinite Context.

Browse the public preview. Join the waitlist for gated trading features.

Browse the public preview. Join the waitlist for gated trading features.

Browse the public preview. Join the waitlist for gated trading features.

Dashboard interface preview