本文へスキップ
Skillpedia
分析とスプレッドシート37k · #7540

pair-trading

できること

このスキルは、関連する2つの資産が、通常の価格の関係に戻ると賭ける戦略をテストします。資産間の統計的な乖離を研究するトレーダー向けです。

使う場面

  • ✓密接に関連する2つの株や暗号資産があり、平均回帰の戦略をテストしたいとき。
  • ✓2つの資産の価格比率が、その平均から大きく離れたとき。
  • ✓2つのポジションからなる単純な取引のアイデアをテストしたいとき。

スキルのリンク

https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/pair-trading/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/pair-trading/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“コカ・コーラとペプシの間で、60日の振り返り期間を使ってペア取引をテストしてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

このスキルは、2つの資産の価格比率を追跡し、その乖離がどれくらい異常かを示すZスコアに変換します。乖離が大きいときに取引を開き、平均の近くに戻ったときに閉じます。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

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
よくある質問

いくつの商品が必要ですか?

ちょうど2つです。この戦略は、資金を2つに均等に分けます。

Zスコアとは何を意味しますか?

現在の価格比率が、その平均から標準偏差何個分離れているかを示します。

ポジションサイズは正確に決まりますか?

いいえ。資金の均等な分割を使い、正確なヘッジ比率は計算しません。

詳細

作者による元の説明

Pair trading strategy. Trades mean reversion using the spread/ratio Z-score of two correlated instruments. Requires at least two instruments.

repo: HKUDS/Vibe-Trading

人気

GitHubのスター
37k
ランキング
#7540
ライセンス
MIT
更新日
2026/11/1

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル