# stat-arb-pairs-trading

> Design and audit pairs and stat-arb strategies: cointegration, OU half-life, Kalman hedge ratios, rules, breaks, costs.

stat-arb-pairs-trading is a paid AI agent skill on Agensi by BanditXBT. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $29 (one-time purchase)
- Creator: [BanditXBT](https://www.agensi.io/creators/banditxbt)
- Version: 1.0
- Last updated: 2026-11-21
- Security: scan passed (2026-11-21); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/stat-arb-pairs-trading
- Tags: trading-investing, web3-crypto, research-analysis

## About this skill

A pair is tradable only if the spread is mean-reverting *out of sample*, fast enough relative to costs, and robust to structural breaks. Treat formation-period fit as a hypothesis, not evidence.

- Start from economic linkage (same industry, ETF vs. constituents, same asset on two venues, spot vs. perp, wrapped vs. underlying). Mining N^2 pairs guarantees false positives; correct for multiple testing (FDR/Bonferroni; see strategy-statistical-validation).
- Literature: Gatev, Goetzmann, Rouwenhorst (2006), "Pairs Trading: Performance of a Relative-Value Arbitrage Rule", Review of Financial Studies 19(3) (distance method; abstract reports excess returns up to ~11% annualized, 1962-2002). Do and Faff (2010), "Does Simple Pairs Trading Still Work?", Financial Analysts Journal 66(4) (profits kept declining through 2009). Avellaneda and Lee (2010), "Statistical arbitrage in the US equities market", Quantitative Finance 10(7) (PCA/ETF residuals).
- Prefer residual-vs-factor (sector/PCA) spreads in equities to control factor exposure (see factor-exposure-attribution).

- **Engle-Granger:** regress y on x (log prices), test the residual. Use `statsmodels.tsa.stattools.coint(y0, y1, trend='c', maxlag=None, autolag='aic')`: null = *no* cointegration (small p = evidence for it); it uses MacKinnon p-values/critical values for residual-based tests, which plain `adfuller` on residuals does not. Results can differ by choice of regressand; run both orderings (y0/y1 swapped).
- **Johansen:** multivariate, gives rank and several vectors: `statsmodels.tsa.vector_ar.vecm.coint_johansen(endog, det_order, k_ar_diff)` (det_order -1 none, 0 constant, 1 linear trend; trace and max-eigenvalue stats) and `select_coint_rank`. Choose deterministic term and lag order deliberately; sensitive in short samples.
- Power is low on short windows: with a 30-day half-life, one trading year (~252 days) holds only ~8 half-lives. Require stability across rolling subsamples, not one p-value.

`dS = θ(μ - S)dt + σ dW`. Discretize as AR(1): `S_t = a + φ S_{t-1} + ε`, `θ = -ln(φ)/Δt`, **half-life = ln2/θ**, stationary sd `σ_eq = σ_ε/sqrt(1-φ²)`. Regressing ΔS on S_{t-1} gives `b = φ - 1`.

## Requires

- Python 3
- statsmodels
- pandas
- Optional: pykalman

## Known limitations

Educational analysis, not investment advice. Entry and exit thresholds are starting heuristics to be tuned out of sample.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the stat-arb-pairs-trading skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### What does stat-arb-pairs-trading do?

Design and audit pairs and stat-arb strategies: cointegration, OU half-life, Kalman hedge ratios, rules, breaks, costs.

### Which AI agents support stat-arb-pairs-trading?

This skill uses the open SKILL.md standard. Use it through an MCP-compatible agent connected to Agensi, and check the compatibility information on this page for confirmed agents and required capabilities.

### How do I use stat-arb-pairs-trading?

Connect your AI agent to Agensi through MCP, then ask it to use stat-arb-pairs-trading on your task. Your agent loads the latest approved version each time. Paid skills require a purchase or active subscription. Skill files are not available for download; your licence does not allow you to save, copy or export any part of a skill.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
