Логотип 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 по мере необходимости, поэтому токены расходуются только при подходящем запросе.

  • Работает с любой большой языковой моделью

    Навыки ИИ — это обычный Markdown, а не код для конкретного поставщика, поэтому они работают с GPT, Claude, Gemini, Grok и локальными моделями.

  • Всё необходимое — в инструкциях

    Всё необходимое для модели содержится в инструкциях — никаких дополнительных файлов для синхронизации.

  • Открытый исходный код

    Издатель навыка на GitHub — HKUDS. Перед установкой изучите исходные материалы.

Установка

Установите навык ИИ Market Microstructure в TypingMind, чтобы использовать его с любой LLM, или добавьте его в другой агент, который умеет читать SKILL.md.

1

Установка в TypingMind

TypingMind устанавливает навык прямо из его папки на GitHub: читает SKILL.md, собирает файлы ресурсов и сохраняет результат локально.

  1. Откройте приложение и перейдите в раздел «Плагины → Навыки».
  2. Выберите «Установить из GitHub».
  3. Вставьте указанную ниже ссылку на папку навыка и подтвердите установку.
    https://github.com/HKUDS/Vibe-Trading/tree/main/agent/src/skills/market-microstructure
  4. Включите навык в каждом чате, где хотите его использовать.
Плагины → Навыки → Добавить навык → По ссылке GitHub, затем вставьте ссылку на папку и нажмите «Продолжить».
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

Включите навык Market Microstructure в любом чате TypingMind, и дальше модель всё сделает сама. Его название и описание хранятся в системном промпте, а при появлении подходящего запроса модель сама загружает полные инструкции. Вам не нужно вызывать навык вручную, и до фактического использования он не расходует токены.

Модель сама загружает навык Market Microstructure, как только появляется подходящий для него запрос.

Работает с любой моделью ИИ

Навыки ИИ — это обычные инструкции в Markdown, а не код для конкретного поставщика, поэтому навык Market Microstructure не привязан к модели, для которой он был создан. Установите его один раз в TypingMind и используйте с GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama или локальной моделью, которую запускаете самостоятельно, — со своими ключами API.

  • Загружается только при необходимости

    Системный промпт содержит только название и описание. Инструкции загружаются при первом подходящем запросе, поэтому неиспользуемый навык не расходует токены.

  • Меняйте модели прямо в чате

    Навык состоит из инструкций, а не кода, поэтому смена модели не нарушает его работу: новая модель читает тот же файл 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?

Микроструктура рынка: анализ спреда между ценами покупки и продажи, метрики токсичности потока ордеров (VPIN / Kyle lambda), показатели ликвидности (Amihud / Roll), модели влияния на цену, анализ книги лимитных ордеров, а также механика аукционов открытия и блок-сделок на китайском рынке акций класса A.

Зачем использовать Market Microstructure в TypingMind?

Потому что вы устанавливаете навык один раз и используете его с любой моделью. Market Microstructure — это обычный текст в формате Markdown, а не код для конкретного поставщика, поэтому один и тот же навык работает с GPT-5, Claude, Gemini, Grok или локальной моделью. Вы можете менять модель прямо во время чата, и навык продолжит работать. TypingMind использует ваши собственные ключи API, поэтому вы платите поставщикам напрямую, а не оформляете подписку с оплатой за каждое место. Ваши навыки и чаты остаются в вашем собственном хранилище.

Как установить Market Microstructure в TypingMind?

В TypingMind откройте «Плагины → Навыки → Установить из GitHub» и вставьте https://github.com/HKUDS/Vibe-Trading/tree/main/agent/src/skills/market-microstructure. TypingMind прочитает файл SKILL.md и установит навык, который можно включать отдельно для каждого чата.

Какие модели ИИ могут использовать Market Microstructure?

Любая модель, которую вы подключите в TypingMind. Навыки ИИ — это обычные инструкции в формате Markdown, а не код для конкретного поставщика, поэтому GPT, Claude, Gemini, Grok и локальные модели могут загружать этот навык, когда запрос ему соответствует.

Со сколькими моделями ИИ можно использовать Market Microstructure?

С любым количеством. В TypingMind вы можете использовать Market Microstructure с любой моделью, которая поддерживает навыки, в том числе с GPT, Claude, Gemini, Grok, DeepSeek, Mistral и Llama. Для этого вы используете собственные ключи API.

Бесплатен ли навык ИИ Market Microstructure?

Да. Навык опубликован на GitHub по лицензии MIT. Издатель — HKUDS. Вы платите только своему поставщику ИИ за использованные токены.

Что такое навыки ИИ?

Навык ИИ — это набор инструкций, которыми модель ИИ может пользоваться каждый раз, когда ей нужно выполнить конкретную задачу. Он соответствует открытому формату Agent Skills: файл SKILL.md с названием и описанием, а также любые скрипты, шаблоны или справочные файлы, которые могут понадобиться модели. Модель читает инструкции, только когда ваш запрос соответствует навыку, поэтому установленный навык ничего не стоит, пока не используется.

Чем навыки ИИ отличаются от плагинов и серверов MCP?

Плагин или сервер MCP даёт модели новые инструменты, которые она может вызывать: при вызове где-то выполняется код и возвращает результат. Навык ИИ, напротив, даёт модели знания и описывает порядок действий: как подойти к задаче, какие шаги выполнить и каким должен быть хороший результат. Навыки — это обычный текст в формате Markdown, поэтому им не нужны сервер, ключ API или среда выполнения, и они работают с любой моделью.

Все
Логотип OpenMontageInc

3d Asset Generation

OpenMontageInc
ОрганизацияПопулярный

Создавайте, восстанавливайте и проверяйте производственные 3D-ресурсы для миров OpenMontage, а также настраивайте их маршрутизацию с помощью Atlas Cloud, fal.ai, лицензированных каталогов и Blender.

10.6K
79.2K
Файлы: 1
Открыть
Логотип OpenMontageInc

Lyria

OpenMontageInc
ОрганизацияПопулярный

Создавайте музыку с помощью Google Lyria через Gemini Interactions API и проверяйте результаты. Используйте перед вызовом OpenMontage `google_music`, созданием промптов для Lyria 3.5 или Clip, работой с генерацией музыки по изображению или…

10.6K
79.2K
Файлы: 2
Открыть
Логотип OpenMontageInc

Pika H3 Flex

OpenMontageInc
ОрганизацияПопулярный

Создавайте видео длительностью 3–15 секунд со встроенным синхронизированным аудио с помощью Pika H3 Flex через API Pika (`pika_video`). Подходит для генерации видео по тексту, настройки по первому и последнему кадру и генерации по референсам…

10.6K
79.2K
Инструкции
Открыть
Логотип affaan-m

Module Regression

affaan-m
СообществоПопулярный

Управляйте регрессиями между модулями в крупных репозиториях с помощью реестра REGRESSION.md. В нём для каждого модуля указываются зависимые от него модули и исполняемая команда приёмочной проверки. После изменений запускайте команду для изменённого модуля…

41.4K
277.3K
Файлы: 2
Открыть

Создайте своё рабочее пространство с ИИ прямо сейчас

Подпишитесь на нашу рассылку, чтобы узнавать о новых функциях и предстоящих розыгрышах 👇