pair-trading
하는 일
이 스킬은 두 관련 자산이 평소의 가격 관계로 되돌아갈 것이라는 전략을 시험합니다. 두 자산 사이의 통계적 격차를 연구하는 트레이더를 위한 스킬입니다.
사용하는 경우
- ✓밀접하게 관련된 두 주식이나 코인이 있고 평균회귀 전략을 시험하고 싶을 때.
- ✓두 자산의 가격 비율이 평균에서 크게 벗어났을 때.
- ✓두 포지션으로 구성된 단순한 거래 아이디어를 시험하고 싶은 경우.
스킬 링크
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일 룩백을 사용해 Coca-Cola와 Pepsi 사이의 페어 트레이드를 시험해 주세요.”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
스킬은 두 자산의 가격 비율을 추적하고, 이를 격차가 얼마나 드문지 보여 주는 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
자주 묻는 질문
종목이 몇 개 필요한가요?
정확히 두 개입니다. 전략은 자본을 두 자산에 똑같이 나눕니다.
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
394k에이전트가 Google Places로 장소를 검색하고, 세부 정보와 리뷰를 가져오고, 장소 이름을 확인하며, 스크립트용 JSON을 출력하도록 돕습니다.