Guide · Agent skill
How to use the Pair Trading Strategy agent skill
Updated · written with AI from the project's own documentation and checked against our catalogue data
The pair-trading skill teaches an AI agent how to build a mean-reversion trading strategy on two closely related assets, such as two stocks in the same industry or BTC and ETH. It tracks how far their price ratio moves from its recent average and produces long/short signals that bet on the ratio returning to normal. This guide explains what the skill does, how to install it, how to ask for it, and what limits to keep in mind.
Quick start
- 1Download the skill. Download the pair-trading ZIP from this page and keep it somewhere easy to find.
- 2Unzip into a skills folder. Unzip it into ~/.claude/skills/ for personal use, or into a project's .claude/skills/ folder for one project.
- 3Install dependencies. Run pip install pandas numpy in the environment where you will run the scripts.
- 4Choose two instruments. Pick two closely related assets, such as two stocks in one industry or BTC and ETH.
- 5Ask the agent in plain language. Describe the pair and say you want a pair-trading or mean-reversion signal, backtest or explanation.
- 6Check the config. Confirm codes has exactly two instruments and the dates align before running any backtest.
- 7Validate the results. Review the signals and test them independently before any real-money use.
What the pair-trading skill makes the agent do
An agent skill is a folder containing a SKILL.md instruction file and any supporting files. When a skill matches your request, the agent reads its instructions and follows them. This one covers pair trading: choosing two highly correlated instruments, measuring how far their price ratio deviates from the mean, and trading against extreme deviations while waiting for the ratio to revert.
The signal logic is simple. The agent computes the ratio of the two closing prices, takes a rolling mean and standard deviation over a lookback window, and converts the ratio into a Z-score. A Z-score below the negative entry threshold means going long A and short B; above the positive threshold means short A and long B; and a Z-score back inside the exit threshold closes the position.
- Ratio: close_A / close_B
- Z-score: (ratio - rolling mean) / rolling standard deviation
- Default parameters: lookback 60, entry_z 2.0, exit_z 0.5
- Sizing: equal weight, with A and B each taking 50% of capital
Install the pair-trading skill
You can install the skill in one of three ways. Download the ZIP from the skill's page on this site and unzip it into your personal skills folder at ~/.claude/skills/, or into a project's .claude/skills/ folder if you want it available only in that project. Alternatively, upload the skill in the Claude apps under Settings → Capabilities → Skills.
Make sure the skill folder is named pair-trading and contains SKILL.md, since the skill is identified by its name in that file.
- Personal install: ~/.claude/skills/pair-trading/
- Project install: .claude/skills/pair-trading/ inside your project
- Claude apps: Settings → Capabilities → Skills, then upload
Set up the requirements
The skill needs Python with pandas and numpy. Install them with the command below. You need a market data source such as Tushare (for stocks) or OKX (for crypto) only if you run the example configuration; the logic itself does not depend on a particular data provider.
- Python with pandas and numpy
- A market data source such as Tushare or OKX, only for the example config
pip install pandas numpyTrigger the skill with natural requests
You do not need special syntax. Describe the pair and what you want, and mention pair trading or mean reversion so the agent matches the skill. Name exactly two instruments, because the skill requires at least two and its code expects exactly two.
Good requests say what you want produced: a signal script, a backtest, or an explanation of the Z-score logic.
- "Use the pair-trading skill to build signals for 601318.SH and 601628.SH."
- "Draft a mean-reversion pair strategy on BTC-USDT and ETH-USDT with a 60-day lookback."
- "Explain how the Z-score entry and exit thresholds are calculated for a pair of stocks."
Configure the example run
The skill ships with an example config.json. The stock example uses the tushare source with two Chinese stock codes and a date range from 2023 to 2024. The crypto version uses the okx source with BTC-USDT and ETH-USDT. Both set initial_cash to 1000000 and commission to 0.001, and both have extra_fields set to null.
Check the codes array first. It must contain exactly two instruments, and the date indexes of the two must be aligned with an inner join before the ratio is calculated.
- codes: exactly 2 instruments
- Dates: the two series must align (inner join)
- Early rows have NaN Z-scores until the lookback window fills, so signals are filled with 0
{
"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
}Read the signal convention
The skill reports positions as signed weights. Instrument A is 0.5 when long, -0.5 when short, and 0 when flat. Instrument B always moves in the opposite direction to A. The skill also warns against generating same-direction signals for both legs, because pair trading is a long-short hedge.
- A: 0.5 long, -0.5 short, 0 flat
- B: opposite direction to A
Safety notes: scripts and network
The skill runs scripts: its package includes example_signal_engine.py, a short Python reference implementation. Read the script before running it, especially if you run it on your own machine. The skill does not use the network itself; the market data source is only needed if you run the example config.
The skill has no risk controls, no slippage modelling and no stop-losses. Its logic uses fixed parameters and equal-weight sizing, and it can lose money when the correlation between the two instruments breaks down. Do not use it for live trading with real capital without independent validation.
- Review example_signal_engine.py before running it
- No built-in stop-losses, risk limits or slippage model
- Not validated for live capital without your own testing
Tips for better results
Choose pairs that are genuinely correlated, such as two stocks in the same industry or BTC and ETH, because the logic assumes the ratio tends to revert. Test different lookback, entry_z and exit_z values in your own backtest rather than relying on the defaults. Keep the two legs aligned by date before you compare them.
- Pick pairs with a economic or industry link, not random tickers
- Vary lookback, entry_z and exit_z in your own tests
- Verify date alignment and that codes has exactly two entries
What people use it for
- Drafting a mean-reversion signal script for two stocks in the same industry.
- Building a backtest of a long-short pair on BTC-USDT and ETH-USDT.
- Learning how Z-score entry and exit thresholds are calculated.
- Adapting the example signal engine as a starting point inside the Vibe-Trading framework.
Frequently asked questions
Is the pair-trading skill free?
The skill is released under the MIT licence, as stated for this item. Check the licence file in the source repository for the full terms before reusing it.
What do I need to run the pair-trading skill?
You need Python with pandas and numpy, installed with pip install pandas numpy. A market data source such as Tushare or OKX is needed only if you run the example configuration.
How do I install the pair-trading skill?
Download the ZIP from this page and unzip it into ~/.claude/skills/ or a project's .claude/skills/ folder. You can also upload it in the Claude apps under Settings → Capabilities → Skills.
Does the pair-trading skill make money?
No. It is a trading-strategy recipe with simple fixed parameters and no risk controls, so it can lose money, especially when the correlation between the two instruments breaks down.
Why does my pair-trading run fail or show NaN values?
Check that codes contains exactly two instruments and that the two date series are aligned with an inner join. Z-scores are NaN until the lookback window fills, so signals should be filled with 0.
How does pair trading compare with other strategies?
Pair trading is a mean-reversion, long-short hedge built on the ratio of two correlated assets. The skill's source does not compare it with other strategies, so evaluate alternatives on your own backtests.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
Use this skill if you are a quant trader, student or developer who wants a clear, readable Z-score pair-trading example to draft or backtest. Pick something else if you want a turnkey profitable bot or a tool for live trading, since it has no stop-losses, slippage modelling or risk controls.
Download the skill