1.9k★pair-trade-screener – OpenClaw Skill
pair-trade-screener is an OpenClaw Skills integration for coding workflows. Statistical arbitrage tool for identifying and analyzing pair trading opportunities. Detects cointegrated stock pairs within sectors, analyzes spread behavior, calculates z-scores, and provides entry/exit recommendations for market-neutral strategies. Use when user requests pair trading opportunities, statistical arbitrage screening, mean-reversion strategies, or market-neutral portfolio construction. Supports correlation analysis, cointegration testing, and spread backtesting.
Skill Snapshot
| name | pair-trade-screener |
| description | Statistical arbitrage tool for identifying and analyzing pair trading opportunities. Detects cointegrated stock pairs within sectors, analyzes spread behavior, calculates z-scores, and provides entry/exit recommendations for market-neutral strategies. Use when user requests pair trading opportunities, statistical arbitrage screening, mean-reversion strategies, or market-neutral portfolio construction. Supports correlation analysis, cointegration testing, and spread backtesting. OpenClaw Skills integration. |
| owner | veeramanikandanr48 |
| repository | veeramanikandanr48/pair-trade-screener |
| language | Markdown |
| license | MIT |
| topics | |
| security | L1 |
| install | openclaw add @veeramanikandanr48/pair-trade-screener |
| last updated | Feb 7, 2026 |
Maintainer

