MyClaw
HomeProductsUse CasesPricingSkillsResourcesCompany
HomeUse CasesPricingSkills
Sign In
Home
ProductsOpenClaw HostingHermes Agent Hosting
Use CasesPricingSkills
ResourcesCompareTutorialLearnBlogUpdatesResourcesCommunity
CompanyAboutSupport
Sign In
MyClaw.ai

Your AI agent, already running.

Product

OpenClaw HostingHermes Agent HostingUse CasesPricingCompareAlibaba Cloud

Resources

BlogUpdatesSkillsModelsSupportCommunityCapybara

Legal

TermsPrivacyCookieGDPRContact

© 2023 Cubo World Inc. All rights reserved.

← Back to Skills
Design & Media
📸

Pair Trading

Pair trading strategy. Trades mean reversion using the spread/ratio Z-score of two correlated instruments. Requires at least two instruments.

by HKUDSv1.0.0
Connecting to VM...
Connecting to VM...
npx clawhub@latest install pair-trading
8.2kStars
8.3kDownloads
6Current Installs
1.2kAll-time Installs
📦
v1.0.0Version
📅
Apr 9, 2026Updated
View Source(ClawHub)

Pair Trading Skill Overview

Pair Trading is a market-neutral strategy skill that monitors the price ratio of two correlated instruments and trades mean reversion when their spread diverges significantly. It computes a rolling Z-score of the price ratio and enters opposing long/short positions when the Z-score exceeds a configurable threshold, then exits when the ratio reverts toward its historical mean. Install this skill to systematically exploit temporary mispricings between two related assets without taking a directional market bet.

How to Use It

Step 1: Run in your terminal or install this skill on MyClaw

npx clawhub@latest install pair-trading
or

Click the Install button at the top of this page for one-click setup

When to Use Pair Trading

Best Fit

  • You have identified two historically correlated instruments (e.g., stocks in the same industry, or BTC/ETH) and want to trade their relative divergences rather than outright direction.
  • You want a market-neutral, long-short hedge where one leg is always long and the other is always short, reducing overall market exposure.
  • You are backtesting equity pairs on Tushare-supported A-share markets or crypto pairs via OKX and need a ready-made Z-score signal pipeline.
  • You prefer a simple, interpretable entry/exit rule driven by configurable Z-score thresholds and a rolling lookback window.

When Not to Use

  • You need to trade more than two instruments simultaneously; this skill requires exactly two instruments and does not support baskets or portfolios.
  • You require a precise hedge-ratio calculation (e.g., via cointegration or OLS beta); this skill uses equal 50/50 capital allocation only.
  • Your two instruments have unreliable or misaligned date indexes, as ratio calculation depends on synchronized price series.

Key Features

Z-Score Signal Generation

Computes a rolling mean and standard deviation of the price ratio (leg A / leg B) over a configurable lookback window, then derives a Z-score to quantify how far the current ratio deviates from its historical norm. Entry and exit signals fire at user-defined Z-score thresholds (entry_z and exit_z).

Simultaneous Long/Short Leg Management

When a signal is triggered, leg A and leg B always receive opposite directions — one goes long while the other goes short. Each leg is allocated exactly 50% of capital, ensuring a balanced, market-neutral hedge at all times.

Configurable Lookback and Threshold Parameters

Three core parameters — lookback (default 60), entry_z (default 2.0), and exit_z (default 0.5) — can be tuned to match the mean-reversion speed and volatility characteristics of any instrument pair.

Multi-Source Data Support

Works with both Tushare (for A-share equities) and OKX (for cryptocurrency pairs such as BTC-USDT / ETH-USDT), making the strategy applicable across asset classes without code changes.

Safe Pre-Warmup Handling

Before the lookback window is fully populated, Z-scores are NaN and signals are automatically set to 0, preventing spurious trades during the initialization period.

Use Cases

A-Share Insurance Sector Pair

Trade two highly correlated A-share insurance stocks (e.g., 601318.SH and 601628.SH) by entering when their price ratio Z-score exceeds ±2.0 and exiting when it falls back within ±0.5. This captures temporary mispricings driven by sector-neutral noise rather than fundamental divergence.

Crypto BTC/ETH Spread Trading

Apply the same Z-score logic to BTC-USDT and ETH-USDT on OKX, exploiting the historically tight correlation between the two largest cryptocurrencies. When one rallies disproportionately relative to the other, the skill shorts the outperformer and longs the laggard.

Backtesting and Parameter Optimization

Use the configurable lookback, entry_z, and exit_z parameters to backtest different mean-reversion assumptions over historical data, comparing how tighter or wider Z-score thresholds affect trade frequency, drawdown, and returns.

Market-Neutral Equity Hedging

Embed this skill within a broader portfolio to add a market-neutral return stream, since the equal-weight long-short structure reduces net market exposure and provides returns that are relatively uncorrelated with broad market direction.

Requirements

  • Python packages: pandas, numpy (install via pip install pandas numpy)
  • Data source (choose one):
    • Tushare API access for A-share equity data
    • OKX API access for cryptocurrency OHLCV data
  • Instruments: Exactly 2 correlated instruments must be specified in the codes array; their price series must share aligned date indexes
Connecting to VM...
npx clawhub@latest install pair-trading
8.2kStars
8.3kDownloads
6Current Installs
1.2kAll-time Installs
📦
v1.0.0Version
📅
Apr 9, 2026Updated
View Source(ClawHub)

FAQ

Reviews

0 reviews

Log in to write a review

No reviews yet. Be the first to share your experience!