agiprolabs/claude-trading-skills/mean-reversion
Claude Code and agent skill by agiprolabs/claude-trading-skills
- community
Checking that the SKILL.md file is still in the repository.
Mean-reversion strategy tools including Hurst exponent, half-life estimation, z-score signals, ADF testing, and Ornstein-Uhlenbeck modeling
Install
npx vskill@latest install agiprolabs/claude-trading-skills/mean-reversionSKILL.md
Mean Reversion
Mean reversion is the statistical tendency for prices, spreads, or other financial variables to return toward a long-run average after deviating from it. A mean-reverting series overshoots its mean, then corrects back -- creating predictable oscillations that can be traded.
When Mean Reversion Works
- Ranging markets: Sideways price action with clear support/resistance
- Pairs spreads: Spread between cointegrated assets reverts to equilibrium
- Oversold/overbought extremes: RSI, Bollinger Band, or z-score extremes in stationary series
- Funding rate arbitrage: Perpetual funding rates revert to baseline
- Stablecoin depegs: Classic mean-reversion opportunity (peg = known mean)
- Post-dump recovery: Brief mean-reversion windows after initial PumpFun dumps
When Mean Reversion Fails
- Strong trending markets (most crypto most of the time)
- Regime changes: what was stationary becomes non-stationary
- Structural breaks: token migration, protocol upgrade, delistings
- Low liquidity: wide spreads consume mean-reversion profits
Testing for Mean Reversion
Before trading mean reversion, you must statistically confirm the series is mean-reverting. Three complementary tests:
1. Augmented Dickey-Fuller (ADF) Test
Tests the null hypothesis that a series has a unit root (non-stationary).
- p < 0.01: Strong evidence of stationarity
- p < 0.05: Evidence of stationarity
- p > 0.10: Cannot reject unit root -- likely non-stationary
2. Hurst Exponent
Measures the long-range dependence of a time series.
| Hurst Value | Interpretation | Trading Implication | |
|---|---|---|---|
| H < 0.5 | Mean-reverting | Trade mean reversion | |
| H = 0.5 | Random walk | No edge | |
| H > 0.5 | Trending | Trade momentum |
3. Variance Ratio Test
Compares variance of multi-period returns to single-period variance.
- VR < 1: Negative autocorrelation (mean-reverting)
- VR = 1: Random walk
- VR > 1: Positive autocorrelation (trending)
See references/statistical_tests.md for complete implementations and interpretation guides.
Half-Life Estimation
The half-life tells you how many periods it takes for a deviation to decay to half its size. This is the single most important parameter for mean-reversion trading.
AR(1) Regression Method
Fit the autoregressive model: delta_X_t = alpha + beta * X_{t-1} + epsilon
Using Half-Life
| Parameter | Rule of Thumb | |
|---|---|---|
| Lookback window | 2x half-life | |
| Holding period | 1x half-life | |
| Maximum hold | 3x half-life (stop) | |
| Signal recalc | 0.5x half-life |
Z-Score Signal Framework
The z-score normalizes the deviation from the mean, providing standardized entry/exit signals.
Signal Rules
| Condition | Signal | Action | |
|---|---|---|---|
| z < -2.0 | Buy | Enter long (price below mean) | |
| z > +2.0 | Sell | Enter short (price above mean) | |
| z crosses 0 | Exit | Close position (returned to mean) | |
| abs(z) > 3.0 | Stop | Close position (reversion failed) |
Lookback Window
Set the rolling window to approximately 2x the half-life:
Position Sizing with Z-Score
Scale position size with z-score magnitude for better risk-adjusted returns:
See references/strategy_design.md for complete entry/exit framework and sizing.
Ornstein-Uhlenbeck (OU) Process
The OU process is the continuous-time model of mean reversion:
| Parameter | Meaning | Estimation | |
|---|---|---|---|
| theta | Speed of mean reversion | From AR(1) beta: theta = -ln(1+beta)/dt | |
| mu | Long-run mean | From AR(1) intercept: mu = -alpha/beta | |
| sigma | Volatility of innovations | Residual std from AR(1) |
Parameter Estimation
Strategy Types
Single-Asset Mean Reversion
Apply z-score framework directly to a token's price series. Works best on:
- Stablecoins (USDC/USDT spread)
- Tokens in established ranges
- After confirming stationarity with ADF test
Pairs Trading
Trade the spread between two cointegrated assets:
- Confirm cointegration (see
cointegration-analysisskill) - Compute spread:
S = Y - beta * X - Apply z-score framework to the spread
- Go long spread (buy Y, sell X) when z < -2
- Go short spread (sell Y, buy X) when z > +2
Statistical Arbitrage
Multi-asset extension of pairs trading:
- Eigenportfolios from PCA of correlated assets
- Trade the smallest eigenvalue portfolios (most mean-reverting)
- Requires larger universe (10+ assets)
Crypto-Specific Considerations
- Most crypto trends: Hurst exponent for BTC, ETH, SOL is typically 0.55-0.70. Raw price mean reversion is rare.
- Where to find mean reversion:
- Pairs spreads (SOL/ETH ratio, BTC dominance)
- Funding rates on perpetuals
- Basis between spot and futures
- Stablecoin depegs
- Fee tier spreads across DEXs
- Short lookbacks: Crypto mean reversion has short half-lives (hours to days, not weeks)
- Transaction costs: DEX swap fees (0.25-1%) can eat mean-reversion profits. Factor in slippage.
- Regime awareness: Use
regime-detectionskill to only trade mean reversion in ranging regimes.
Integration with Other Skills
| Skill | Integration | |
|---|---|---|
cointegration-analysis | Find cointegrated pairs for pairs trading | |
pandas-ta | RSI, Bollinger Bands as mean-reversion indicators | |
regime-detection | Filter: only trade MR in ranging regimes | |
vectorbt | Backtest mean-reversion strategies | |
volatility-modeling | Estimate sigma for OU model | |
slippage-modeling | Factor execution costs into P&L estimates | |
position-sizing | Size positions using Kelly + z-score scaling |
Files
References
references/statistical_tests.md-- ADF, Hurst exponent, variance ratio, and half-life estimation with full implementations and interpretationreferences/strategy_design.md-- Z-score framework, position sizing, pairs trading setup, risk management, and backtest considerations
Scripts
scripts/mean_reversion_test.py-- Comprehensive mean-reversion analysis: ADF, Hurst, variance ratio, half-life, OU estimation, z-score signalsscripts/pairs_scanner.py-- Scan multiple assets for mean-reverting pairs: correlation, cointegration, spread analysis, ranking
Quick Start
This skill provides analytical tools and information only. It does not constitute financial advice or trading recommendations.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/mean-reversion/SKILL.md
Popularity
- Repository stars
- 393
- Repository forks
- 76
- 7-day trend score
- 30
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 19 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/agiprolabs/claude-trading-skills/mean-reversion)