量化庫

未能創建 Quantlib 的 LM 固定波動率模型對象

  • October 4, 2020

我想創建http://www.jquantlib.com/en/latest/_static/javadocs/0.2.6-SNAPSHOT/jquantlib/index.html?org/jquantlib/pricingengines/swap/DiscountingSwapEngine.htmlLmFixedVolatilityModel中定義的對象

下面是我的程式碼 -

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

int main() 
{
   using namespace QuantLib;

   std::vector<QuantLib::Date> voldays;
   std::vector<QuantLib::Real> volvalues;

   voldays = TARGET().businessDayList(Date(29, March, 2019), Date(29, April, 2019));
   for (int i = 0; i < voldays.size(); i++) volvalues.push_back(0.10);

   ext::shared_ptr<LmVolatilityModel> volModel(new LmFixedVolatilityModel(volvalues, voldays);
}

但是,通過此實現,我遇到了錯誤-

aa.cpp:17:50: error: no matching constructor for initialization of 'QuantLib::LmFixedVolatilityModel'
       ext::shared_ptr<LmVolatilityModel> volModel(new LmFixedVolatilityModel(volvalues, voldays));
                                                       ^                      ~~~~~~~~~~~~~~~~~~
/usr/local/include/ql/legacy/libormarketmodels/lmfixedvolmodel.hpp:33:9: note: candidate constructor not viable: no known conversion from 'std::vector<QuantLib::Real>'
     (aka 'vector<double>') to 'const QuantLib::Array' for 1st argument
       LmFixedVolatilityModel(const Array& volatilities,
       ^
/usr/local/include/ql/legacy/libormarketmodels/lmfixedvolmodel.hpp:31:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2
     were provided
   class LmFixedVolatilityModel : public LmVolatilityModel {

你能幫我用正確的方法來創建一個LmFixedVolatilityModel對象嗎?

非常感謝您的時間和幫助。

我目前還沒有安裝 QuantLib,所以我沒有辦法檢查下面的程式碼。但是我忍不住發布了這個。請驗證它是否有效。

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

using namespace QuantLib;

int main() 
{
   std::vector<Date> voldays;
   std::vector<Real> volvalues(voldays.size(), 0.1);

   voldays = TARGET().businessDayList(Date(29, March, 2019), Date(29, April, 2019));
   
   Array volarray(volvalues.begin(), volvalues.end());    // added line

   ext::shared_ptr<LmVolatilityModel> volModel(new LmFixedVolatilityModel(volarray, voldays));

return 0;
}

引用自:https://quant.stackexchange.com/questions/58441