Agent skill

Pair Trading Signals

by HKUDS in HKUDS/Vibe-Trading

Trades mean reversion between two correlated instruments using the Z-score of their price ratio, going long one leg and short the other when the ratio stretches.

MITAuto-check passedBusiness, Finance & HR

Install Pair Trading Signals

skills CLI
$ npx skills add HKUDS/Vibe-Trading --skill pair-trading -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install HKUDS/Vibe-Trading pair-trading --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/HKUDS/Vibe-Trading.git skills-src && mkdir -p .claude/skills && cp -r skills-src/agent/src/skills/pair-trading .claude/skills/pair-trading && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
pair-trading
GitHub stars
35k
Token cost
~651 tokens
SKILL.md length
272 words
Files
2
Skills in repo
89
Repo updated
First seen
Licence
MIT

At a glance

Trades mean reversion between two correlated instruments using the Z-score of their price ratio, going long one leg and short the other when the ratio stretches.

  • Works in 4 steps: Compute the price ratio: ratio = close_A… → Rolling mean and standard deviation:… → Z-score: z = (ratio - mean) / std → …
  • Trading the ratio between two correlated stocks or coins
  • SKILL.md covers Purpose, Signal Logic, Implementation Notes and Parameters, plus 4 more sections
  • Runs Python scripts from its folder; calls pip

What it does

The skill picks two highly correlated instruments, such as stocks in one industry or BTC and ETH, and tracks how far their price ratio drifts from its rolling mean. It computes the ratio, the rolling mean and standard deviation, and a Z-score. A Z-score below the negative entry threshold goes long A and short B, one above the positive threshold goes short A and long B, and a small absolute Z closes the position.

Implementation notes are strict: the codes array must hold exactly two instruments, A and B take opposite signals with 50% of capital each and no hedge-ratio calculation, and the two date indexes must be aligned with an inner join. Defaults are a 60-period lookback, entry at 2.0 and exit at 0.5, and Z-scores are NaN before the window fills, so signals are set to 0. Example configs cover A-shares through tushare and crypto through OKX.

When your agent uses it

  • Trading the ratio between two correlated stocks or coins
  • Setting entry and exit Z-score thresholds for a mean-reversion strategy
  • Writing a long-short signal engine for exactly two instruments

Example prompts

  • “Write a pair trading signal engine for 601318.SH and 601628.SH.”
  • “Backtest BTC-USDT against ETH-USDT with an entry Z-score of 2.0 and an exit of 0.5.”
  • “Why do I get NaN signals at the start of my pair trading backtest?”
  • “Align the dates of the two instruments before computing the ratio.”

Requirements

  • Python with pandas and numpy
  • Data for exactly two correlated instruments

Workflow steps

4 steps, taken from the first numbered list in SKILL.md.

  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

What it can do on your machine

Read from SKILL.md and the folder at commit e532650. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships script files (Python), which the agent can run.

    Shell commands in SKILL.md call:

    • pip

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use pip, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Pair Trading Signals loads about 651 tokens when it runs. Until then it costs about 39 tokens; SKILL.md has 272 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~39
When it runs · the whole SKILL.md, loaded when a task matches
~651

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from HKUDS/Vibe-Trading at commit e532650, republished under its MIT licence (© HKUDS). 272 words, ~651 tokens.

Download SKILL.mdSave it as .claude/skills/pair-trading/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
pair-trading
description
Pair trading strategy. Trades mean reversion using the spread/ratio Z-score of two correlated instruments. Requires at least two instruments.
category
strategy

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

ParameterDefaultDescription
lookback60Lookback window for mean and standard deviation
entry_z2.0Entry Z-score threshold
exit_z0.5Exit Z-score threshold

Example config.json

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:

