Four numbers for a whole curve
The market quotes US Treasury yields at ten maturities, from 3 months to 30 years, but a bank needs a rate for every date. In this capstone you describe the whole curve with the four numbers of the Nelson–Siegel model: a long-run level β₀, a slope β₁, a hump β₂ and a decay length λ in years. You calibrate them to the quotes with scipy.optimize.least_squares, starting from several values of λ because the curve is not linear in it, and keep the fit with the lowest cost. From the fitted curve you read a forward rate, and you integrate the instantaneous forward curve with integrate.quad to get a discount factor D(T)=e^(-A/100), where A is the area under the forward curve in percent.
The same curve prices a bond. Each cash flow is discounted with the yield of its own maturity, P=Σcᵢ e^(-y(tᵢ)tᵢ/100), and the yield to maturity is the single rate that gives back the price, found with optimize.brentq. Options work the same way: the implied volatility is the root of bs_call(σ)-price, again found with brentq. Real option quotes are not part of the shared data, so you test the smile on prices you generate yourself with the provided bs_call, and fit the smile σ(m)=a+b m+c m² in log-moneyness m=ln(K/S) by least squares. Every function is graded on random inputs against an independent reference, and the last test runs your whole study on the real Treasury file.
- Calibrate from several starts: the decay length makes the fit non-linear, so one start can stop at a poor curve.
- Check with a second route: the discount factor from the integrated forward curve must equal the one from the yield.
- Roots price the market: a yield to maturity and an implied volatility are both roots found with brentq on a pricing error.
Lab · what's graded
- The quoted curve of a day5 pts
- The Nelson–Siegel yield10 pts
- Calibrating the curve15 pts
- A forward rate10 pts
- A discount factor from forwards10 pts
- A bond price from the curve10 pts
- A yield to maturity10 pts
- An implied volatility10 pts
- A quadratic smile10 pts
- The whole calibration10 pts