R语言和QuantLib中Nelson-Siegel模型收益曲线建模分析
原文链接:http://tecdat.cn/?p=11803
Nelson-Siegel- [Svensson]模型是拟合收益曲线的常用方法。可以用其参数的经济可解释性来解释其受欢迎程度,但这很可能是因为欧洲中央银行使用了它。对ECB可能采取的措施不一定在所有情况下都有效:模型参数有时非常不稳定,无法收敛。
纳尔逊(Nelson)和西格尔(Siegel)在其原始论文中从远期利率入手,然后推导了收益率至到期曲线的公式.
Nelson-Siegel模型是简约的,可以生成丰富的收益曲线。
但是,由于简单地使用它,它通常失去了经济上的可解释性,甚至更糟的是无法收敛。
上图显示了这种情况,随后的R代码再现了这种情况。
plot(MATURITY_BASES, oldYields, main="Nelson-Siegel Calibration Failure in YieldCurve R Package")lines(MATURITY_BASES, oldYields)points(newMats, newYields, col="blue")lines(newMats, newYields, col="blue")points(newMats, newNsYields, col="red")lines(newMats, newNsYields, col="red")legend("topleft",legend=c("old observed yields","new observed yields","NS-Fit new yields"), col=c("black","blue", "red"),lty=1)
请注意,newMat [urities]比MATURITY_BASES短一天,因为此代码模仿了一个频繁使用的案例,因为当前的收益曲线与昨天的曲线进行了比较。从某种意义上讲,这是一个简单示例,因为对于给定的到期日,我们已经具有零收益率,并且“仅”需要连接点。实际上,我们通常与票息债券有关,这会使事情变得更加复杂。
您可能会认为,由于YieldCurve软件包的实施不佳而导致收敛失败。我要讲的不是不好的实现,而是要高度依赖所使用的数值方法,如下面的更实际的示例所示。
QuantLib提供更逼真的建模
/*
* 提示:该行代码过长,系统自动注释不进行高亮。一键复制会移除系统注释
* #include <ql/qldefines.hpp>#ifdef BOOST_MSVC# include <ql/auto_link.hpp>#endif#include <ql/termstructures/yield/fittedbonddiscountcurve.hpp>#include <ql/termstructures/yield/piecewiseyieldcurve.hpp>#include <ql/termstructures/yield/flatforward.hpp>#include <ql/termstructures/yield/bondhelpers.hpp>#include <ql/termstructures/yield/nonlinearfittingmethods.hpp>#include <ql/pricingengines/bond/bondfunctions.hpp>#include <ql/time/calendars/target.hpp>#include <ql/time/daycounters/simpledaycounter.hpp>#include <boost/timer.hpp>#include <iostream>#include <iomanip>#include <boost/make_shared.hpp>#include "ql/time/daycounters/thirty360.hpp"#include "ql/time/daycounters/actualactual.hpp"#include "ql/math/optimization/conjugategradient.hpp"#include "ql/math/optimization/simplex.hpp"using namespace QuantLib;int main(int, char*[]) { try { Calendar calendar = NullCalendar(); Date today = Date(18, December, 2017); Settings::instance().evaluationDate() = today; //market data double cleanPrices1[] = { 107.96, 135.88, 110.6, 133.46, 135.8, 142.155, 121.045, 134.97, 117.04, 101.61, 128.67, 106.615, 106.36, 99.515, 101.21, 105.655, 114.828 }; double cleanPrices2[] = { 107.9, 134.965, 110.37, 132.89, 135.62,140.845, 120.585, 133.995, 116.745, 101.58, 128.115,105.985, 105.395,99.385, 100.79,104.955, 114.7985 }; double cleanPrices3[] = { 107.96, 134.625, 110.58, 132.65, 135.145, 140.585, 120.385, 133.735, 116.635, 101.62, 127.925, 105.6, 105.085, 99.29, 100.6, 104.945, 114.7415 }; double cleanPrices4[] = { 107.78, 134.39, 110.175, 132.445, 134.905, 139.515, 120.115, 133.475, 116.455, 101.58, 127.845, 105.53,104.805, 99.07, 100.46, 104.885, 114.6225 }; double coupons[] = { 0.053, 0.045, 0.04, 0.0435, 0.044, 0.043, 0.03375, 0.03875, 0.03, 0.015, 0.03625, 0.01375, 0.01625, 0, 0.00625, 0.01875, 0.04 }; Real redemption = 100.0; const double FACE_VALUE = 100.0; //Bond helpers const Size numberOfBonds = (sizeof(coupons) / sizeof(coupons[0])); std::vector<boost::shared_ptr<BondHelper> > bondHelpersA; std::vector< boost::shared_ptr<SimpleQuote> > quoteA; std::vector<boost::shared_ptr<BondHelper> > bondHelpersB; std::vector< boost::shared_ptr<SimpleQuote> > quoteB; std::vector<boost::shared_ptr<BondHelper> > bondHelpersC; std::vector< boost::shared_ptr<SimpleQuote> > quoteC; std::vector<boost::shared_ptr<BondHelper> > bondHelpersD; std::vector< boost::shared_ptr<SimpleQuote> > quoteD; for (Size i = 0; i < numberOfBonds; i++) { boost::shared_ptr<SimpleQuote> cp1(new SimpleQuote(cleanPrices1<em class="d4pbbc-italic"></em>)); quoteA.push_back(cp1); boost::shared_ptr<SimpleQuote> cp2(new SimpleQuote(cleanPrices2<em class="d4pbbc-italic"></em>)); quoteB.push_back(cp2); boost::shared_ptr<SimpleQuote> cp3(new SimpleQuote(cleanPrices3<em class="d4pbbc-italic"></em>)); quoteC.push_back(cp3); boost::shared_ptr<SimpleQuote> cp4(new SimpleQuote(cleanPrices4<em class="d4pbbc-italic"></em>)); quoteD.push_back(cp4); } RelinkableHandle<Quote> quoteHandleA[numberOfBonds]; RelinkableHandle<Quote> quoteHandleB[numberOfBonds]; RelinkableHandle<Quote> quoteHandleC[numberOfBonds]; RelinkableHandle<Quote> quoteHandleD[numberOfBonds]; for (Size j = 0; j < numberOfBonds; j++) { quoteHandleA[j].linkTo(quoteA[j]); quoteHandleB[j].linkTo(quoteB[j]); quoteHandleC[j].linkTo(quoteC[j]); quoteHandleD[j].linkTo(quoteD[j]); } std::vector<boost::shared_ptr<BondHelper> > instrumentsA; std::vector<boost::shared_ptr<BondHelper> > instrumentsB; std::vector<boost::shared_ptr<BondHelper> > instrumentsC; std::vector<boost::shared_ptr<BondHelper> > instrumentsD; for (Size j = 0; j < numberOfBonds; j++) { Date bondSettlementDate = calendar.advance(issueDates[j], settlementDays[j] * Days); Schedule schedule(bondSettlementDate, maturityDates[j], Period(frequency), calendar, accrualConvention, accrualConvention, DateGeneration::Backward, false); boost::shared_ptr<FixedRateBond> bond(new FixedRateBond(settlementDays[j], FACE_VALUE, schedule, std::vector<Rate>(1, coupons[j]), dc[j], convention, redemption, issueDates[j])); instrumentsA.push_back(helperA); instrumentsB.push_back(helperB); instrumentsC.push_back(helperC); instrumentsD.push_back(helperD); } //Nelson-Siegel Fittings Real tolerance = 1.0e-14; Size max = 10000; boost::shared_ptr<FittedBondDiscountCurve> tsA( new FittedBondDiscountCurve(curveSettlementDays, calendar, instrumentsA, ActualActual(), NelsonSiegelFitting(), tolerance, max)); boost::shared_ptr<FittedBondDiscountCurve> tsB( new FittedBondDiscountCurve(curveSettlementDays, calendar, instrumentsB, ActualActual(), NelsonSiegelFitting(), tolerance, max)); boost::shared_ptr<FittedBondDiscountCurve> tsC( new FittedBondDiscountCurve(curveSettlementDays, calendar, instrumentsC, ActualActual(), NelsonSiegelFitting(), tolerance, max)); boost::shared_ptr<FittedBondDiscountCurve> tsD( new FittedBondDiscountCurve(curveSettlementDays, calendar, instrumentsD, ActualActual(), NelsonSiegelFitting(), tolerance, max)); std::cout << tsA->fitResults().numberOfIterations() << std::endl; std::cout << tsB->fitResults().numberOfIterations() << std::endl; std::cout << tsC->fitResults().numberOfIterations() << std::endl; std::cout << tsD->fitResults().numberOfIterations() << std::endl; std::cout << tsA->fitResults().solution() << std::endl; std::cout << tsB->fitResults().solution() << std::endl; std::cout << tsC->fitResults().solution() << std::endl; std::cout << tsD->fitResults().solution() << std::endl; return 0; } catch (std::exception& e) { std::cerr << e.what() << std::endl; return 1; } catch (...) { std::cerr << "unknown error" << std::endl; return 1; }}
*/
正式而言,收益曲线每天的变化并不显着,但是模型参数却可以:
Nelson-Siegel意识到了这些问题,并提供了解决这些问题的方法。特别是,他们考虑了Taus的时间序列,并确定了Taus的最佳拟合值的中值和合理范围。 但是,与往常一样,原始论文被引用的次数可能多于阅读次数。此外,如果需要按时间顺序排列的收益率数据,可能会感到困惑,而不是仅仅考虑相关日期的数据。即使处理时间序列不是问题,Nelson和Siegel也没有指定正式的算法来选择的最佳值。这就是我们将在后续工作中尝试做的,敬请期待!
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Vue实现pc/H5弹窗拖拽
- 微信小程序skeleton骨架屏
- 微信小程序锚点选择导航栏
- vue-ripple-directive点击水波纹
- dubbo学习之源码创建属于自己的dubbo-demo
- Vue4.x配置env开发环境、测试环境、生产环境
- SpringBoot总结之CommandLineRunner
- 详细整理Spring事务失效的具体场景及解决方案
- Vue监听文本框实时输入限制输入长度
- 30 分钟轻松搞定正则表达式基础
- Vant引入CDN实现图片懒加载
- Js时间戳倒计时天时分秒
- 微信小程序引用we-cropper裁切图片
- NodeJs获取get/post传值
- Mybatis源码本地化构建Demo