market-microstructure
它能做什么
这项技能解释交易屏幕上的价格是如何形成的,包括价差、订单流和流动性。适合希望降低交易成本或恰当安排大额下单时机的交易者。
适用场景
- ✓当你想要对交易成本做出切合实际的估算,而不是只看固定费用的时候。
- ✓当你计划买入或卖出大额仓位,并希望限制其对价格的冲击的时候。
- ✓当你想检查某只股票的流动性是否足以支持你的策略的时候。
技能链接
https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/market-microstructure/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“如果要买入这只股票 5 万股而不推动价格,实际会花多少成本?”
每周 5 个新技能,1 分钟读完。
工作原理
它会衡量买价与卖价之间的差距,以及交易如何推动价格变动。它还会利用流动性指标和订单簿数据来确定订单的规模和时机。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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 |
| 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
VPIN (Volume-Synchronized Probability of Informed Trading):
Principle: replace clock time with volume time to measure the probability of informed trading
Calculation steps:
1. Bucket trades by fixed volume (Volume Bucket)
Bucket size V = average daily volume / 50 (about 5-10 minutes per bucket)
2. Classify buy and sell volume in each bucket (Bulk Volume Classification):
buy_volume = V × Φ(ΔP / σ) (standard normal CDF)
sell_volume = V - buy_volume
3. Compute order-flow imbalance:
OI_i = |buy_volume_i - sell_volume_i|
4. VPIN = Σ(OI_i) / (n × V) (n=50-bucket rolling window)
Interpretation:
VPIN < 0.3 -> normal, low informed-trading share
VPIN 0.3-0.5 -> caution, informed trading rising
VPIN > 0.5 -> dangerous, high probability that major information is about to be released
China A-share usage:
A sudden VPIN spike in a stock may foreshadow:
- insider trading ahead of a major announcement
- institutional position building / distribution
Before the 2015 China A-share flash crashes, VPIN stayed above 0.6 for a prolonged period
Kyle's Lambda (price impact coefficient):
Model: ΔP = λ × OrderFlow + ε
where OrderFlow = buy volume - sell volume
Estimation method:
1. Compute ΔP and OrderFlow in 5-minute windows
2. Regress ΔP = α + λ × OrderFlow
3. λ = price change caused by one unit of order flow
Interpretation:
Large λ -> poor liquidity, high impact
Small λ -> good liquidity, large orders can be executed cheaply
Typical China A-share values:
Large cap (CSI 300): λ ≈ 0.001-0.005
Mid cap (CSI 500): λ ≈ 0.005-0.02
Small cap (CSI 1000): λ ≈ 0.02-0.1
Liquidity Measures
| Metric | Formula | Advantages | Disadvantages |
|---|---|---|---|
| Amihud illiquidity | ` | R_t | / Volume_t` |
| Roll implied spread | 2√(-Cov(R_t, R_{t-1})) |
Requires only daily data | Fails when covariance is positive |
| LOT zero-return ratio | zero-return days / total days | Intuitive | Too coarse |
| Turnover ratio | volume / free float | Simple and intuitive | Does not reflect price impact |
| Traded value | average daily notional | Absolute liquidity | Does not reflect relative impact |
Amihud calculation (China A-shares):
ILLIQ = (1/D) × Σ(|R_d| / VOL_d) (D=trading days, monthly)
Normalization: ILLIQ × 10^6 (for readability)
Screening rules:
ILLIQ < 0.5 -> high liquidity (large-cap blue chips)
ILLIQ 0.5-5 -> medium liquidity
ILLIQ > 5 -> low liquidity (trade cautiously)
Strategy application:
- Liquidity
常见问题
什么是买卖价差?
它是买方愿意出的最高价与卖方要求的最低价之间的差距。
它涵盖 A 股吗?
涵盖。它包括 A 股的集合竞价、收盘集合竞价和大宗交易。
什么是 VPIN?
VPIN 是衡量订单流毒性的指标,显示有多少交易可能来自知情交易者。
详情
作者的原始描述
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.
repo: HKUDS/Vibe-Trading
热度
- GitHub 星标
- 37k
- 排名
- #7531
- 许可证
- MIT
- 更新时间
- 2026/11/1
评论
- …