关于前端:R语言和QuantLib中NelsonSiegel模型收益曲线建模分析

52次阅读

共计 4254 个字符,预计需要花费 11 分钟才能阅读完成。

 原文链接: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.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 };

 
        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 也没有指定_正式的_算法来抉择的最佳值。

正文完
 0