σμ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
  • 日本語
  • 中文
SciPy skill›Module 2 · Curves and integrals›Topic 2.2·~45 minIntermediate

Interpolating a yield curve and its forwards

Skill positionModule 2 of 3 · Topic 2 of 5
2.2 Interpolating a yield curve and its forwards
—Lab score— / 100Total XP—Streak—

Filling the gaps between quotes

The Treasury quotes ten maturities and everything else is interpolated. scipy.interpolate offers the standard tools. np.interp joins the quotes with straight lines: it is simple and never overshoots, but its slope jumps at every quote. CubicSpline(x, y, bc_type='natural') joins them with a smooth curve whose first and second derivatives are continuous; the price of smoothness is that it can overshoot between quotes and, outside the quoted range, it runs away, so it should not be extrapolated. PchipInterpolator(x, y) is smooth too but preserves the shape: where the data rise, it rises, so it cannot invent a hump. All three pass through every quote; they differ in between, and in what they do to everything derived from the curve.

The differences matter because derived quantities amplify them. A discount factor is D(t)=e^(-y(t) t/100), and the forward rate between two dates is the slope of its logarithm, f=-Δln D/Δt×100. A small kink in the yield becomes a visible jump in the forward. On 9 October 2026 the 15-year yield is 5.445% by linear interpolation, 5.464% by a natural cubic spline and 5.493% by PCHIP, and the largest jump between neighbouring forwards on a 120-point grid is 0.91 points for the linear curve and about 0.21 for the splines. On the inverted curve of 3 January 2000 the splines' forwards dip to 4.76% and 4.63% while the linear ones stay at 5.63%. There is no best method, only a choice to make on purpose: smooth forwards for pricing, shape preservation for risk, plain lines when you must not invent anything.

  • All three pass through the quotes: they differ between them and in the forwards they imply.
  • Forwards are the slope of log discount factors: any kink in the yield shows up as a jump.
  • Do not extrapolate a cubic spline: use it between the quotes and nowhere else.

Lab · what's graded

  • Three interpolations20 pts
  • Discount factors10 pts
  • The forward curve20 pts
  • Roughness10 pts
  • Comparing the methods15 pts
  • One real day25 pts
Explorer · lab-sp-17
▾ lab-sp-17
▾ data
…
bash · in-browser
learner@quantcraft:~/lab-sp-17$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-sp-17 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