# Market Microstructure

Market microstructure: bid-ask spread analysis, order-flow toxicity metrics (VPIN /...

- Repository: https://github.com/HKUDS/Vibe-Trading (37375 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add HKUDS/Vibe-Trading --skill market-microstructure -g -a claude-code -y`
Codex: `npx skills add HKUDS/Vibe-Trading --skill market-microstructure -g -a codex -y`
Cursor: `npx skills add HKUDS/Vibe-Trading --skill market-microstructure -g -a cursor -y`
Gemini CLI: `npx skills add HKUDS/Vibe-Trading --skill market-microstructure -g -a gemini-cli -y`

## Description

Market microstructure: bid-ask spread analysis, order-flow toxicity metrics (VPIN / Kyle lambda), liquidity measures (Amihud / Roll), price-impact models, limit-order-book analysis, and China A-share call auction / block trade mechanics.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Market Microstructure

## Overview

Study the micro-level mechanisms of price formation: who is trading, how they are trading, and how trades affect prices. For quantitative strategies, this matters because it improves transaction-cost estimation, identifies informed trading, and optimizes execution.

Applicable scenarios:
- Precise estimation of strategy trading costs (instead of simply assuming a flat 0.1% fee)
- Designing large-order execution strategies (`TWAP / VWAP / IS`)
- Detecting order-flow toxicity (avoid time windows dominated by informed traders)
- Quantifying liquidity risk (flash-crash warning)
- Capturing China A-share-specific microstructure features (call auction / closing auction / block trades)

## Core Concepts

### Bid-Ask Spread

**Three measurements:**
| Metric | Formula | Meaning |
|------|------|------|
| Quoted spread | `Ask - Bid` | Best spread shown in the limit order book |
| Effective spread | `2 × |trade price - mid price|` | Actual spread paid by the trader |
| Realized spread | `2 × direction × (trade price - mid price 5min later)` | True market-maker profit |

```
China A-share example:
  Instrument: 600519.SH Kweichow Moutai
  Best bid: 1680.00  Best ask: 1680.50
  Quoted spread: 0.50 RMB = 0.03%

  Instrument: 000001.SZ Ping An Bank
  Best bid: 11.05  Best ask: 11.06
  Quoted spread: 0.01 RMB = 0.09%

Spread decomposition (Roll):
  Spread = adverse-selection cost + inventory cost + order-processing cost
  In China A-shares: adverse selection accounts for 60-70% (mixture of retail and informed traders)

Spread drivers:
  - Larger market cap -> smaller spread (Moutai 0.03% vs small-cap 0.5%)
  - Higher volatility -> wider spread (market-maker risk premium)
  - Higher volume -> narrower spread (greater competition)
  - Higher information asymmetry -> wider spread (adverse selection)
```

### Order-Flow Toxicity Metrics

The rest: https://github.com/HKUDS/Vibe-Trading/blob/HEAD/agent/src/skills/market-microstructure/SKILL.md
