打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
R语言和QuantLib中Nelson-Siegel模型收益曲线建模分析

原文链接:http://tecdat.cn/?p=11803


Nelson-Siegel- [Svensson]模型是拟合收益曲线的常用方法。它的优点是其参数的经济可解释性,被银行广泛使用。但它不一定在所有情况下都有效:模型参数有时非常不稳定,无法收敛。

纳尔逊(Nelson)和西格尔(Siegel)在其原始论文中从远期利率入手,然后推导了收益率至到期曲线的公式.

Nelson-Siegel模型是简约的,可以生成丰富的收益曲线。

但是,由于简单地使用它,它通常失去了经济上的可解释性,甚至无法收敛。


上图显示了这种情况。

plot(MATURITY_BASES, oldYields
lines(MATURITY_BASES, oldYields)
points(newMats, newYields, col="blue")
lines(newMats, newYields, col="blue")

此代码模仿了一个频繁使用的案例,当前的收益曲线与昨天的曲线进行了比较。从某种意义上讲,这是一个简单示例,因为对于给定的到期日,我们已经具有零收益率。实际上,我们通常与票息债券有关,这会使事情变得更加复杂。

您可能会认为,由于软件的实施而导致收敛失败。我要讲的不是不好的实现,而是要高度依赖所使用的数值方法,如下面的更实际的示例所示。

提供更逼真的建模

#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>

 
using namespace QuantLib;
 
int main(int, char*[]) {
    try {
        Calendar calendar = NullCalendar();
        Date today = Date(18, December, 2017);
        Settings::instance().evaluationDate() = today;
 
        //市场数据
        double cleanPrices1[] = { 107.96, 135.88, 110.6,   133.46, 135.8142.155, 121.045, 134.97, 117.04,
            101.61, 128.67, 106.615, 106.36, 99.515, 101.21105.655, 114.828 };
        double cleanPrices2[] = { 107.9134.965, 110.37132.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 };

 
        std::vector<boost::shared_ptr<BondHelper> > bondHelpersA;
        std::vector< boost::shared_ptr<SimpleQuote> > quoteA;
        std::vector<boost::shared_ptr<BondHelper> > bondHelpersB;

        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];

         
 
        //Nelson-Siegel模型拟合
        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;

正式而言,收益曲线每天的变化并不显着,但是模型参数却可以:

Nelson-Siegel意识到了这些问题,并提供了解决这些问题的方法。特别是,他们考虑了Taus的时间序列,并确定了Taus的最佳拟合值的中值和合理范围。
但是,与往常一样,原始论文被引用的次数可能多于阅读次数。此外,如果需要按时间顺序排列的收益率数据,可能会感到困惑,而不是仅仅考虑相关日期的数据。即使处理时间序列不是问题,Nelson和Siegel也没有指定_正式的_算法来选择的最佳值。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
关于boost::shared_ptr...高兴得太早 - Charlie's Blog ...
Boost编程指南之BoostThread
RCF—用于C++的进程间通讯
Boost智能指针——scoped_ptr
智能指针
八 智能指针类
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服