![](/img/trans.png)
[英]quantlib multiple defininition of "QuantLib::MulticurvesSensitivities:performCalculations() const'
[英]QuantLib Error: “QuantLib::Handle<QuantLib::TermStructure>” cannot convert to “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,
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 中發生了變化?
非常感謝提前。
構造函數參數特別要求您傳遞Handle<YieldTermStructure>
。
但是,您傳遞的是不兼容類型的Handle<TermStructure>
,這就是您收到錯誤的原因。
我不知道圖書館,但我希望你可以通過聲明來糾正它
Handle<YieldTermStructure> crv_handle(crv);
1.22 中發生的變化是無關的。 該參數的參數傳遞方法已從by-constant-reference更改為by-value 。 你仍然會得到同樣的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.