Order Types & Mechanics
Level: 5 — Mastery (cross-domain: market microstructure + math + coding) Time limit: 90 minutes Total marks: 60
Instructions: Answer all three questions. Show all reasoning, derivations, and code logic. Where code is requested, pseudocode with correct algorithmic structure earns full marks. State every assumption.
Question 1 — Matching Engine & Order Book Dynamics (22 marks)
A price/time-priority continuous limit order book (LOB) for stock ABC has the following resting state (all prices in ₹, quantities in shares):
BIDS (buy)
| Price | Qty | Time (arrival order) |
|---|---|---|
| 100.50 | 200 | t1 |
| 100.50 | 150 | t3 |
| 100.45 | 400 | t2 |
| 100.40 | 500 | t5 |
ASKS (sell)
| Price | Qty | Time |
|---|---|---|
| 100.55 | 100 | t4 |
| 100.60 | 300 | t6 |
| 100.65 | 250 | t7 |
(a) State the current best bid, best ask, and the bid–ask spread. Compute the mid-price and the micro-price (size-weighted mid). Show the micro-price formula. (5 marks)
(b) An incoming market BUY order for 550 shares arrives. Walk the matching engine through every fill (price, quantity, counterparty level) respecting price-time priority. Compute the volume-weighted average execution price (VWAP) and the total slippage in ₹ versus the best ask at arrival. (7 marks)
(c) After the fill in (b), a trader submits a marketable limit BUY for 400 shares with a limit of 100.62. Show the resulting fills and state what happens to any unfilled remainder — does it rest, and at what price? Give the new best bid/ask. (5 marks)
(d) Prove, in general, that under price-time priority a market order can never receive a worse price than the same-sized marketable limit order with a limit set at or beyond the market order's realised worst fill. State the one condition under which they fill identically. (5 marks)
Question 2 — Stop / Bracket Orders, Slippage & Circuit Limits (20 marks)
Stock XYZ closed yesterday at ₹500. Today's circuit band is ±10% (symmetric, based on previous close). Tick size ₹0.05.
(a) Compute the upper and lower circuit prices. A GTT sell order was set with a trigger at ₹560 and limit at ₹558. Explain whether this GTT can ever execute today, and justify using the circuit band. (4 marks)
(b) A trader goes long 100 shares at ₹500 using a bracket order (BO) with:
- Target (take-profit): +₹15
- Stop-loss trigger: −₹8
Give the target and stop trigger prices. If price gaps down through the stop and the stop is a stop-market filled at ₹489.30 (slippage below trigger), compute the realised P&L in ₹ and as a % of capital deployed. (5 marks)
(c) Define slippage formally. For a stop-LIMIT (not stop-market) placed with trigger ₹492 and limit ₹491, explain a concrete scenario where the stop-limit fails to protect the trader and leaves the position open, and quantify the additional loss if price then falls to ₹470 before any exit. (6 marks)
(d) Write pseudocode for a function simulate_bracket(entry, tp_offset, sl_offset, price_path) that scans a list of tick prices and returns the exit price and reason ("target", "stop", or "open"). Assume long position, and target checked before stop within the same tick only if both hit. (5 marks)
Question 3 — Pre-Open Call Auction: Equilibrium Price Discovery (18 marks)
During NSE's pre-open session, the following limit orders are collected for stock PQR (market orders treated as willing to trade at any price). Reference price ₹200.
| Buy orders (price, qty) | Sell orders (price, qty) |
|---|---|
| MKT, 300 | MKT, 200 |
| 201, 400 | 198, 300 |
| 200, 500 | 199, 500 |
| 199, 600 | 200, 400 |
| 198, 300 | 201, 600 |
(a) State the call-auction objective function: the equilibrium (opening) price is the one that maximises executable volume; ties broken by minimum order imbalance. Explain in one line why this differs from continuous matching. (3 marks)
(b) Build the cumulative demand (buy) and cumulative supply (sell) schedules at each candidate price {198, 199, 200, 201}. Remember: buyers willing to pay ≥ P; sellers willing to accept ≤ P; market orders count at every price. (7 marks)
(c) Determine the equilibrium opening price and the matched (traded) quantity. Show the imbalance at each price and apply the tie-break rule if needed. (5 marks)
(d) State what happens to the unmatched market orders and unmatched limit orders when the continuous session opens. (3 marks)
Answer keyMark scheme & solutions
Question 1
(a) (5 marks)
- Best bid = ₹100.50 (highest buy). Best ask = ₹100.55 (lowest sell). (1)
- Spread = 100.55 − 100.50 = ₹0.05. (1)
- Mid-price = (100.50 + 100.55)/2 = ₹100.525. (1)
- Micro-price formula (size-weighted toward the opposite size): Using top-of-book sizes: at 100.50 — but strictly top level is best price aggregate. Use best-level sizes (all at 100.50), . (1) Micro-price ≈ ₹100.5389 (leans toward ask because bid size dominates → upward pressure). (1)
(Accept best-level bid qty = 350 aggregated, or 200 if only first order counted — state assumption. Full marks if formula + reasoning correct.)
(b) (7 marks)
Market BUY 550 walks the ask side by price-time priority:
- Fill 100 @ 100.55 (level t4). Remaining 450. (1)
- Fill 300 @ 100.60 (level t6). Remaining 150. (1)
- Fill 150 @ 100.65 (level t7, partial; 100 left resting). Remaining 0. (1)
VWAP: (2) VWAP = ₹100.6045.
Slippage vs best ask at arrival (100.55): (2)
- Per share = 100.6045 − 100.55 = ₹0.0545
- Total = 0.0545 × 550 = ₹30.00 (i.e. 55332.5 − 550×100.55 = 55332.5 − 55302.5 = ₹30.00).
(c) (5 marks)
After (b), ask book: 100.65 has 100 left, then 100.60 & 100.55 exhausted. Wait — 100.55 and 100.60 fully consumed; 100.65 has 250−150=100 remaining. No new asks below 100.65. Marketable limit BUY 400 @ 100.62:
- Best ask now 100.65 > limit 100.62 → not marketable against it. (2)
- So zero fills; the order is not marketable. Unfilled 400 shares rest as a bid at 100.62. (2)
- New best bid = 100.62, new best ask = 100.65. Spread = ₹0.03. (1)
(Key insight: after the market order swept 100.55 and 100.60, the limit at 100.62 cannot reach 100.65, so it rests and improves the bid.)
(d) (5 marks)
Claim: A market order M for quantity Q and a marketable limit order L (same Q, limit L_p ≥ realised worst fill price of M) execute against the same resting liquidity; M's average price ≤ L's is false in general — they are identical or L is weakly worse only by resting. Correct statement:
- Both walk the book from best ask upward (buy). (1)
- Market order fills all Q at successively worse prices; realised worst price = . (1)
- Limit order with limit can reach every level M reached, so it fills the same levels for the same quantities → same VWAP. (1)
- If , the limit order stops early, filling fewer shares at better average price but leaving a remainder resting (not fully executed). Thus per-share it is never worse; but it fails the fill-completeness. (1)
- Identical fill condition: and book unchanged between the two arrivals (no intervening orders) ⇒ same fills, same VWAP. (1)
Question 2
(a) (4 marks)
- Upper circuit = 500 × 1.10 = ₹550.00. (1)
- Lower circuit = 500 × 0.90 = ₹450.00. (1)
- GTT sell trigger ₹560 is above the upper circuit (₹550). (1)
- Price cannot trade above ₹550 today ⇒ trigger at 560 can never be hit today ⇒ GTT cannot execute today. (GTT persists to future sessions when band shifts.) (1)
(b) (5 marks)
- Target price = 500 + 15 = ₹515. (1)
- Stop trigger = 500 − 8 = ₹492. (1)
- Stop-market fills at ₹489.30 (gapped/slipped below trigger). P&L = (489.30 − 500) × 100 = −10.70 × 100 = −₹1070. (2)
- Capital deployed = 500 × 100 = ₹50,000. % = −1070/50000 = −2.14%. (1)
(c) (6 marks)
- Slippage = difference between the expected/reference execution price and the actual fill price: (signed; adverse for a seller when fill < ref). (2)
- Stop-LIMIT scenario: trigger ₹492 activates a limit sell at ₹491. If price gaps from ₹493 straight to ₹485 (no trades between 491 and 485 at/above 491), the limit at 491 cannot fill because market is now below the limit → order rests unfilled, position stays open. (2)
- If price then falls to ₹470 with the position still open, mark-to-market loss = (470 − 500) × 100 = −₹3000, versus intended stop loss ≈ (492−500)×100 = −₹800. Additional loss = 3000 − 800 = ₹2200 relative to intended protection. (2)
(d) (5 marks)
function simulate_bracket(entry, tp_offset, sl_offset, price_path):
target = entry + tp_offset # long: profit above
stop = entry - sl_offset # long: loss below
for p in price_path:
if p >= target: # target checked first
return (target, "target") # or p, per fill convention
if p <= stop:
return (stop, "stop")
return (price_path[-1], "open") # never triggered
Marks: correct target/stop computation (1), loop over ticks (1), target-before-stop ordering (1), stop branch (1), open/return-last fallback (1).
Question 3
(a) (3 marks)
- Objective: choose opening price that maximises total executable (matched) volume; if multiple prices tie on volume, pick the one with minimum imbalance (|cum demand − cum supply|); further ties → price closest to reference. (2)
- Differs from continuous matching because all orders are aggregated and cleared at one single uniform price (uniform-price auction) rather than sequential price-time matching. (1)
(b) (7 marks)
Buyers willing at price P = those with limit ≥ P plus MKT (300). Sellers willing at P = limit ≤ P plus MKT (200).
Buy limits: 201→400, 200→500, 199→600, 198→300. Sell limits: 198→300, 199→500, 200→400, 201→600.
Cumulative demand (buy, ≥P):
- P=201: MKT300 + 400 = 700 (1)
- P=200: 700 + 500 = 1200 (1)
- P=199: 1200 + 600 = 1800 (1)
- P=198: 1800 + 300 = 2100 (0.5)
Cumulative supply (sell, ≤P):
- P=198: MKT200 + 300 = 500 (1)
- P=199: 500 + 500 = 1000 (1)
- P=200: 1000 + 400 = 1400 (1)
- P=201: 1400 + 600 = 2000 (0.5)
(c) (5 marks)
Matched volume at P = min(demand, supply):
| P | Demand | Supply | Matched=min | Imbalance |
|---|---|---|---|---|
| 198 | 2100 | 500 | 500 | 1600 |
| 199 | 1800 | 1000 | 1000 | 800 |
| 200 | 1200 | 1400 | 1200 | 200 |
| 201 | 700 | 2000 | 700 | 1300 |
- Maximum matched volume = 1200 at P = 200. (3)
- No tie ⇒ equilibrium opening price = ₹200, traded quantity = 1200 shares. (2)
(d) (3 marks)
- All executable orders trade at the uniform price ₹200. (1)
- Unmatched limit orders (demand 1200 vs supply 1400 → 200 sell shares unfilled, and the marginal buy limits below 200) carry into the continuous session and rest in the order book at their limit prices. (1)
- Unmatched market orders are converted to limit orders at the opening price (₹200) for the continuous session (they do not lapse). (1)
[
{"claim":"Q1b VWAP of market buy 550 = 100.6045","code":"vwap=(100*100.55+300*100.60+150*100.65)/550; result = abs(vwap-100.6045) < 1e-6"},
{"claim":"Q1b total slippage vs best ask = 30.00","code":"slip=(100*100.55+300*100.60+150*100.65)-550*100.55; result = abs(slip-30.00) < 1e-6"},
{"claim":"Q2b bracket stop P&L = -1070 and -2.14%","code":"pnl=(489.30-500)*100; pct=pnl/(500*100)*100; result = abs(pnl+1070)<1e-9 and abs(pct+2.14)<1e-2"},
{"claim":"Q2 circuit limits 550 and 450","code":"result = (500*1.10==550) and (500*0.90==450)"},
{"claim":"Q3c equilibrium price 200 maximises matched volume 1200","code":"D={198:2100,199:1800,200:1200,201:700}; S={198:500,199:1000,200:1400,201:2000}; matched={p:min(D[p],S[p]) for p in D}; best=max(matched,key=lambda p:matched[p]); result = (best==200) and (matched[200]==1200)"}
]