veeramanikandanr48
Maintains pair-trade-screener in the OpenClaw Skills directory.
View GitHub profilename: pair-trade-screener description: Statistical arbitrage tool for identifying and analyzing pair trading opportunities. Detects cointegrated stock pairs within sectors, analyzes spread behavior, calculates z-scores, and provides entry/exit recommendations for market-neutral strategies. Use when user requests pair trading opportunities, statistical arbitrage screening, mean-reversion strategies, or market-neutral portfolio construction. Supports correlation analysis, cointegration testing, and spread backtesting.
Pair Trade Screener
Overview
This skill identifies and analyzes statistical arbitrage opportunities through pair trading. Pair trading is a market-neutral strategy that profits from the relative price movements of two correlated securities, regardless of overall market direction. The skill uses rigorous statistical methods including correlation analysis and cointegration testing to find robust trading pairs.
Core Methodology:
- Identify pairs of stocks with high correlation and similar sector/industry exposure
- Test for cointegration (long-term statistical relationship)
- Calculate spread z-scores to identify mean-reversion opportunities
- Generate entry/exit signals based on statistical thresholds
- Provide position sizing for market-neutral exposure
Key Advantages:
- Market-neutral: Profits in up, down, or sideways markets
- Risk management: Limited exposure to broad market movements
- Statistical foundation: Data-driven, not discretionary
- Diversification: Uncorrelated to traditional long-only strategies
When to Use This Skill
Use this skill when:
- User asks for "pair trading opportunities"
- User wants "market-neutral strategies"
- User requests "statistical arbitrage screening"
- User asks "which stocks move together?"
- User wants to hedge sector exposure
- User requests mean-reversion trade ideas
- User asks about relative value trading
Example user requests:
- "Find pair trading opportunities in the tech sector"
- "Which stocks are cointegrated?"
- "Screen for statistical arbitrage opportunities"
- "Find mean-reversion pairs"
- "What are good market-neutral trades right now?"
Analysis Workflow
Step 1: Define Pair Universe
Objective: Establish the pool of stocks to analyze for pair relationships.
Option A: Sector-Based Screening (Recommended)
Select a specific sector to screen:
- Technology
- Financials
- Healthcare
- Consumer Discretionary
- Industrials
- Energy
- Materials
- Consumer Staples
- Utilities
- Real Estate
- Communication Services
Option B: Custom Stock List
User provides specific tickers to analyze:
Example: ["AAPL", "MSFT", "GOOGL", "META", "NVDA"]
Option C: Industry-Specific
Narrow focus to specific industry within sector:
- Example: "Software" within Technology sector
- Example: "Regional Banks" within Financials
Filtering Criteria:
- Minimum market cap: $2B (mid-cap and above)
- Minimum average volume: 1M shares/day (liquidity requirement)
- Active trading: No delisted or inactive stocks
- Same exchange preference: Avoid cross-exchange complications
Step 2: Retrieve Historical Price Data
Objective: Fetch price history for correlation and cointegration analysis.
Data Requirements:
- Timeframe: 2 years (minimum 252 trading days)
- Frequency: Daily closing prices
- Adjustments: Adjusted for splits and dividends
- Clean data: No gaps or missing values
FMP API Endpoint:
GET /v3/historical-price-full/{symbol}?apikey=YOUR_API_KEY
Data Validation:
- Verify consistent date ranges across all symbols
- Remove stocks with >10% missing data
- Fill minor gaps with forward-fill method
- Log data quality issues
Script Execution:
python scripts/fetch_price_data.py --sector Technology --lookback 730
Step 3: Calculate Correlation and Beta
Objective: Identify candidate pairs with strong linear relationships.
Correlation Analysis:
For each pair of stocks (i, j) in the universe:
- Calculate Pearson correlation coefficient (ρ)
- Calculate rolling correlation (90-day window) for stability check
- Filter pairs with ρ >= 0.70 (strong positive correlation)
Correlation Interpretation:
- ρ >= 0.90: Very strong correlation (best candidates)
- ρ 0.70-0.90: Strong correlation (good candidates)
- ρ 0.50-0.70: Moderate correlation (marginal)
- ρ < 0.50: Weak correlation (exclude)
Beta Calculation:
For each candidate pair (Stock A, Stock B):
Beta = Covariance(A, B) / Variance(B)
Beta indicates the hedge ratio:
- Beta = 1.0: Equal dollar amounts
- Beta = 1.5: $1.50 of B for every $1.00 of A
- Beta = 0.8: $0.80 of B for every $1.00 of A
Correlation Stability Check:
- Calculate correlation over multiple periods (6mo, 1yr, 2yr)
- Require correlation to be stable (not deteriorating)
- Flag pairs where recent correlation < historical correlation by >0.15
Step 4: Cointegration Testing
Objective: Statistically validate long-term equilibrium relationship.
Why Cointegration Matters:
- Correlation measures short-term co-movement
- Cointegration proves long-term equilibrium relationship
- Cointegrated pairs mean-revert predictably
- Non-cointegrated pairs may diverge permanently
Augmented Dickey-Fuller (ADF) Test:
For each correlated pair:
- Calculate spread:
Spread = Price_A - (Beta × Price_B) - Run ADF test on spread series
- Check p-value: p < 0.05 indicates cointegration (reject null hypothesis of unit root)
- Extract ADF statistic for strength ranking
Cointegration Interpretation:
- p-value < 0.01: Very strong cointegration (★★★)
- p-value 0.01-0.05: Moderate cointegration (★★)
- p-value > 0.05: No cointegration (exclude)
Half-Life Calculation:
Estimate mean-reversion speed:
Half-Life = -log(2) / log(mean_reversion_coefficient)
- Half-life < 30 days: Fast mean-reversion (good for short-term trading)
- Half-life 30-60 days: Moderate speed (standard)
- Half-life > 60 days: Slow mean-reversion (long holding periods)
Python Implementation:
from statsmodels.tsa.stattools import adfuller
# Calculate spread
spread = price_a - (beta * price_b)
# ADF test
result = adfuller(spread)
adf_stat = result[0]
p_value = result[1]
# Interpret
is_cointegrated = p_value < 0.05
Step 5: Spread Analysis and Z-Score Calculation
Objective: Quantify current spread deviation from equilibrium.
Spread Calculation:
Two common methods:
Method 1: Price Difference (Additive)
Spread = Price_A - (Beta × Price_B)
Best for: Stocks with similar price levels
Method 2: Price Ratio (Multiplicative)
Spread = Price_A / Price_B
Best for: Stocks with different price levels, easier interpretation
Z-Score Calculation:
Measures how many standard deviations spread is from its mean:
Z-Score = (Current_Spread - Mean_Spread) / Std_Dev_Spread
Z-Score Interpretation:
- Z > +2.0: Stock A expensive relative to B (short A, long B)
- Z > +1.5: Moderately expensive (watch for entry)
- Z -1.5 to +1.5: Normal range (no trade)
- Z < -1.5: Moderately cheap (watch for entry)
- Z < -2.0: Stock A cheap relative to B (long A, short B)
Historical Spread Analysis:
- Calculate mean and std dev over 90-day rolling window
- Plot historical z-score distribution
- Identify maximum historical z-score deviations
- Check for structural breaks (spread regime change)
Step 6: Generate Entry/Exit Recommendations
Objective: Provide actionable trading signals with clear rules.
Entry Conditions:
Conservative Approach (Z ≥ ±2.0):
LONG Signal:
- Z-score < -2.0 (spread 2+ std devs below mean)
- Spread is mean-reverting (cointegration p < 0.05)
- Half-life < 60 days
→ Action: Buy Stock A, Short Stock B (hedge ratio = beta)
SHORT Signal:
- Z-score > +2.0 (spread 2+ std devs above mean)
- Spread is mean-reverting (cointegration p < 0.05)
- Half-life < 60 days
→ Action: Short Stock A, Buy Stock B (hedge ratio = beta)
Aggressive Approach (Z ≥ ±1.5):
- Lower threshold for more frequent trades
- Higher win rate but smaller avg profit per trade
- Requires tighter risk management
Exit Conditions:
Primary Exit: Mean Reversion (Z = 0)
Exit when spread returns to mean (z-score crosses 0)
→ Close both legs simultaneously
Secondary Exit: Partial Profit Take
Exit 50% when z-score reaches ±1.0
Exit remaining 50% at z-score = 0
Stop Loss:
Exit if z-score extends beyond ±3.0 (extreme divergence)
Risk: Possible structural break in relationship
Time-Based Exit:
Exit after 90 days if no mean-reversion
Prevents holding broken pairs indefinitely
Step 7: Position Sizing and Risk Management
Objective: Determine dollar amounts for market-neutral exposure.
Market Neutral Sizing:
For a pair (Stock A, Stock B) with beta = β:
Equal Dollar Exposure:
If portfolio size = $10,000 allocated to this pair:
- Long $5,000 of Stock A
- Short $5,000 × β of Stock B
Example (β = 1.2):
- Long $5,000 Stock A
- Short $6,000 Stock B
→ Market neutral, beta = 0
Position Sizing Considerations:
- Total pair allocation: 10-20% of portfolio per pair
- Maximum pairs: 5-8 active pairs for diversification
- Correlation across pairs: Avoid highly correlated pairs
Risk Metrics:
- Maximum loss per pair: 2-3% of total portfolio
- Stop loss trigger: Z-score > ±3.0 or -5% loss on spread
- Portfolio-level risk: Sum of all pair risks ≤ 10%
Step 8: Generate Pair Analysis Report
Objective: Create structured markdown report with findings and recommendations.
Report Sections:
-
Executive Summary
- Total pairs analyzed
- Number of cointegrated pairs found
- Top 5 opportunities ranked by statistical strength
-
Cointegrated Pairs Table
- Pair name (Stock A / Stock B)
- Correlation coefficient
- Cointegration p-value
- Current z-score
- Trade signal (Long/Short/None)
- Half-life
-
Detailed Analysis (Top 10 Pairs)
- Pair description
- Statistical metrics
- Current spread position
- Entry/exit recommendations
- Position sizing
- Risk assessment
-
Spread Charts (Text-Based)
- Historical z-score plot (ASCII art)
- Entry/exit levels marked
- Current position indicator
-
Risk Warnings
- Pairs with deteriorating correlation
- Structural breaks detected
- Low liquidity warnings
File Naming Convention:
pair_trade_analysis_[SECTOR]_[YYYY-MM-DD].md
Example: pair_trade_analysis_Technology_2025-11-08.md
Quality Standards
Statistical Rigor
Minimum Requirements for Valid Pair:
- ✓ Correlation ≥ 0.70 over 2-year period
- ✓ Cointegration p-value < 0.05 (ADF test)
- ✓ Spread stationarity confirmed
- ✓ Half-life < 90 days
- ✓ No structural breaks in recent 6 months
Red Flags (Exclude Pair):
- Correlation dropped >0.20 in recent 6 months
- Cointegration p-value > 0.05
- Half-life increasing over time (mean-reversion weakening)
- Significant corporate events (merger, spin-off, bankruptcy risk)
- Liquidity concerns (avg volume < 500K shares/day)
Practical Considerations
Transaction Costs:
- Assume 0.1% round-trip cost per leg
- Total cost per pair = 0.4% (entry + exit, both legs)
- Minimum z-score threshold should exceed transaction costs
Short Selling:
- Verify stock is shortable (not hard-to-borrow)
- Factor in short interest costs (borrow fees)
- Monitor short squeeze risk
Execution:
- Enter/exit both legs simultaneously (avoid leg risk)
- Use limit orders to control slippage
- Pre-locate shorts before entry
Available Scripts
scripts/find_pairs.py
Purpose: Screen for cointegrated pairs within a sector or custom list.
Usage:
# Sector-based screening
python scripts/find_pairs.py --sector Technology --min-correlation 0.70
# Custom stock list
python scripts/find_pairs.py --symbols AAPL,MSFT,GOOGL,META --min-correlation 0.75
# Full options
python scripts/find_pairs.py \
--sector Financials \
--min-correlation 0.70 \
--min-market-cap 2000000000 \
--lookback-days 730 \
--output pairs_analysis.json
Parameters:
--sector: Sector name (Technology, Financials, etc.)--symbols: Comma-separated list of tickers (alternative to sector)--min-correlation: Minimum correlation threshold (default: 0.70)--min-market-cap: Minimum market cap filter (default: $2B)--lookback-days: Historical data period (default: 730 days)--output: Output JSON file (default: stdout)--api-key: FMP API key (or set FMP_API_KEY env var)
Output:
[
{
"pair": "AAPL/MSFT",
"stock_a": "AAPL",
"stock_b": "MSFT",
"correlation": 0.87,
"beta": 1.15,
"cointegration_pvalue": 0.012,
"adf_statistic": -3.45,
"half_life_days": 42,
"current_zscore": -2.3,
"signal": "LONG",
"strength": "Strong"
}
]
scripts/analyze_spread.py
Purpose: Analyze a specific pair's spread behavior and generate trading signals.
Usage:
# Analyze specific pair
python scripts/analyze_spread.py --stock-a AAPL --stock-b MSFT
# Custom lookback period
python scripts/analyze_spread.py \
--stock-a JPM \
--stock-b BAC \
--lookback-days 365 \
--entry-zscore 2.0 \
--exit-zscore 0.5
Parameters:
--stock-a: First stock ticker--stock-b: Second stock ticker--lookback-days: Analysis period (default: 365)--entry-zscore: Z-score threshold for entry (default: 2.0)--exit-zscore: Z-score threshold for exit (default: 0.0)--api-key: FMP API key
Output:
- Current spread analysis
- Z-score calculation
- Entry/exit recommendations
- Position sizing
- Historical z-score chart (text)
Reference Documentation
references/methodology.md
Comprehensive guide to statistical arbitrage and pair trading:
- Pair Selection Criteria: How to identify good pair candidates
- Statistical Tests: Correlation, cointegration, stationarity
- Spread Construction: Price difference vs price ratio approaches
- Mean Reversion: Half-life calculation and interpretation
- Risk Management: Position sizing, stop losses, diversification
- Common Pitfalls: Survivorship bias, look-ahead bias, overfitting
references/cointegration_guide.md
Deep dive into cointegration testing:
- What is Cointegration?: Intuitive explanation
- ADF Test: Step-by-step procedure
- P-Value Interpretation: Statistical significance thresholds
- Half-Life Estimation: AR(1) model approach
- Structural Breaks: Testing for regime changes
- Practical Examples: Case studies with real pairs
Integration with Other Skills
Sector Analyst Integration:
- Use Sector Analyst to identify sectors in rotation
- Screen for pairs within outperforming sectors
- Pairs in leading sectors may have stronger trends
Technical Analyst Integration:
- Confirm pair entry/exit with individual stock technicals
- Check support/resistance levels before entry
- Validate trend direction aligns with spread signal
Backtest Expert Integration:
- Feed pair candidates to Backtest Expert for validation
- Test historical z-score entry/exit rules
- Optimize threshold parameters (entry z-score, stop loss)
- Walk-forward analysis for robustness
Market Environment Analysis Integration:
- Avoid pair trading during extreme volatility (VIX > 30)
- Correlations break down in crisis periods
- Prefer pair trading in sideways/range-bound markets
Portfolio Manager Integration:
- Track multiple pair positions
- Monitor overall market-neutral exposure
- Calculate portfolio-level pair trading P/L
- Rebalance hedge ratios periodically
Important Notes
- All analysis and output in English
- Statistical foundation: No discretionary interpretation
- Market neutral focus: Minimize directional beta exposure
- Data quality critical: Garbage in, garbage out
- Requires FMP API key: Free tier sufficient for basic screening
- Python dependencies: pandas, numpy, scipy, statsmodels
Common Use Cases
Use Case 1: Technology Sector Pairs
User: "Find pair trading opportunities in tech stocks"
Workflow:
1. Screen Technology sector for stocks with market cap > $10B
2. Calculate all pairwise correlations
3. Filter pairs with correlation ≥ 0.75
4. Run cointegration tests
5. Identify current z-score extremes (|z| > 2.0)
6. Generate top 10 pairs report
Use Case 2: Specific Pair Analysis
User: "Analyze AAPL and MSFT as a pair trade"
Workflow:
1. Fetch 2-year price history for AAPL and MSFT
2. Calculate correlation and beta
3. Test for cointegration
4. Calculate current spread and z-score
5. Generate entry/exit recommendation
6. Provide position sizing guidance
Use Case 3: Regional Bank Pairs
User: "Screen for pairs among regional banks"
Workflow:
1. Filter Financials sector for industry = "Regional Banks"
2. Exclude banks with <$5B market cap
3. Calculate pairwise statistics
4. Rank by cointegration strength
5. Focus on pairs with half-life < 45 days
6. Report top 5 mean-reverting pairs
Troubleshooting
Problem: No cointegrated pairs found
Solutions:
- Expand universe (lower market cap threshold)
- Relax cointegration p-value to 0.10
- Try different sectors (Utilities often cointegrate well)
- Increase lookback period to 3 years
Problem: All z-scores near zero (no trade signals)
Solutions:
- Normal market condition (pairs in equilibrium)
- Check back later or expand universe
- Lower entry threshold to ±1.5 instead of ±2.0
Problem: Pair correlation broke down
Solutions:
- Check for corporate events (earnings, guidance changes)
- Verify no M&A activity or restructuring
- Remove pair from watchlist if structural break confirmed
- Monitor for 30 days before re-entering
API Requirements
- Required: FMP API key (free tier sufficient)
- Rate Limits: ~250 requests/day on free tier
- Data Usage: ~2 requests per symbol for 2-year history
- Upgrade: Professional plan ($29/mo) recommended for frequent screening
Resources
- FMP Historical Price API: https://site.financialmodelingprep.com/developer/docs/historical-price-full
- Stock Screener API: https://site.financialmodelingprep.com/developer/docs/stock-screener-api
- Statsmodels Documentation: https://www.statsmodels.org/stable/index.html
- Cointegration Paper: Engle & Granger (1987) - "Co-Integration and Error Correction"
Version: 1.0 Last Updated: 2025-11-08 Dependencies: Python 3.8+, pandas, numpy, scipy, statsmodels, requests
Pair Trade Screener
Statistical arbitrage tool for identifying and analyzing pair trading opportunities using cointegration testing and mean-reversion analysis.
Overview
The Pair Trade Screener finds statistically significant pair trading opportunities by:
- Testing for cointegration (long-term equilibrium relationships)
- Calculating hedge ratios (beta values)
- Measuring mean-reversion speed (half-life)
- Generating entry/exit signals based on z-score thresholds
Market Neutral Strategy: Profit from relative price movements regardless of overall market direction.
Features
✅ Sector-wide screening - Analyze all stocks in a sector ✅ Custom pair analysis - Test specific stock combinations ✅ Statistical rigor - Cointegration tests (ADF), correlation analysis ✅ Mean-reversion metrics - Half-life calculation, z-score tracking ✅ Trade signals - Automatic entry/exit recommendations ✅ FMP API integration - Free tier sufficient for screening ✅ JSON output - Structured results for further analysis
Installation
Prerequisites
- Python 3.8+
- FMP API key (free tier: 250 requests/day)
Install Dependencies
pip install pandas numpy scipy statsmodels requests
Get FMP API Key
- Visit: https://financialmodelingprep.com/developer/docs
- Sign up for free account
- Copy your API key
- Set environment variable:
export FMP_API_KEY="your_key_here"
Or add to ~/.bashrc / ~/.zshrc for persistence.
Usage
Quick Start
# Screen Technology sector for pairs
python scripts/find_pairs.py --sector Technology
# Analyze specific pair
python scripts/analyze_spread.py --stock-a AAPL --stock-b MSFT
Screening for Pairs
Sector-Based Screening:
# Screen entire sector
python scripts/find_pairs.py --sector Financials
# Adjust correlation threshold
python scripts/find_pairs.py --sector Energy --min-correlation 0.75
# Longer lookback period
python scripts/find_pairs.py --sector Healthcare --lookback-days 1095
Custom Stock List:
# Test specific stocks
python scripts/find_pairs.py --symbols AAPL,MSFT,GOOGL,META,NVDA
# Tech giants pair screening
python scripts/find_pairs.py --symbols JPM,BAC,WFC,C,GS,MS
Full Options:
python scripts/find_pairs.py \
--sector Technology \
--min-correlation 0.70 \
--min-market-cap 10000000000 \
--lookback-days 730 \
--output tech_pairs.json \
--api-key YOUR_KEY
Analyzing Individual Pairs
Basic Analysis:
python scripts/analyze_spread.py --stock-a AAPL --stock-b MSFT
Custom Parameters:
python scripts/analyze_spread.py \
--stock-a JPM \
--stock-b BAC \
--lookback-days 365 \
--entry-zscore 2.0 \
--exit-zscore 0.5 \
--api-key YOUR_KEY
Example Output
Pair Screening Results
PAIR TRADING SCREEN SUMMARY
==========================================================================
Total pairs analyzed: 45
Cointegrated pairs: 12
Pairs with trade signals: 5
==========================================================================
ACTIVE TRADE SIGNALS
==========================================================================
Pair: XOM/CVX
Signal: LONG
Z-Score: -2.35
Correlation: 0.9421
P-Value: 0.0012
Half-Life: 28.3 days
Strength: ★★★
Individual Pair Analysis
PAIR TRADE ANALYSIS: AAPL / MSFT
==========================================================================
[ PAIR STATISTICS ]
Correlation: 0.8732
Hedge Ratio (Beta): 1.1523
Data Points: 365
[ COINTEGRATION TEST ]
ADF Statistic: -3.8542
P-value: 0.0028
Result: ✅ COINTEGRATED (p < 0.05)
Strength: ★★★ Very Strong
[ MEAN REVERSION ]
Half-Life: 42.1 days
Speed: Moderate (suitable for pair trading)
[ Z-SCORE ]
Current Z-Score: -2.13
Historical Range: [-3.45, 3.12]
[ TRADE SIGNAL ]
Signal: 🔺 LONG SPREAD
Action: Long AAPL, Short MSFT
Rationale: Z-score = -2.13 → AAPL cheap relative to MSFT
[ POSITION SIZING ]
Example Allocation: $10,000
LONG AAPL: $5,000 (27 shares @ $185.50)
SHORT MSFT: $5,762 (14 shares @ $411.25)
Exit Conditions:
- Primary: Z-score crosses 0 (mean reversion)
- Stop Loss: Z-score > ±3.0
- Time-based: No reversion after 90 days
Understanding the Metrics
Correlation
- Range: -1 to +1
- Threshold: ≥ 0.70 required
- Interpretation: Higher = stronger co-movement
Cointegration P-Value
- Range: 0 to 1
- Threshold: < 0.05 required (statistically significant)
- Interpretation: Lower = stronger cointegration
- p < 0.01: ★★★ Very strong
- p 0.01-0.05: ★★ Moderate
- p > 0.05: ☆ Not cointegrated (reject)
Half-Life
- Meaning: Time for spread to revert halfway to mean
- Fast: < 30 days (ideal for short-term trading)
- Moderate: 30-60 days (standard pair trading)
- Slow: > 60 days (long-term positions)
Z-Score
- Calculation: (Current Spread - Mean) / Std Dev
- Entry Signals:
- Z > +2.0: Short spread (Short A, Long B)
- Z < -2.0: Long spread (Long A, Short B)
- Exit: Z crosses 0 (mean reversion)
- Stop: |Z| > 3.0 (extreme divergence)
Hedge Ratio (Beta)
- Meaning: Dollar amount of Stock B per $1 of Stock A
- Example: Beta = 1.2 → Short $1,200 of B for every $1,000 long in A
- Purpose: Market-neutral positioning (net beta ≈ 0)
Common Workflows
1. Weekly Pair Screening
# Monday: Screen for new opportunities
python scripts/find_pairs.py --sector Technology --output tech_pairs.json
# Review top pairs in JSON output
cat tech_pairs.json | jq '.pairs[] | select(.signal != "NONE")'
# Detailed analysis on top candidates
python scripts/analyze_spread.py --stock-a AAPL --stock-b MSFT
2. Sector Rotation Pairs
# Screen multiple sectors
for sector in Technology Financials Healthcare Energy; do
python scripts/find_pairs.py --sector $sector --output ${sector}_pairs.json
sleep 5
done
# Find pairs with strongest signals
cat *_pairs.json | jq '.pairs[] | select(.current_zscore | . > 2 or . < -2)'
3. Monitor Existing Pairs
# Update z-scores for current positions
python scripts/analyze_spread.py --stock-a XOM --stock-b CVX
python scripts/analyze_spread.py --stock-a JPM --stock-b BAC
python scripts/analyze_spread.py --stock-a GOOGL --stock-b META
API Usage & Rate Limits
Free Tier:
- 250 API requests/day
- ~2 requests per stock for price data
- Can screen ~60 stocks/day (= 1,770 pairs)
Screening Costs:
Sector screening (30 stocks):
- Fetch 30 stock prices = 30 requests
- Analyze 435 pairs (30 choose 2) = 0 additional requests
- Total: 30 requests
Individual pair analysis:
- Fetch 2 stock prices = 2 requests
Tips:
- Run sector screens once/week (not daily)
- Cache results in JSON files
- Monitor specific pairs daily (2 requests each)
- Upgrade to paid plan if screening multiple sectors daily
Interpretation Guide
When to Trade
✅ Strong Pair (Enter):
- Correlation > 0.80
- P-value < 0.03
- Half-life 20-60 days
- |Z-score| > 2.0
- Economic linkage (same sector/industry)
⚠️ Marginal Pair (Caution):
- Correlation 0.70-0.80
- P-value 0.03-0.05
- Half-life > 60 days
- |Z-score| 1.5-2.0
❌ Weak Pair (Avoid):
- Correlation < 0.70
- P-value > 0.05
- Half-life > 90 days or undefined
- No economic linkage
Exit Conditions
Primary Exit:
- Z-score crosses 0 (spread reverts to mean)
- Close both legs simultaneously
Stop Loss:
- |Z-score| > 3.0 (extreme divergence, possible structural break)
- -5% loss on spread
- Exit immediately
Time-Based:
- No mean reversion after 90 days (or 3× half-life)
- Free capital for better opportunities
Troubleshooting
No pairs found
Solutions:
- Lower
--min-correlationto 0.65 - Expand stock universe (try different sector)
- Increase
--lookback-daysto 1095 (3 years)
API rate limit exceeded
Solutions:
- Wait 24 hours (free tier resets daily)
- Cache screening results (JSON files)
- Upgrade to paid plan ($14/mo Starter tier)
All z-scores near zero
Normal: Pairs in equilibrium, no trade signals Action: Check back later or expand universe
Pair correlation broke down
Causes: Corporate events, M&A, business model changes Detection: Recent correlation << historical correlation Action: Exit pair, remove from watchlist
Integration with Other Skills
Backtest Expert:
- Test pair trading strategies historically
- Optimize entry/exit thresholds
- Validate robustness
Sector Analyst:
- Identify sectors in rotation
- Screen for pairs within leading sectors
Technical Analyst:
- Confirm individual stock trends
- Check support/resistance before entry
Portfolio Manager:
- Track multiple pair positions
- Monitor overall market-neutral exposure
Resources
Documentation:
references/methodology.md- Statistical arbitrage theoryreferences/cointegration_guide.md- Cointegration testing guide
FMP API:
- API Docs: https://financialmodelingprep.com/developer/docs
- Historical Price API:
/v3/historical-price-full/{symbol} - Stock Screener API:
/v3/stock-screener
Academic Papers:
- Engle & Granger (1987): "Co-Integration and Error Correction"
- Gatev et al. (2006): "Pairs Trading: Performance of a Relative-Value Arbitrage Rule"
License
Educational and research use. Trade at your own risk. Past performance does not guarantee future results.
Version: 1.0 Last Updated: 2025-11-08 Dependencies: Python 3.8+, pandas, numpy, scipy, statsmodels, requests API: FMP API (free tier sufficient)
Permissions & Security
Security level L1: Low-risk skills with minimal permissions. Review inputs and outputs before running in production.
Requirements
- **Required**: FMP API key (free tier sufficient) - **Rate Limits**: ~250 requests/day on free tier - **Data Usage**: ~2 requests per symbol for 2-year history - **Upgrade**: Professional plan ($29/mo) recommended for frequent screening
FAQ
How do I install pair-trade-screener?
Run openclaw add @veeramanikandanr48/pair-trade-screener in your terminal. This installs pair-trade-screener into your OpenClaw Skills catalog.
Does this skill run locally or in the cloud?
OpenClaw Skills execute locally by default. Review the SKILL.md and permissions before running any skill.
Where can I verify the source code?
The source repository is available at https://github.com/openclaw/skills/tree/main/skills/veeramanikandanr48/pair-trade-screener. Review commits and README documentation before installing.
