QuantLib 错误:“QuantLib::Handle<QuantLib::TermStructure>”无法转换为“const QuantLib::Handle<QuantLib::YieldTermStructure> &”

问题描述

我正在使用 C++ 中的 QuantLib 1.19。当我尝试传递一个 TermStructure 句柄来创建一个新的 IborIndex 时,我得到了主题中的错误。我的代码看起来像:

#include <iostream>
#include <ql/quantlib.hpp>
#include <vector>

int main() {
    using namespace std;
    using namespace QuantLib;

    Date today(21,Apr,2021);
    std::string familyName("TestTest");
    Period tenor(1,Years);
    Natural settlementDays(0);
    USDCurrency usd;
    Currency currency(usd);
    TARGET target;
    BusinessDayConvention convention(ModifiedFollowing);
    bool endOfMonth(true);
    Actual365Fixed dayCounter;

    ext::shared_ptr<YieldTermStructure> crv(new FlatForward(today,0.03,dayCounter));
    Handle<TermStructure> crv_handle(crv);

    IborIndex crv_index(familyName,tenor,settlementDays,currency,target,convention,endOfMonth,dayCounter,crv_handle);
    
    return EXIT_SUCCESS;
}

我正在检查 1.19 中 IborIndex 的定义,是这样的:

    class IborIndex : public InterestRateIndex {
      public:
        IborIndex(const std::string& familyName,const Period& tenor,Natural settlementDays,const Currency& currency,const Calendar& fixingCalendar,BusinessDayConvention convention,bool endOfMonth,const DayCounter& dayCounter,const Handle<YieldTermStructure>& h =
                                    Handle<YieldTermStructure>());

但在最新版本 1.22 中,它在 termstructure 句柄参数中删除了 const:

    class IborIndex : public InterestRateIndex {
      public:
        IborIndex(const std::string& familyName,Handle<YieldTermStructure> h = Handle<YieldTermStructure>());

我是 C++ 的新手。所以也许这真的是一个基本 C++ 的问题。但是你能帮我理解我在 1.19 中出现这个错误的原因吗?为什么它现在在 1.22 中发生了变化?

非常感谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)