json
{
  "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

bash
pip install pandas numpy

Signal Convention

  • Instrument A: 0.5 = long, -0.5 = short, 0 = flat
  • Instrument B: direction is opposite to A

© HKUDS, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file in agent/src/skills/pair-trading of HKUDS/Vibe-Trading.

  • SKILL.md
  • example_signal_engine.py

Open the folder on GitHubat commit e532650

Compare with similar skills

Pair Trading Signals next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Pair Trading Signals compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Pair Trading Signals this skillHKUDS/Vibe-Trading35k—~651Automated safety check: PassMIT
Tushare Datazillionare/zillionare3212 repos~2.3kAutomated safety check: PassNone
Quant Blog Writingzillionare/zillionare321—~895Automated safety check: PassNone
Statistical Data Analysislingzhi227/agent-research-skills386—~886Automated safety check: PassNone
Q-EDA Exploratory AnalysisTyrealQ/q-skills108—~1.1kAutomated safety check: PassMIT
Tooluniverse Epigenomicswu-yc/LabClaw1.1k2 repos~14kAutomated safety check: PassNone

Similar skills

  • Tushare Data

    zillionare/zillionare

    面向中文自然语言的 Tushare 数据研究技能。用于把“看看这只股票最近怎么样”“帮我查财报趋势”“最近哪个板块最强”“北向资金在买什么”“给我导出一份行情数据”这类请求,转成可执行的数据获取、清洗、对比、筛选、导出与简要分析流程。适用于 A 股、指数、ETF/基金、财务、估值、资金流、公告新闻、板块概念与宏观数据等研究场景。

    321 GitHub starsUsed in 2 repos~2.3k tokens
    Business, Finance & HRAuto-check passed
  • Quant Blog Writing

    zillionare/zillionare

    撰写文笔精炼、富有深度的量化交易博文,论点清晰、证据确凿、叙事层次更加丰富。适用于量化交易博文、因子研究、回测复盘、数据源排查、市场微观结构、策略原理、风险控制、职业观察、量化人物故事等选题。文章将聚焦具体角度,提供详实的大纲、证据规划及成稿,力求内容兼具思想深度与诚实性,而非单纯口号式宣传;同时,通过人物经历、引言、贡献及行业背景的融入,让文章更具可读性和吸引力。

    321 GitHub stars~895 tokensUpdated yesterday
    Business, Finance & HRAuto-check passed
  • Statistical Data Analysis

    lingzhi227/agent-research-skills

    Writes statistical analysis code for experimental data, runs it through a four-round review, and reports effect sizes, p-values and confidence intervals.

    386 GitHub stars~886 tokensUpdated 7 mo ago
    Data & AnalyticsAuto-check passed
  • Runs exploratory data analysis on tabular data after you confirm each column's measurement level, then writes CSV tables and a narrative summary.

    108 GitHub stars~1.1k tokensUpdated 16 days ago
    Data & AnalyticsAuto-check passed
  • Production-ready genomics and epigenomics data processing for BixBench questions.

    1.1k GitHub starsUsed in 2 repos~14k tokens
    Research & ScienceAuto-check passed
  • Backtesting

    gauss314/skills

    Academic backtesting framework for quantitative research. An agent skill from gauss314/skills.

    247 GitHub stars~2.4k tokensUpdated 3 mo ago
    Business, Finance & HRAuto-check passed

More from HKUDS/Vibe-Trading

All 89 skills in this repo
  • Eastmoney Market Data

    HKUDS/Vibe-Trading

    Index of Eastmoney's free, no-token market data interfaces for China A-shares and Hong Kong stocks: fund flows, dragon-tiger lists, margin trading, reports and news.

    35k GitHub stars~1k tokensUpdated yesterday
    Auto-check passed
  • OKX Market Data

    HKUDS/Vibe-Trading

    Retrieves public OKX cryptocurrency market data such as spot prices, candlesticks, funding rates and open interest through the OKX V5 REST API, with no authentication.

    35k GitHub stars~1.3k tokensUpdated yesterday
    Auto-check passed
  • SEC EDGAR Filings Fetcher

    HKUDS/Vibe-Trading

    Fetches U.S. SEC EDGAR data: resolves tickers to CIK numbers, lists recent 10-K, 10-Q and 8-K filings with document URLs, and pulls XBRL financial series.

    35k GitHub stars~1.4k tokensUpdated yesterday
    Auto-check passed
  • A-Share ST Risk Screener

    HKUDS/Vibe-Trading

    Predicts whether a mainland China A-share company risks an ST or *ST warning after its next annual report, using financial thresholds and Sina penalty records.

    35k GitHub stars~4.9k tokensUpdated yesterday
    Auto-check passed
  • Breaks a structural trend such as AI infrastructure into its physical supply chain and ranks lesser-known listed companies sitting on each bottleneck.

    35k GitHub stars~2.7k tokensUpdated yesterday
    Auto-check passed
  • Plans and drafts an eight-part, roughly 120k-word investigative series on one company, built around a strict fact-check pass rather than fast drafting.

    35k GitHub stars~2.4k tokensUpdated yesterday
    Auto-check passed

Questions about Pair Trading Signals

What does Pair Trading Signals do?

Trades mean reversion between two correlated instruments using the Z-score of their price ratio, going long one leg and short the other when the ratio stretches. The skill picks two highly correlated instruments, such as stocks in one industry or BTC and ETH, and tracks how far their price ratio drifts from its rolling mean. It computes the ratio, the rolling mean and standard deviation, and a Z-score.

When should I use Pair Trading Signals?

Pair Trading Signals fits situations like: trading the ratio between two correlated stocks or coins; setting entry and exit Z-score thresholds for a mean-reversion strategy; writing a long-short signal engine for exactly two instruments.

How do I install Pair Trading Signals in Claude Code?

Run `npx skills add HKUDS/Vibe-Trading --skill pair-trading -a claude-code`. Or copy the skill folder (agent/src/skills/pair-trading in HKUDS/Vibe-Trading) into .claude/skills/pair-trading in your project. Claude Code loads it when a task matches its description.

How do I install Pair Trading Signals in Codex?

Run `npx skills add HKUDS/Vibe-Trading --skill pair-trading -a codex`. Or copy the skill folder (agent/src/skills/pair-trading in HKUDS/Vibe-Trading) into .agents/skills/pair-trading in your project. Codex loads it when a task matches its description.

Can I use Pair Trading Signals in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add HKUDS/Vibe-Trading --skill pair-trading -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/pair-trading, .gemini/skills/pair-trading, .github/skills/pair-trading and .opencode/skills/pair-trading in your project.

What does Pair Trading Signals need to run?

Going by SKILL.md and its folder, Pair Trading Signals needs Python for the scripts in its folder and the command-line tools its instructions call (pip). Our summary lists: Python with pandas and numpy; Data for exactly two correlated instruments.

Does Pair Trading Signals access the network?

SKILL.md contains no URLs. Its commands use pip, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Pair Trading Signals safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Pair Trading Signals use?

Pair Trading Signals is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Pair Trading Signals use?

About 651 tokens (SKILL.md is roughly 2.6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Pair Trading Signals?

Skills that share tags, products or a category with Pair Trading Signals: Tushare Data (zillionare/zillionare, 321 stars), Quant Blog Writing (zillionare/zillionare, 321 stars), Statistical Data Analysis (lingzhi227/agent-research-skills, 386 stars) and Q-EDA Exploratory Analysis (TyrealQ/q-skills, 108 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Pair Trading Signals?

HKUDS (a GitHub organization) maintains it in HKUDS/Vibe-Trading, which has 35,043 GitHub stars. The repository holds 89 skills in this directory. The repository was last updated on October 8, 2026.

Source: HKUDS/Vibe-Trading on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.