我正在使用QuantLib 1.19在C++。当我试图传递一个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,
const Period& tenor,
Natural settlementDays,
const Currency& currency,
const Calendar& fixingCalendar,
BusinessDayConvention convention,
bool endOfMonth,
const DayCounter& dayCounter,
Handle<YieldTermStructure> h = Handle<YieldTermStructure>());我是C++的新手。所以,也许这真的是一个基本的C++问题。但是你能帮我理解一下我在1.19中出现这个错误的原因吗?为什么现在在1.22中改变了?
事先非常感谢。
发布于 2021-04-21 09:19:23
构造函数参数特别要求您传递一个Handle<YieldTermStructure>。
但是,您正在传递一个Handle<TermStructure>,这是一个不兼容的类型,这就是您获得错误的原因。
我不知道图书馆,但我希望你可以通过声明
Handle<YieldTermStructure> crv_handle(crv);1.22中发生的变化是不相关的。该参数的参数传递方法已从按常量引用改为按值传递.你还是会犯同样的错误。
https://stackoverflow.com/questions/67192496
复制相似问题