Finance & businessSharpeEdgePairs Trading in Python: Cointegration Tests & Dynamic Hedge Ratio Estimation
Pairs Trading in Python: Cointegration Tests & Dynamic Hedge Ratio Estimation
Long-form33:14People & BlogsPublished Nov 24, 2026, 8:00 AM · 1w ago
Views
7,915
+3 views/hour
Views / hour now
3
measured 6h ago
Peak views / hour
466
1w ago
First 24 hours
3.6K
views at 24 h
Engagement
2.5%
likes + comments / views
Likes
163
2.1% of views
Comments
33
0.42% of views
Est. ad revenue
$95–$228
lifetime, $12–28.8 RPM
Checked every 12 h while the video is this age · last check 6h ago · next in 353 min. YouTube itself updates public counts with a short delay.
Avg views / day
957
since upload
vs channel median
0.6×
this video's views ÷ the channel's usual
Rank in channel
#7
of 11 tracked
Views over time
77 readings
Total views Views gained per hour
Description
Consulting calls and strategy reviews: https://sharpe-edge.netlify.app
Educational content, not financial advice (full disclaimer below)
Two assets that move together are not enough for pairs trading. Correlated assets can drift apart forever: what you need is cointegration, a combination of prices that keeps reverting to its mean. In this video I go from theory to code: stationarity and the ADF test, Engle-Granger and Johansen, half-life of mean reversion, a dynamic hedge ratio with rolling OLS and an ALMA filter, and a full pair screening and backtest in Python, with multiple testing correction and out-of-sample validation to separate real relationships from statistical noise.
In this video:
- What pairs trading is: market-neutral mean reversion on the relationship between two assets
- Correlation vs cointegration, spurious correlation, and the drunk and her dog
- Stationarity and order of integration: I(0) vs I(1)
- The Augmented Dickey-Fuller test: null hypothesis, lags, and how to read it
- Hedge ratio and spread: why OLS is not symmetric, prices vs log prices
- Engle-Granger two-step method and its limitations
- The CADF test: why standard ADF critical values are wrong on residuals (MacKinnon critical values)
- The Johansen test: VECM, cointegration rank, trace and max eigenvalue statistics, eigenvectors as hedge ratios
- Speed of mean reversion: half-life (Ornstein-Uhlenbeck) and Hurst exponent
- Dynamic hedge ratio: rolling OLS smoothed with an ALMA filter, and how a too-reactive beta fakes stationarity
- How to find cointegrated pairs: economic universe, pre-filtering, cointegration tests, half-life filter
- The multiple testing problem: Bonferroni and Benjamini-Hochberg corrections
- Risks and traps: relationship breakdown, look-ahead bias, two-leg costs, asymmetric risk
Resources:
Jupyter notebook: https://github.com/pietrobelli26/sharpe_edge_code
References:
- Engle, Granger (1987), Co-Integration and Error Correction: Representation, Estimation, and Testing
- Johansen (1988), Statistical Analysis of Cointegration Vectors
- Dickey, Fuller (1979), Distribution of the Estimators for Autoregressive Time Series with a Unit Root
- MacKinnon (2010), Critical Values for Cointegration Tests
- Murray (1994), A Drunk and Her Dog: An Illustration of Cointegration and Error Correction
- Gatev, Goetzmann, Rouwenhorst (2006), Pairs Trading: Performance of a Relative-Value Arbitrage Rule
- Do, Faff (2010), Does Simple Pairs Trading Still Work?
- Vidyamurthy, Pairs Trading: Quantitative Methods and Analysis
- Chan, Algorithmic Trading: Winning Strategies and Their Rationale
Do you trade pairs or baskets? How do you estimate your hedge ratio, static, rolling or Kalman, and have you ever had a pair break down on you live? Let me know in the comments.
🔔 Subscribe for algorithmic trading, quant research, and Python strategy development.
📌 Previous video - Market Regimes Detection: https://youtu.be/dzGEf3QWmXU
Disclaimer: This video is for educational purposes only and is not financial advice. Trading involves risk, and past performance (backtested or otherwise) does not guarantee future results.
Timestamps:
00:00 Intro
01:03 What is pairs trading
02:04 Correlation vs cointegration
03:20 Stationarity and order of integration
04:26 The ADF test
05:29 Hedge ratio and spread
06:33 Engle-Granger
07:14 CADF test and critical values
08:00 Johansen test
09:10 Half-life and Hurst exponent
10:20 Dynamic hedge ratio with ALMA
11:38 Finding cointegrated pairs
12:43 Multiple testing problem
13:50 Risks and traps
14:57 Python code
32:18 Recap
#AlgorithmicTrading #Python #PairsTrading #Cointegration #StatisticalArbitrage #QuantitativeTrading #Backtesting
Details
- Published
- Nov 24, 2026, 8:00 AM
- Length
- 33:14 (1,994 s)
- Format
- Long-form
- Category
- People & Blogs
- Audio language
- EN
- Quality
- HD
- Captions
- No
- Made for kids
- No
- Licensed content
- No
- Video ID
- _yrv7kb_CRY
More from SharpeEdge
Market Regime Detection for Algo Trading | Python Analysis28.6K views · 3w ago · +5/h
How to Manage a Portfolio of Trading Strategies (Without Overfitting) | Python Analysis18.2K views · 5w ago · +1/h
Is the Kalman Filter Just a Fancy Moving Average? Python Analysis + Backtest24.6K views · 7w ago · +1/h
Does Machine Learning Actually Improve a Trading Strategy? A Walk-Forward Stress Test25K views · 2mo ago · +1/h
When to Stop a Trading Strategy | Alpha Decay Detection in Python7.4K views · 2mo ago
How to Evaluate Prop Firm Challenges Using Monte Carlo Simulation | Python Analysis3.4K views · 3mo ago
How to Use Logistic Regression for Trading | Python Data Analysis & Backtest14.9K views · 3mo ago
How to Code a Trading Bot in MetaTrader 5 (Full Tutorial) | Expert Advisor from Scratch1.4K views · 4mo ago
Statistics from the YouTube Data API, tracked by FameX. Views per hour, revenue and comparisons are FameX estimates.