Price Modeling

How the engine prices option legs, constructs net spread prices, and checks exit conditions against historical data.

Per-Leg Fill Price

Every fill is derived from the actual bid and ask quotes stored in the historical data — never from a model or synthetic price. No per-leg rounding is applied; fills use raw float precision.

Step 1 — Mid price

The mid is computed from the raw bid and ask:

mid = (bid + ask) / 2

If the bid is zero (ask-only quote, common for deep OTM wings near expiry), mid is set to zero and the leg is treated as nearly worthless on the sell side.

Step 2 — Fill quality adjustment

Fill quality shifts the assumed fill from the mid toward the bid (sell) or ask (buy). Quality 0 means mid price; quality 1 means full bid or ask:

// Selling a leg (short leg, long leg at close)

fill = mid − quality × (mid − bid) − slippage

// Buying a leg (long leg, short leg at close)

fill = mid + quality × (ask − mid) + slippage

Slippage at the per-leg level is normally zero — it is applied once at the trade level after the net spread price is computed (see below).

Edge case: ask-only quotes

Near expiry, deep ITM options may only have an ask with no bid. When buying such a leg, the engine uses the ask directly rather than a mid-based formula. When selling, the fill is zero (the option is effectively worthless to sell). For a long call or long put that is in the money, a missing bid is not treated as a $0 sale: the option settles at its intrinsic value, and during the day that minute is skipped.

Net Spread Price Snapping

CBOE rules allow individual legs in a complex order to execute at $0.01 increments internally, but the net spread price must be a valid $0.05 multiple. The engine enforces this after computing the raw net price from the two per-leg fills.

Snapping is applied conservatively:

DirectionRuleRationale
Credit (entry, receiving premium)Floor to nearest $0.05You receive at most this much
Debit / cost-to-close (paying)Ceil to nearest $0.05You pay at least this much

Example: raw leg fills produce a $3.125 credit → snapped to $3.10 (floor). A cost-to-close of $1.975 → snapped to $2.00 (ceil). The maximum impact of snapping is $0.025 per trade.

Multi-leg positions

For N-leg positions (butterflies, iron condors), the engine sums per-leg raw fills into a single closing cost, then snaps the total once (ceil). This mirrors how brokers route complex orders on CBOE — legs are sent as a package with a single net price constraint.

Slippage

After the net spread price is snapped, a flat slippage amount is added to the cost-to-close. It represents execution friction: queue position, market movement between signal and fill, and bid-ask widening during fast markets.

SettingDefaultApplied
fills.slippageper underlying (see below)Once per closing transaction, at exit only
fills.quality0 (mid)Per leg, at both entry and exit

When you don’t set a slippage value, the default depends on the underlying, reflecting how much wider SPX option markets trade than the ETF products:

UnderlyingDefault slippage
SPX$0.05
SPY / QQQ$0.02

An explicit fills.slippage value always wins over the per-underlying default — including an explicit 0, which disables slippage entirely.

Slippage is charged once per closing transaction, not per leg. A two-leg spread and a four-leg iron butterfly both pay one slippage charge at close. For most positions the whole structure closes together, so this is simply once per trade.

The one case with more than one closing transaction is an iron condor managed per side: each side can close on its own. Two sides stopped out at different times are two independent closes and pay two slippage charges; both sides closed at the same minute (for example by an exit-time filter) count as a single four-leg close and pay one; a side that rides to expiration pays its settlement slippage inside that side’s own P&L instead of a separate charge. Per-side trades expose early_close_events and exit_slippage fields in the trade data so you can verify exactly what was charged.

Entry fills are not adjusted by slippage — only by fill quality. This reflects that entry orders can typically be worked patiently, while exits (especially stop-loss exits) happen under time pressure.

In multi-day backtests, this one fill model applies everywhere the position is priced: entry fills, the minute-by-minute valuation that drives exit rules, and the end-of-day marks that build the daily equity curve. Setting fills.quality or fills.slippage changes all of them together, and the per-underlying defaults above apply consistently.

Note: some multi-day valuation paths — daily equity-curve marks and exit monitoring for certain position types — previously ignored the configured fill model and always priced at mid with a fixed $0.05 slippage. In particular, SPY / QQQ backtests without an explicit slippage value monitored at $0.05 on those paths while entering at the $0.02 default. All paths now use the same configured (or default) values, so re-running a saved multi-day backtest may show slightly different exit timing and equity-curve values; SPX configs without fill settings are unaffected.

Exit Condition Checking

The engine checks exit conditions — profit target, stop loss, trailing stop, time stop — by evaluating the spread’s current P&L at each time step. Today, this happens at 1-minute intervals, matching the granularity of the historical quote data.

What happens inside a minute

Besides each minute’s close, the engine reads that minute’s high and low quotes. A stop loss breached by a spike inside the minute fires even if the minute closes back inside your threshold. A profit target touched inside the minute exits only if the trade is still profitable at the minute’s close. In both cases the fill is the minute’s close, so exits land on 1-minute prices. See Monitoring Precision.

1-second exit detection Planned

A future update will use 1-second SPX option data for exit condition checking, with fills still recorded at the 1-minute level:

  • Detection at 1 second — the engine will look for the stop or target at the 1-second level within each minute. The rules stay the same as today: a stop reached at any second triggers the exit; a profit target reached at some second exits only if the trade is still profitable where it fills (today, the minute’s close).
  • Fill at 1 second (upcoming) — once 1-second bid/ask quote data is available, fills will also move to the second level. Until then, fills are recorded at the minute’s close.