Yield Curve Modeling: Nelson-Siegel and Dynamic Models
Module: Fintech AI | Difficulty: Advanced
Nelson-Siegel
Factors
| Factor | Name | Interpretation | |--------|------|---------------| | | Level | Long-term rate | | | Slope | Term premium | | | Curvature | Medium-term |
Dynamic Nelson-Siegel
import numpy as np
from scipy.optimize import curve_fit
class NelsonSiegel:
def __init__(self):
self.params = None
def _ns_curve(self, tau, beta0, beta1, beta2, lam):
lt = lam * tau
factor1 = (1 - np.exp(-lt)) / lt
factor2 = factor1 - np.exp(-lt)
return beta0 + beta1 * factor1 + beta2 * factor2
def fit(self, maturities, yields):
popt, _ = curve_fit(self._ns_curve, maturities, yields,
p0=[0.05, -0.02, 0.01, 0.5])
self.params = popt
def predict(self, maturities):
return self._ns_curve(maturities, *self.params)
Research Insight: The Nelson-Siegel model captures the yield curve with just 3-4 parameters. The DNS extension adds dynamics, enabling forecasting. Machine learning improves yield curve modeling by capturing non-linearities and regime changes.