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がスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
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
- Compute the price ratio:
ratio = close_A / close_B - Rolling mean and standard deviation:
mean = ratio.rolling(lookback).mean(),std = ratio.rolling(lookback).std() - Z-score:
z = (ratio - mean) / std - 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 (
codesarray 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
codesmust 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
コメント
- …
このリポジトリの他のスキル
vibe-trading
37kバックテスト、ファクター分析、オプション価格、多くの市場にまたがる市場データを含む、金融リサーチの完全なツールキットをエージェントに与えます。
adr-hshare
37k中国企業が複数の市場に上場している価格差、例えば米国のADRと香港株の差を比べる方法をエージェントに示します。
akshare
37kエージェントが、APIキーなしで、中国と世界の株式、先物、外国為替、経済指標の無料の市場データを取得できるよう支援します。
alpha-zoo
37k既製のストックファクターのライブラリを閲覧し、選んだ市場で一群のファクターがリターンをどれだけ予測するかを検証できるよう支援します。
似ているスキル
gitcrawl
394k保存されたGitHubのイシューとプルリクエストのアーカイブを検索し、重複をまとめ、GitHub上の現在の状態を確認するようエージェントを支援します。
slacrawl
394kローカルのSlackアーカイブ内のメッセージを検索して件数を数え、アーカイブの新しさを確認し、必要に応じて更新するようエージェントを支援します。
goplaces
394kGoogle Placesを使って、場所を検索し、詳細や口コミを取得し、場所の名前を解決するようエージェントを支援します。スクリプト用にJSON出力もできます。