σμ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ᵀμ = μ*∫Σ∂∞λ
σμ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 AcademySkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
Skills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
Python skill›Module 3 · Probability & Monte Carlo simulation›Topic 3.2·~40 minIntermediate

Skewness and kurtosis

Skill positionModule 3 of 11 · Topic 2 of 12
3.2 Skewness and kurtosis
—Lab score— / 100Total XP—Streak—

Beyond the mean and the variance

Two return series can have the same mean and the same volatility and still be very different to hold. One drifts up slowly and now and then drops 6% in a day; the other is symmetric and calm. Mean and variance are the first two moments of a distribution. The k-th central moment is the average of (x - mean) ** k. Moments 3 and 4 describe the shape: skewness says which tail is longer, kurtosis how heavy the tails are.

m_k = mean((x - mean)^k) skewness = m3 / m2^1.5 excess kurtosis = m4 / m2^2 - 3
import numpy as np

def central_moment(x, k):
    return float(np.mean((x - x.mean()) ** k))

# Calm days of about +1%, and one crash of -6%
returns = np.array([0.010, 0.012, 0.008, 0.011, 0.009, 0.010, 0.012, -0.060, 0.010, 0.009])

print(round(central_moment(returns, 2), 8))     # 0.00044389   the variance with ddof=0
print(round(central_moment(returns, 3), 10))    # -2.47823e-05   odd powers keep the sign: the crash dominates
print(round(central_moment(returns, 4), 12))    # 1.587946e-06   even powers are always positive

Skewness: which tail is longer

Cubing keeps the sign of each deviation and makes big ones count far more, so the third moment is dominated by the most extreme values. Dividing by m2 ** 1.5 removes the units, giving the skewness: 0 for a symmetric distribution, negative when the long tail is on the left (rare big losses), positive when it is on the right (rare big gains). Equity indices usually have negative skew: slow rises, sudden falls. The skewness of a sample of 100,000 normal values is about 0.

m2 = central_moment(returns, 2)
m3 = central_moment(returns, 3)
print(round(m3 / m2 ** 1.5, 3))     # -2.65   strongly negative: one big loss among calm gains

mirror = -returns                    # flip every return: the long tail moves to the right
print(round(central_moment(mirror, 3) / central_moment(mirror, 2) ** 1.5, 3))   # 2.65

Kurtosis: how heavy are the tails

The fourth power makes extreme values count enormously, so m4 / m2 ** 2 grows with the tails. For a normal distribution it equals 3, which is why we quote the excess kurtosis, m4 / m2 ** 2 - 3: it is 0 for a normal distribution, positive for fat tails (extreme days happen more often than the bell predicts) and negative for thin tails (the thinnest possible, two equal spikes, gives -2). Daily returns of most assets have a clearly positive excess kurtosis, often 5 or more. Both statistics are unchanged when you rescale or shift the returns, so they describe shape only.

m4 = central_moment(returns, 4)
print(round(m4 / m2 ** 2 - 3, 3))   # 5.059   fat tails: one crash dominates the fourth moment

calm = np.array([-0.02, -0.01, -0.005, 0.0, 0.005, 0.01, 0.02, -0.015, 0.015, 0.0])
c2, c3, c4 = (central_moment(calm, k) for k in (2, 3, 4))
print(round(c3 / c2 ** 1.5, 3), round(c4 / c2 ** 2 - 3, 3))   # 0.0 -1.033   symmetric, slightly thin tails
# Shape does not depend on scale or shift: multiply the returns by 3 and add 1
rescaled = returns * 3 + 1
print(round(central_moment(rescaled, 3) / central_moment(rescaled, 2) ** 1.5, 3))   # -2.65
print(round(central_moment(rescaled, 4) / central_moment(rescaled, 2) ** 2 - 3, 3))  # 5.059   the same two numbers
One crash can change everythingSkewness and kurtosis are driven by the few most extreme values, so they are much less stable than the mean or the volatility: add or remove one day and they jump. Compute them on enough data (hundreds of days at least), and look at the histogram too before trusting a number.
  • The k-th central moment is mean((x - mean) ** k): moments 2, 3 and 4 give variance, skewness and kurtosis.
  • Skewness m3 / m2 ** 1.5: negative means a long left tail (rare big losses); excess kurtosis m4 / m2 ** 2 - 3 is 0 for a normal.
  • Positive excess kurtosis means fat tails; both statistics are driven by a few extreme days, so they need lots of data.

Next up: fat tails and normality tests, checking formally whether returns follow the bell curve.

Lab · what's graded

  • Compute the building block with central_moment25 pts
  • Measure which tail is longer with skewness25 pts
  • Measure how heavy the tails are with excess_kurtosis25 pts
  • Put a name on the shape with shape_label25 pts
Explorer · lab-55-1
▾ lab-55-1
…
bash · in-browser
learner@quantcraft:~/lab-55-1$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-55-1 goes back to the starter files and the terminal is cleared. Your current solution will be lost — this can't be undone.

Will be reset
  • main.py → starter code
  • Terminal history and test output
  • Unsubmitted changes
Will be kept
  • Best lab score
  • Your XP and streak
  • Lecture progress and notes

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