Agent SkillsHKUDS/Vibe-Trading › pair-trading

pair-trading

GitHub

基于均值回归原理,对两只高度相关资产的价格比率Z-score进行监控。当偏离超过阈值时执行反向开仓,回归均值时平仓。需严格配置两个标的及参数,适用于量化策略开发。

agent/src/skills/pair-trading/SKILL.md HKUDS/Vibe-Trading

Trigger Scenarios

需要构建配对交易策略 实现基于Z-score的均值回归信号生成 配置双资产对冲组合

Install

npx skills add HKUDS/Vibe-Trading --skill pair-trading -g -y
More Options

Non-standard path

npx skills add https://github.com/HKUDS/Vibe-Trading/tree/main/agent/src/skills/pair-trading -g -y

Use without installing

npx skills use HKUDS/Vibe-Trading@pair-trading

指定 Agent (Claude Code)

npx skills add HKUDS/Vibe-Trading --skill pair-trading -a claude-code -g -y

安装 repo 全部 skill

npx skills add HKUDS/Vibe-Trading --all -g -y

预览 repo 内 skill

npx skills add HKUDS/Vibe-Trading --list

SKILL.md

Frontmatter
{
    "name": "pair-trading",
    "category": "strategy",
    "description": "Pair trading strategy. Trades mean reversion using the spread\/ratio Z-score of two correlated instruments. Requires at least two instruments."
}

Pair Trading Strategy

Purpose

Select two highly correlated instruments (such as stocks from the same industry or BTC/ETH), monitor how far their price ratio (or spread) deviates from the mean, and trade against extreme deviations while waiting for mean reversion.

Signal Logic

  1. Compute the price ratio: ratio = close_A / close_B
  2. Rolling mean and standard deviation: mean = ratio.rolling(lookback).mean(), std = ratio.rolling(lookback).std()
  3. Z-score: z = (ratio - mean) / std
  4. Signal generation:
    • Z < -entry_z → long A, short B (ratio is too low, expected to revert)
    • Z > +entry_z → short A, long B (ratio is too high, expected to revert)
    • |Z| < exit_z → close the position (reverted back near the mean)

Implementation Notes

  • Pair trading requires exactly two instruments (codes array length = 2)
  • The first instrument is A (leg1), and the second is B (leg2)
  • Signals for A and B are opposite: when A is long, B is short, and vice versa
  • Equal-weight allocation only: A and B each take 50% of capital, with no precise hedge-ratio calculation

Parameters

Parameter Default Description
lookback 60 Lookback window for mean and standard deviation
entry_z 2.0 Entry Z-score threshold
exit_z 0.5 Exit Z-score threshold

Example config.json

{
  "source": "tushare",
  "codes": ["601318.SH", "601628.SH"],
  "start_date": "2023-01-01",
  "end_date": "2024-12-31",
  "initial_cash": 1000000,
  "commission": 0.001,
  "extra_fields": null
}

Cryptocurrency version:

{
  "source": "okx",
  "codes": ["BTC-USDT", "ETH-USDT"],
  "start_date": "2024-01-01",
  "end_date": "2024-12-31",
  "initial_cash": 1000000,
  "commission": 0.001,
  "extra_fields": null
}

Common Pitfalls

  • codes must contain exactly 2 instruments, no more and no less
  • The date indexes of the two instruments must be aligned (use an inner join), otherwise the ratio calculation will be wrong
  • Before the lookback window is filled, Z-scores are NaN, so fill signals with 0
  • Do not generate same-direction signals for both A and B; pair trading is fundamentally a long-short hedge

Dependencies

pip install pandas numpy

Signal Convention

  • Instrument A: 0.5 = long, -0.5 = short, 0 = flat
  • Instrument B: direction is opposite to A

Version History

  • 0aa45a9 Current 2026-07-24 17:47

Same Skill Collection

agent/src/skills/adr-hshare/SKILL.md
agent/src/skills/akshare/SKILL.md
agent/src/skills/alpha-zoo/SKILL.md
agent/src/skills/ashare-pre-st-filter/SKILL.md
agent/src/skills/asset-allocation/SKILL.md
agent/src/skills/backtest-diagnose/SKILL.md
agent/src/skills/behavioral-finance/SKILL.md
agent/src/skills/candlestick/SKILL.md
agent/src/skills/ccxt/SKILL.md
agent/src/skills/chanlun/SKILL.md
agent/src/skills/commodity-analysis/SKILL.md
agent/src/skills/corporate-events/SKILL.md
agent/src/skills/correlation-analysis/SKILL.md
agent/src/skills/correlation-regime/SKILL.md
agent/src/skills/cross-market-strategy/SKILL.md
agent/src/skills/crypto-derivatives/SKILL.md
agent/src/skills/data-routing/SKILL.md
agent/src/skills/defi-yield/SKILL.md
agent/src/skills/dividend-analysis/SKILL.md
agent/src/skills/doc-reader/SKILL.md
agent/src/skills/earnings-forecast/SKILL.md
agent/src/skills/earnings-revision/SKILL.md
agent/src/skills/eastmoney/SKILL.md
agent/src/skills/edgar-sec-filings/SKILL.md
agent/src/skills/elliott-wave/SKILL.md
agent/src/skills/event-driven/SKILL.md
agent/src/skills/execution-model/SKILL.md
agent/src/skills/factor-research/SKILL.md
agent/src/skills/fund-analysis/SKILL.md
agent/src/skills/fundamental-filter/SKILL.md
agent/src/skills/geopolitical-risk/SKILL.md
agent/src/skills/global-macro/SKILL.md
agent/src/skills/harmonic/SKILL.md
agent/src/skills/hedging-strategy/SKILL.md
agent/src/skills/hk-connect-flow/SKILL.md
agent/src/skills/ichimoku/SKILL.md
agent/src/skills/investor-lenses/SKILL.md
agent/src/skills/liquidation-heatmap/SKILL.md
agent/src/skills/macro-analysis/SKILL.md
agent/src/skills/market-microstructure/SKILL.md
agent/src/skills/minute-analysis/SKILL.md
agent/src/skills/ml-strategy/SKILL.md
agent/src/skills/mootdx/SKILL.md
agent/src/skills/multi-factor/SKILL.md
agent/src/skills/okx-market/SKILL.md
agent/src/skills/onchain-analysis/SKILL.md
agent/src/skills/options-advanced/SKILL.md
agent/src/skills/options-payoff/SKILL.md
agent/src/skills/options-strategy/SKILL.md

Metadata

Files
0
Version
9806936
Hash
6feb5221
Indexed
2026-07-24 17:47

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-16 20:12
浙ICP备14020137号-1 $mapa de visitantes$