Market Microstructure 标志

Market Microstructure

组织热门
HKUDS
market-microstructure

市场微观结构:买卖价差分析、订单流毒性指标(VPIN / Kyle lambda)、流动性指标(Amihud / Roll)、价格冲击模型、限价订单簿分析,以及中国 A 股集合竞价和大宗交易机制。

Add to TypingMind

概览

发布者HKUDS
代码仓库Vibe-Trading
技能名称market-microstructure
星标数
33.6K
复刻数
5.5K
附带文件
仅含指令
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 HKUDS 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Market Microstructure AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/HKUDS/Vibe-Trading/tree/main/agent/src/skills/market-microstructure
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HKUDS/Vibe-Trading.git /tmp/Vibe-Trading
mkdir -p .claude/skills
cp -r /tmp/Vibe-Trading/agent/src/skills/market-microstructure .claude/skills/market-microstructure
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Market Microstructure,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Market Microstructure。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Market Microstructure 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

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:

MetricFormulaMeaning
Quoted spreadAsk - BidBest spread shown in the limit order book
Effective spread`2 ×trade price - mid price
Realized spread2 × 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

MetricFormulaAdvantagesDisadvantages
Amihud illiquidity`R_t/ Volume_t`
Roll implied spread2√(-Cov(R_t, R_{t-1}))Requires only daily dataFails when covariance is positive
LOT zero-return ratiozero-return days / total daysIntuitiveToo coarse
Turnover ratiovolume / free floatSimple and intuitiveDoes not reflect price impact
Traded valueaverage daily notionalAbsolute liquidityDoes 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 factor: low-liquidity stocks tend to earn long-run excess return (liquidity premium)
    - Liquidity monitor: sudden rise in ILLIQ -> warning of liquidity drying up

Analysis Framework

1. Price-Impact Models

Power-law impact:

Naming. This is the concave impact term from the Almgren-Chriss literature, and it is neither linear (the exponent is 0.6, not 1) nor Almgren-Chriss optimal execution — no trading trajectory, no permanent/temporary split and no risk-aversion parameter is computed here or anywhere in this repo. The tested implementation is src.quantlib.impact.sqrt_impact; call it rather than retyping the formula.

Model: impact = η × σ × (Q / V)^0.6
  η: impact coefficient, about 0.5-1.5 for China A-shares
  σ: daily volatility
  Q: traded quantity (shares)
  V: average daily volume (shares)

Example:
  Sell 100,000 shares of Kweichow Moutai
  Average daily volume 5,000,000 shares, daily volatility 1.8%
  impact = 1.0 × 0.018 × (100000/5000000)^0.6
         = 0.018 × 0.0085
         = 0.015% (1.5bp, acceptable)

  Sell 100,000 shares of a small-cap stock
  Average daily volume 500,000 shares, daily volatility 3.0%
  impact = 1.0 × 0.03 × (100000/500000)^0.6
         = 0.03 × 0.076
         = 0.23% (23bp, should be executed in slices)

Execution-splitting methods:
  TWAP: uniform in clock time -> simple but ignores market state
  VWAP: volume-profile execution -> better matches market rhythm
  IS: minimize Implementation Shortfall -> optimal but requires real-time optimization

Nonlinear impact (square-root model):

impact = σ × √(Q / (ADV × T))
  σ: daily volatility
  Q: total trade size
  ADV: average daily traded value
  T: execution days

Applicable to: large trades (Q/ADV > 5%)

2. Limit Order Book Analysis

Depth metrics:
  Level 1 depth: queue size at the best bid and best ask
  Level 5 depth: total queue size across the first 5 levels
  Depth asymmetry: (Bid depth - Ask depth) / (Bid depth + Ask depth)
    > 0 -> stronger bid side, price tends to rise
    < 0 -> stronger ask side, price tends to fall

Resilience:
  The speed at which the book recovers after a large-order impact
  Fast recovery -> good liquidity, temporary impact
  Slow recovery -> poor liquidity, persistent impact

China A-share LOB characteristics:
  - The shallowest depth is in the 15 minutes before the open (highest information asymmetry)
  - Depth improves from 10:00-10:30 (institutions begin participating)
  - Best depth is from 14:00-14:57 (most intraday information has been digested)
  - During the 14:57-15:00 closing auction, depth changes sharply (late-day grabbing / dumping)

Order-book imbalance signal:
  OIR = (Bid_vol - Ask_vol) / (Bid_vol + Ask_vol)
  Rolling 5-minute OIR > 0.3 -> short-term bullish signal (accuracy about 55-60%)
  Note: in China A-shares, large orders are often rapidly added and canceled (icebergs / spoofing), so OIR signals need filtering

3. Flash-Crash Mechanism and Prevention

Flash-crash characteristics:
  1. Price drops more than 5% within minutes
  2. Volume first expands, then collapses (liquidity evaporates)
  3. Bid-ask spread widens sharply (market makers pull quotes)
  4. Followed by a V-shaped rebound (not always fully recovered)

Triggers:
  - Large market order + thin liquidity -> punches through multiple levels instantly
  - Stop-loss chain -> initial selloff triggers more stop orders
  - Algo resonance -> multiple trend-following algos sell simultaneously
  - ETF discount arbitrage -> ETF redemption and constituent selling intensify the drop

Preventive measures:
  1. Use limit orders instead of market orders: specify the maximum acceptable price
  2. Monitor VPIN: if VPIN breaks above 0.5 -> stop trading
  3. Liquidity threshold: exclude instruments with Amihud > 10
  4. Spread monitor: if spread widens suddenly to >5x normal -> pause orders
  5. Time avoidance: do not execute large orders in the first 15 minutes after open or the last 5 minutes before close

China A-share flash-crash cases:
  2015 Jun-Jul: thousands of stocks hit limit-down, with VPIN staying elevated
  2020-07-13: Shanghai Composite plunged and then rebounded in a V-shape
  Pattern: liquidity dries up -> limit-down locking (China-specific) -> next-day panic selling

4. China A-Share-Specific Microstructure

Call-auction strategy:
  9:15-9:20: orders can be entered and canceled, mostly probing quotes (low reference value)
  9:20-9:25: orders can be entered but not canceled, so real intent is revealed
  Signal: after 9:20, buy orders far exceed sell orders -> likely gap-up open

  Execution: place orders at 9:24:50 (last 10 seconds of the call auction)
  Risk: cannot cancel, and the final execution price may deviate from expectation

Closing call auction (14:57-15:00):
  Feature: closing price is decided within 3 minutes, with concentrated institutional rebalancing and index-fund flows
  Signal: closing-auction volume > 10% of the whole day -> institutions are rebalancing

  Strategy application:
  - VWAP algos should finish most of execution before 14:50, leaving a small residual for the close
  - Avoid placing large orders after 14:57 (high price uncertainty)

Block-trade discount signal:
  Discount = (block-trade price - closing price) / closing price
  Discount < -5%: seller is eager to exit -> short-term bearish
  Discount > -2%: traded near market price -> may be turnover rather than reduction

  Buyer identity:
  Well-known institutional seat buys -> positive signal
  Same broker on both sides -> may be wash trading (neutral)

Output Format

Microstructure analysis report:

=== Liquidity Diagnosis ===
Instrument: 000858.SZ Wuliangye
Date: 2026-03-28
Average daily traded value: 2.8 billion RMB  Turnover ratio: 0.85%
Amihud: 0.32 (high liquidity)
Effective spread: 0.05% (2.5bp)
Kyle Lambda: 0.003

=== Order-Flow Analysis ===
VPIN: 0.28 (normal)
Order-book imbalance (OIR): +0.12 (mild bid-side bias)
Net large-order buying: +230 million RMB (institutional buying bias)

=== Trading-Cost Estimate ===
Planned trade size: 500,000 shares (about 40 million RMB)
Estimated impact cost: 0.08% (32k RMB)
Commission: 0.025% (10k RMB)
Stamp duty: 0.05% (20k RMB, sell side)
Total one-way transaction cost: about 0.16%

=== Execution Suggestion ===
Recommended strategy: VWAP
Execution window: 10:00-14:50 (avoid the open and the close)
Number of slices: 5-8 (about 60k-100k shares per slice)
Time sensitivity: low (VPIN is normal, no urgency to execute)

Notes

  1. Data requirement is high: microstructure analysis requires tick-level / Level-2 data, while ordinary daily data only supports rough measures such as Amihud / Roll
  2. China A-share Level-2 data: ten-level depth data from SSE / SZSE requires a paid subscription, costing roughly 50k-200k RMB per year
  3. High-frequency trading restrictions: China A-shares strictly prohibit programmatic quote-cancel manipulation (spoofing), so microstructure signals are for analysis only, not for HFT strategies
  4. VPIN calibration: bucket size has a large impact on results and must be adjusted for instrument liquidity; one parameter does not fit all
  5. Cross-market differences: China A-share T+1 settlement and daily price limits make its microstructure significantly different from textbook US-equity models
  6. Illusion of liquidity: high turnover in some China A-shares comes from speculative matched trading and does not represent true liquidity

Dependencies

bash
pip install pandas numpy scipy

常见问题

Market Microstructure AI 技能有什么作用?

市场微观结构:买卖价差分析、订单流毒性指标(VPIN / Kyle lambda)、流动性指标(Amihud / Roll)、价格冲击模型、限价订单簿分析,以及中国 A 股集合竞价和大宗交易机制。

为什么在 TypingMind 中使用 Market Microstructure?

因为您只需安装一次,就能搭配任何模型使用。Market Microstructure 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Market Microstructure?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/HKUDS/Vibe-Trading/tree/main/agent/src/skills/market-microstructure。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Market Microstructure?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Market Microstructure 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Market Microstructure 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Market Microstructure AI 技能免费吗?

是的。HKUDS 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