Module 71 — Market Microstructure & Trading Systems
How markets actually work at the level of order flow — the mechanics of the order book, how prices form, why large orders move markets, how to execute trades without paying unnecessary costs, and how high-frequency traders extract value from microstructure inefficiencies. Essential for any quant who needs to translate signals into actual positions.
Learning Objectives
- Understand the full structure of a limit order book and how prices form
- Decompose the bid-ask spread into its economic components
- Apply market impact models to estimate execution costs before trading
- Design and evaluate execution algorithms: TWAP, VWAP, and Implementation Shortfall
- Conduct transaction cost analysis to measure and attribute execution quality
- Understand HFT strategies and their implications for institutional traders
- Navigate PSX-specific trading mechanics and constraints
1. The Order Book
Order Types
Every trade begins with an order. The two fundamental types:
Market order: Execute immediately at the best available price.
- Pro: Guaranteed execution
- Con: No price control — in thin markets, you may pay much more than expected
Limit order: Execute only at your specified price or better.
- Pro: Price control
- Con: Not guaranteed to fill — may sit unexecuted
Other order types:
| Order Type | Description | Use Case |
|---|---|---|
| Stop order | Becomes market order when price hits trigger | Stop-loss, momentum entry |
| Stop-limit | Becomes limit order at trigger | Stop-loss with price floor |
| Iceberg/hidden | Shows only a portion of the full size | Large institutions concealing size |
| Fill-or-kill (FOK) | Execute in full immediately or cancel | Block trades |
| Immediate-or-cancel (IOC) | Execute what you can now, cancel rest | Partial fill acceptable |
| Good-till-cancelled (GTC) | Stays in book until filled or cancelled | Passive accumulation |
The Limit Order Book
The limit order book (LOB) is a real-time list of all outstanding limit orders at every price level, organized by price and time priority.
BIDS (buyers) ASKS (sellers)
Price Size Orders | Price Size Orders
149.90 5,000 3 | 150.10 3,000 2
149.80 12,000 7 | 150.20 8,000 4
149.70 8,000 5 | 150.30 15,000 6
149.60 20,000 12 | 150.40 10,000 5
Best bid: 149.90 (highest price a buyer will pay) Best ask: 150.10 (lowest price a seller will accept) Bid-ask spread: 150.10 − 149.90 = 0.20 (20 cents, or ~13 bps) Mid-price: (149.90 + 150.10) / 2 = 150.00
Price-time priority: Orders are filled in price priority first (best price executes first), then time priority within the same price (earliest order executes first — hence the incentive for HFTs to be fast).
PSX Order Book Mechanics
Pakistan Stock Exchange (PSX):
- Trading hours: Monday–Friday, 9:30am–3:30pm PKT (with pre-open 9:00–9:30am)
- KSE-100 index: 100 largest companies by market cap/liquidity
- Order matching: continuous matching during regular session, call auction at pre-open and market close
- Tick size: varies by stock price (minimum price move)
- Circuit breakers: 7.5% daily limit up/down for individual stocks, 5% for index
PSX vs developed markets:
| Feature | PSX | NYSE/LSE |
|---|---|---|
| Daily volume | ~PKR 15–30B | Trillions |
| Institutional participation | Low (retail-dominated) | High |
| Short selling | Restricted (margin financing only) | Freely permitted |
| Derivatives | Futures on ~50 stocks | Full options + futures ecosystem |
| Dark pools | None | Active |
| HFT | Minimal | 40–60% of volume |
2. Bid-Ask Spread Components
The bid-ask spread is not free money for market makers. It has three economic components:
Order Processing Costs
The fixed costs of running a market-making operation: technology, exchange fees, regulatory costs, back-office processing. These are real but small — a few basis points in most markets.
Inventory Risk
A market maker who buys shares builds inventory. If prices fall before they can sell, they lose money. To compensate, they demand a spread that covers the risk of holding inventory. In volatile stocks, inventory risk is higher → wider spreads.
Implication: Spreads widen when:
- Volatility increases
- Market is one-sided (everyone wants to buy or everyone wants to sell)
- End of day (inventory cleared, market maker reduces size)
- PSX example: spreads widen significantly before/after IMF announcements, SBP policy decisions
Adverse Selection (Information Asymmetry)
This is the most intellectually interesting component. Some traders have better information than others.
The informed trader problem: A market maker sets a spread. Some of their counterparties are:
- Uninformed (noise/liquidity traders): Trading for reasons unrelated to information (rebalancing, cash needs). They're good to trade with.
- Informed traders: Trading because they know the stock is mispriced. They're dangerous — the market maker always loses to them.
The market maker widens the spread to recover losses to informed traders from gains on uninformed traders. This is adverse selection.
Glosten-Milgrom model (1985): Derives the optimal spread given the proportion of informed traders. Higher information asymmetry → wider spread. This is why:
- Earnings announcement periods have wider spreads (more informed traders)
- Small-cap stocks have wider spreads (less analyst coverage → more private information)
- PSX has wider spreads for less-covered stocks
Kyle's Lambda (Price Impact)
Kyle (1985) modeled how prices respond to order flow. The key result: price impact is proportional to order flow:
ΔP = λ × Q
Where Q is net order flow (positive = buy pressure) and λ (lambda) is the price impact coefficient.
Higher λ means a less liquid market — each unit of order flow moves the price more. Lambda can be estimated empirically from regression of price changes on signed order flow.
3. Market Impact Models
When a large institution needs to buy PKR 500M of a single stock, they cannot hit the market all at once — they would move the price significantly against themselves. Market impact is the cost of this price pressure.
Components of Market Impact
Temporary impact: Price moves while you are trading, then partially reverts. Caused by your order consuming liquidity.
Permanent impact: Price moves and does not revert — your trading revealed information (or the market thinks it did). True information incorporation.
Total execution cost = Temporary impact + Permanent impact + Spread crossing
The Square-Root Impact Law
Empirically robust across many markets: temporary market impact scales with the square root of trade size relative to volume:
MI = σ × η × √(Q/V)
Where:
- σ = daily volatility of the stock
- η = market impact coefficient (≈ 0.1–1.0 depending on market)
- Q = quantity to trade
- V = average daily volume
Example: FERROQUANT wants to buy PKR 200M of an OGDC stock. Daily volume = PKR 500M, daily volatility = 1.5%.
MI ≈ 1.5% × 0.5 × √(200/500) = 1.5% × 0.5 × 0.632 = 0.47%
So FERROQUANT will pay approximately 0.47% above mid-price just from market impact — PKR ~940,000 on a PKR 200M order. This is before commissions.
Almgren-Chriss Optimal Execution Model
Almgren and Chriss (2000) solved the classic execution problem: how should you split a large order over time to minimize total execution cost?
The tradeoff:
- Trade quickly → High temporary impact (liquidating too fast)
- Trade slowly → High timing risk (price moves against you while you wait)
Optimal solution: Trade faster when:
- Risk aversion is high (don't want price to run away)
- Volatility is high
- Temporary impact is low relative to permanent impact
Trade slower when:
- Market is very liquid (low temporary impact)
- Volatility is low (safe to wait)
- Time horizon is long
The model produces the efficient frontier of execution strategies — for any level of timing risk, what is the minimum implementation shortfall? Similar to Markowitz for portfolios, but for execution.
4. Execution Algorithms
Execution algorithms (algos) break large orders into smaller pieces and time their submission to minimize market impact and execution costs. Every institutional buy-side firm uses algos.
TWAP (Time-Weighted Average Price)
Execute the order in equal slices over a specified time window.
Example: Buy 100,000 shares over 4 hours → buy 25,000 shares every hour.
Pros:
- Simple, transparent, predictable
- Good when you don't know when volume will be concentrated
- Easy to explain to compliance
Cons:
- Ignores volume — trades equally in thin and liquid periods
- Telegraphs intent (predictable pattern can be front-run)
Best for: Less liquid stocks, uniform volume patterns, simple execution mandates.
VWAP (Volume-Weighted Average Price)
Match the market's intraday volume profile. Trade more when market volume is high, less when it is low.
Target % of each period = Actual volume in period / Total daily volume
Historical volume profiles show U-shaped patterns: high volume at open and close, low volume midday. VWAP algos front-load and back-load execution accordingly.
Benchmark: VWAP algos aim to execute at or near the market VWAP for the day. Performance is measured as:
VWAP slippage = Execution price − Market VWAP
Pros:
- Aligns with market liquidity — minimizes market impact
- Standard institutional benchmark
Cons:
- Ignores information — you may be buying at a price that's already reflecting bad news
- End-of-day volume creates execution pressure
PSX VWAP: PSX has low intraday volume predictability and wider spreads, making strict VWAP harder to achieve. The "dumb VWAP" problem — VWAP doesn't adapt if the stock suddenly moves.
Implementation Shortfall (IS)
Also called "arrival price" algorithm. Minimize the difference between the decision price (when you decided to trade) and the actual execution price.
IS = (Execution Price − Decision Price) × Shares Executed
+ Opportunity Cost of Unexecuted Shares
IS decomposition:
- Market impact: Price moved because of your own trading
- Timing risk: Price moved while you were executing (not your fault)
- Delay cost: Price moved between decision and when you started trading
- Missed trade cost: Shares not executed if price moved away before completion
IS algorithms are "smart": They trade faster when the stock is moving against them (reduce opportunity cost) and slower when it moves in their favor (let the market come to them).
Comparison of benchmarks:
| Algorithm | Benchmark | Philosophy | Risk |
|---|---|---|---|
| TWAP | Time average | Simple, mechanical | Ignores liquidity |
| VWAP | Volume-weighted daily average | Match market flow | Predictable, no adaptation |
| IS | Decision price | Minimize real cost of the decision | Trades faster in adverse moves |
| POV | % of volume | Participate at fixed % | Adapts to volume but long tail |
Participation Rate (POV)
Execute at a fixed percentage of market volume (e.g., 15% of all trades in this stock). Automatically adapts to actual volume — if the market is quiet, you trade less; if volume surges, you trade more.
Risk: No guaranteed completion time. If the stock becomes illiquid (volume dries up), you may be unable to complete the order in your target window.
5. Transaction Cost Analysis
Transaction Cost Analysis (TCA) measures and attributes the true cost of trading — from the moment a portfolio manager makes a decision to when the trade is complete.
Pre-Trade TCA
Estimate expected execution cost before the trade to inform the decision:
- Should we trade at all given current liquidity?
- Should we break the order into smaller pieces across days?
- Which algo is most appropriate?
- What is the expected market impact?
Pre-trade inputs: Order size, average daily volume, current spread, intraday volatility, recent order flow, benchmark price.
Post-Trade TCA
Measure actual execution cost after the trade to evaluate performance:
Total execution cost = Commission + Spread + Market impact + Opportunity cost
Attribution breakdown:
| Cost Component | What It Measures | Typical Range |
|---|---|---|
| Commission | Broker fee | 5–20bps |
| Spread cost | Half-spread at execution | 5–100bps |
| Market impact | Price move caused by your order | 10–100bps |
| Timing risk | Price move while executing | Variable |
| Opportunity cost | Unexecuted shares | Variable |
TCA benchmarks:
- Arrival price (IS): Measures from decision price
- VWAP: Compares execution to day's VWAP
- Close price: Compares to end-of-day price
- Interval VWAP: VWAP during your execution window only
TCA for FERROQUANT on PSX
PSX-specific considerations:
- Spreads are wider (50–200bps for mid-cap stocks vs 1–5bps on NYSE)
- Daily volume is lower → market impact is higher for the same PKR amount
- Intraday patterns are less predictable
- Pre-settlement T+2, lower margin financing availability
FERROQUANT TCA dashboard should track:
- Average spread paid vs NBBO spread at time of execution
- Market impact by strategy and stock
- VWAP performance (did the desk beat or miss VWAP?)
- Commissions as % of portfolio AUM
- Liquidity adjusted position sizing (don't own > 5% of ADV in any stock)
6. High-Frequency Trading
HFT firms use ultra-low latency technology to execute strategies that profit from microstructure advantages. In developed markets, HFTs account for 40–60% of equity volume.
HFT Strategy Types
Electronic market making: Post quotes on both sides of the book simultaneously (bid and ask). Profit from the spread. Manage inventory risk by adjusting quotes as inventory builds.
Key metric: fill rate and inventory turnover. Effective market makers have high fill rates and keep inventory flat — they're not directional, they're a flow intermediary.
Statistical arbitrage (stat arb): Exploit short-term pricing anomalies between related instruments:
- ETF vs basket of constituent stocks
- Futures vs spot (index arb)
- Pairs of correlated stocks
HFTs execute this at millisecond speed — by the time a human sees the mispricing, it's gone.
Latency arbitrage: Exploit the tiny time lag between when a price update reaches different exchanges or participants. If Stock X's futures price moves at Exchange A, an HFT firm can trade the spot at Exchange B before B's price adjusts.
Order anticipation (controversial): Detect large institutional orders in progress and trade ahead of them. Technically legal but ethically contested. Creates adverse selection for institutional traders — which is why IS algorithms are designed to be unpredictable.
Latency and Co-location
HFT speed is measured in microseconds (millionths of a second):
- Network round trip (NY to London): ~70 milliseconds
- Co-located server to exchange matching engine: <1 microsecond
- Speed of light across a data center: nanoseconds
Co-location: Placing your servers in the same data center as the exchange's matching engine. Reduces latency to the minimum physically possible. PSX does not currently offer formal co-location.
Microwave towers: Some HFT firms use point-to-point microwave networks between exchanges (faster than fiber optic cable for long-distance). The Chicago–New York microwave network (for CME–NYSE arb) was a significant infrastructure investment.
HFT Impact on Institutional Traders
Negative effects:
- Order anticipation increases execution cost
- Markets appear liquid but depth disappears when you need it ("phantom liquidity")
- Adverse selection from faster traders
Positive effects:
- Tighter spreads for small orders (market making HFTs compete to post tight quotes)
- Better price discovery
- More continuous liquidity
PSX and HFT: Pakistan's market has minimal HFT activity. This means:
- Spreads are wider (no aggressive electronic market making competition)
- But institutional orders are less likely to be front-run
- Market impact is driven by traditional block trading dynamics, not latency
7. Alternative Trading Venues
Dark Pools
Private trading venues where large institutional orders can be matched anonymously, without revealing size or direction to the public order book.
How they work:
- Institutional A wants to sell 1M shares of Apple
- Institutional B wants to buy 1M shares of Apple
- Both route to a dark pool, where they match at mid-price
- Neither reveals their intent to the lit (public) market
Benefits:
- No market impact — large blocks execute without moving price
- Price improvement over lit market (often at mid-price)
- Anonymity
Risks:
- Information leakage (some dark pools had conflicts of interest — trading against their clients)
- Execution uncertainty (no guarantee of fill)
- Contribution to price discovery reduction
MiFID II (EU): Capped dark pool trading at 8% of total stock volume — regulators concerned that too much dark trading harms price discovery.
PSX: No dark pools exist. All trading is lit. Large block trades are negotiated OTC (bilateral) and then reported to PSX.
Crossing Networks and Periodic Auctions
Crossing networks: Match orders at predefined times (e.g., 3x daily) at the benchmark price (usually VWAP or mid). No market impact.
Periodic auctions: Brief auction windows throughout the day. Orders accumulate, then match at the clearing price that maximizes volume. Reduces HFT advantage.
Block Trading
For very large orders (e.g., 5%+ of daily volume), institutions sometimes negotiate bilateral block trades:
- Investment bank acts as broker or principal
- Negotiated price — discount to market for sellers, premium for buyers
- Reported to exchange after execution
- Upstairs market in PSX: large trades are negotiated directly between brokers
Self-Assessment
-
FERROQUANT Capital wants to buy a 2% stake in Engro Fertilizers (EFERT). EFERT trades PKR 2B per day on average, and the 2% stake is worth PKR 1.5B.
(a) Calculate the order size as a percentage of average daily volume (ADV). (b) Using the square-root impact law (σ = 1.8% daily, η = 0.6), estimate the market impact if FERROQUANT executes in one day. (c) If FERROQUANT spreads execution over 5 days, recalculate the market impact per day and total. Why is total impact lower? (d) What execution algorithm would you recommend and why? Consider TWAP, VWAP, and IS. (e) The decision price was PKR 85.00. After 5 days of execution, the average fill price is PKR 85.60 and FERROQUANT executed 90% of the order (the remaining 10% was abandoned when the price moved above their limit). Calculate Implementation Shortfall in PKR terms.
-
FERROQUANT's trading desk is evaluating a post-trade TCA report for last quarter. The report shows:
- Average spread paid: 85bps
- NBBO spread at time of execution: 60bps
- Market impact (permanent): 22bps
- Market impact (temporary): 15bps
- Commission: 12bps
- Timing risk (price movement during execution): 18bps
- Total implementation shortfall: 152bps
(a) What does "average spread paid: 85bps vs NBBO 60bps" mean? What caused the 25bps excess? (b) Decompose the total IS into its components and identify the two largest cost drivers. (c) If FERROQUANT could eliminate temporary market impact through better algo selection, what % reduction in total cost would that achieve? (d) A rival fund's TCA shows IS of 85bps on similar PSX trades. What structural advantages might explain the difference?
-
An HFT firm operating on PSX identifies the following pattern: when the KSE futures price moves, the constituent stocks reprice on average 80ms later.
(a) What HFT strategy does this describe? Is it latency arbitrage, stat arb, or electronic market making? (b) If the HFT firm can react in 5ms and institutional traders react in 200ms, quantify the exploitable window. (c) How should FERROQUANT modify its execution strategy to reduce losses to this type of HFT activity? (d) PSX is considering co-location services. Would this benefit FERROQUANT or primarily benefit HFT firms? Argue both sides.