Chuyển đến nội dung
Skillpedia
Phân tích và bảng tính37k · #7540

pair-trading

Skill này làm gì

Skill này kiểm thử một chiến lược cược rằng hai tài sản liên quan sẽ quay về mối quan hệ giá thông thường. Skill dành cho trader nghiên cứu khoảng cách thống kê giữa các tài sản.

Khi nào nên dùng

  • ✓Khi bạn có hai cổ phiếu hoặc coin liên quan chặt chẽ và muốn kiểm thử chiến lược hồi quy về trung bình.
  • ✓Khi tỷ lệ giá giữa hai tài sản đi xa mức trung bình của nó.
  • ✓Khi bạn muốn kiểm thử một ý tưởng giao dịch đơn giản với hai vị thế.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/pair-trading/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Kiểm thử giao dịch cặp giữa Coca-Cola và Pepsi với cửa sổ nhìn lại 60 ngày.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill theo dõi tỷ lệ giá giữa hai tài sản và chuyển nó thành điểm Z, cho biết khoảng cách này bất thường đến đâu. Nó mở giao dịch khi khoảng cách lớn và đóng khi nó quay về gần mức trung bình.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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
Câu hỏi thường gặp

Tôi cần bao nhiêu công cụ?

Đúng hai. Chiến lược chia vốn đều giữa hai bên.

Điểm Z nghĩa là gì?

Nó cho biết tỷ lệ giá hiện tại lệch khỏi trung bình bao nhiêu độ lệch chuẩn.

Skill có định khối lượng vị thế chính xác không?

Không. Nó chia vốn đều nhau và không tính tỷ lệ phòng hộ chính xác.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
37k
Vị trí xếp hạng
#7540
Giấy phép
MIT
Cập nhật
1/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự