σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
Time Series skill›Module 4 · Several series and hidden states›Topic 4.1·~1 hrAdvanced

Cointegration and pairs

Skill positionModule 4 of 5 · Topic 1 of 2
4.1 Cointegration and pairs
—Lab score— / 100Total XP—Streak—

Two walks that stay together

Two price series xtx_txt​ and yty_tyt​ that are each integrated of order one can still share a long-run link: if some combination zt=yt−α−βxtz_t=y_t-\alpha-\beta x_tzt​=yt​−α−βxt​ is stationary, the series are cointegrated. Each wanders, but they wander together, and the gap ztz_tzt​ keeps returning to its mean. This is the statistical basis of pairs trading: when the spread is unusually wide, you short the expensive leg and buy the cheap one, expecting it to close. Cointegration is about price levels over the long run. It differs from correlation, which measures whether daily returns move together and says nothing about whether the levels stay close.

zt=yt−α−βxt,Zt=zt−zˉsz,t1/2=ln⁡(1/2)ln⁡φ,Δyt=−λ zt−1+…z_t=y_t-\alpha-\beta x_t,\qquad Z_t=\frac{z_t-\bar z}{s_z},\qquad t_{1/2}=\frac{\ln(1/2)}{\ln\varphi},\qquad \Delta y_t=-\lambda\,z_{t-1}+\dotszt​=yt​−α−βxt​,Zt​=sz​zt​−zˉ​,t1/2​=lnφln(1/2)​,Δyt​=−λzt−1​+…(1)

The Engle-Granger test has two steps. First regress yty_tyt​ on xtx_txt​ by least squares to estimate α\alphaα and the hedge ratio β\betaβ. Then run an ADF test on the residuals ztz_tzt​. Because the residuals come from a fitted regression, the ordinary ADF critical values are too lenient and the Engle-Granger values apply: about −3.34-3.34−3.34 at 5% for two series with a constant. If the unit root is rejected, the pair is cointegrated and the spread is mean-reverting with half-life ln⁡(1/2)/ln⁡φ\ln(1/2)/\ln\varphiln(1/2)/lnφ, where φ\varphiφ is the spread's AR(1) coefficient. The error-correction view says that when yesterday's spread was positive, yyy falls or xxx rises today. To trade, standardise the spread into a z-score, enter when ∣Z∣|Z|∣Z∣ exceeds about 2, exit near 0, and size the legs by β\betaβ. The risks are real: the relationship can break, β\betaβ drifts, costs eat small spreads, and testing thousands of pairs will find many that pass by chance, so choose pairs for an economic reason and confirm out of sample.

A spread and its signalSuppose regressing yyy on xxx gave α=10\alpha=10α=10 and β=1.5\beta=1.5β=1.5. When x=40x=40x=40 and y=73y=73y=73 the spread is z=73−10−1.5⋅40=3z=73-10-1.5\cdot40=3z=73−10−1.5⋅40=3. If the spread has mean 000 and standard deviation 1.51.51.5, the z-score is Z=2Z=2Z=2: yyy is expensive relative to xxx. The trade shorts 100 units of yyy and buys 1.5⋅100=1501.5\cdot100=1501.5⋅100=150 units of xxx. If the spread's AR(1) coefficient is 0.950.950.95 per day, the half-life is ln⁡(0.5)/ln⁡(0.95)≈13.5\ln(0.5)/\ln(0.95)\approx13.5ln(0.5)/ln(0.95)≈13.5 days, so you should expect to wait weeks, not hours.
  • Cointegrated: each series wanders, but a linear combination of them is stationary.
  • Engle-Granger: regress, then test the residuals with ADF using the stricter Engle-Granger critical values.
  • Pairs trade: trade the z-score of the spread, size legs by β\betaβ, and expect the spread to close over about one half-life.

Lab · what's graded

  • The spread15 pts
  • The z-score10 pts
  • The half-life of the spread15 pts
  • Sizing the legs10 pts
  • Reading the test15 pts
  • Match the vocabulary15 pts
  • Building a pairs trade10 pts
  • Correlation is not cointegration10 pts
0/ 8 answered
Tasks
1Numeric answer15 ptsNot answered

A regression gave α=10\alpha=10α=10 and β=1.5\beta=1.5β=1.5. When x=40x=40x=40 and y=73y=73y=73, what is the spread z=y−α−βxz=y-\alpha-\beta xz=y−α−βx?

z=z =z=accepted: ± 0.01
2Numeric answer10 ptsNot answered

The spread is 333, its mean is 000 and its standard deviation is 1.51.51.5. What is the z-score?

Z=Z =Z=accepted: ± 0.01
3Numeric answer15 ptsNot answered

The spread follows an AR(1) with φ=0.95\varphi=0.95φ=0.95 per day. What is its half-life ln⁡(0.5)/ln⁡(0.95)\ln(0.5)/\ln(0.95)ln(0.5)/ln(0.95) in days? Give it to one decimal.

days=days =days=accepted: ± 0.1
4Numeric answer10 ptsNot answered

The trade shorts 100 units of yyy and the hedge ratio is β=1.5\beta=1.5β=1.5. How many units of xxx does it buy?

units=units =units=accepted: ± 0.5
5Choice15 ptsNot answered

In the Engle-Granger procedure, which result says that the pair is cointegrated?

6Match15 ptsNot answered

Match each term with its meaning.

Pick the partner of each item on the left.

Correlation
Cointegration
Spread
Error correction
7Order the steps10 ptsNot answered

Put the steps in order.

Drag to reorder, or focus an item, press Space to lift it, the arrow keys to move it and Space to drop it.

  1. 1Trade the z-score with thresholds and check costs out of sample
  2. 2Pick a pair with an economic link
  3. 3Test the residuals for a unit root and compute the half-life
  4. 4Regress one price on the other to get the hedge ratio
8Explain in words10 ptsNot answered

In one or two sentences, explain why two stocks whose daily returns are highly correlated need not be cointegrated.

Math modeKeyboard or LaTeX inputTask 1 of 8 · Ctrl ⏎ to check

Log in to run your code.

Every lecture is free to read. Create an account or log in to run code, run tests and submit this lab.

  • In-browser IDE with a bash terminal — nothing to install
  • Instant grading, XP and your place on the skill
Create an accountLog in
OR
Continue with GitHub