| name | yield-curve-fitting |
| description | 收益率曲线拟合工具,实现Nelson-Siegel参数模型(简化版)与三次样条插值,构建即期与远期收益率曲线。适用于固定收益教学、曲线拟合方法学习与利率期限结构原理演示;采用简化优化算法且未覆盖多曲线框架/负利率/信用利差剥离,不适用于实盘定价、债券估值或利率衍生品对冲管理。 |
| version | 1.0.0 |
| author | wangyi |
yield-curve-fitting
收益率曲线拟合工具,支持 Nelson-Siegel 参数模型与三次样条插值,构建即期收益率曲线与远期收益率曲线。
📌 说明:本工具基于简化模型实现,仅使用 Python 标准库。结果仅供学习参考,不构成投资建议或交易依据。
脚本API
nelson_siegel_yield(tau, beta0, beta1, beta2, lam)
计算 Nelson-Siegel 模型收益率。
必填: tau, beta0, beta1, beta2, lam
fit_nelson_siegel(maturities, yields, lam_init=2.5, max_iter=10000, tol=1e-10)
用网格搜索 + 梯度下降拟合 Nelson-Siegel 参数。
必填: maturities, yields
cubic_spline_interpolate(x, y, target_x)
自然三次样条插值。
必填: x, y, target_x
spot_to_forward(spot_maturities, spot_rates)
由即期收益率曲线推导远期收益率曲线(连续复利)。
必填: spot_maturities, spot_rates
fit_yield_curve(maturities, yields, method='nelson_siegel', target_maturities=None)
统一收益率曲线拟合接口。
必填: maturities, yields
调用示例
python scripts/main.py \
--maturities <maturities> \
--yields <yields> \
--method <method> \
--target-maturities <target_maturities> \
--beta0 <beta0> \
--beta1 <beta1> \
--beta2 <beta2> \
--lam <lam> \
--lam-init <lam_init> \
--max-iter <max_iter> \
--spot-maturities <spot_maturities> \
--spot-rates <spot_rates> \
--target-x <target_x> \
--tau <tau> \
--tol <tol> \
--x <x> \
--y <y>