본문으로 건너뛰기
Skillpedia
분석 및 스프레드시트37k · #7540

pair-trading

하는 일

이 스킬은 두 관련 자산이 평소의 가격 관계로 되돌아갈 것이라는 전략을 시험합니다. 두 자산 사이의 통계적 격차를 연구하는 트레이더를 위한 스킬입니다.

사용하는 경우

  • ✓밀접하게 관련된 두 주식이나 코인이 있고 평균회귀 전략을 시험하고 싶을 때.
  • ✓두 자산의 가격 비율이 평균에서 크게 벗어났을 때.
  • ✓두 포지션으로 구성된 단순한 거래 아이디어를 시험하고 싶은 경우.

스킬 링크

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

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/pair-trading/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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

  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
자주 묻는 질문

종목이 몇 개 필요한가요?

정확히 두 개입니다. 전략은 자본을 두 자산에 똑같이 나눕니다.

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

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