1
$\begingroup$

I want to create am LmFixedVolatilityModel object as defined in http://www.jquantlib.com/en/latest/_static/javadocs/0.2.6-SNAPSHOT/jquantlib/index.html?org/jquantlib/pricingengines/swap/DiscountingSwapEngine.html

Below is my code -

#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);
}

However with this implementation, I am getting below error -

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 {

Could you please help me with the right way to create an LmFixedVolatilityModel object?

Many thanks for your time and help.

$\endgroup$
1
  • $\begingroup$ volvalues should be a QuantLib::Array $\endgroup$
    – Giogre
    Oct 4, 2020 at 12:36

1 Answer 1

0
$\begingroup$

I have not QuantLib installed at the moment, so I have no means to check the code below. However I could not resist posting this. Please verify whether it works.

#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;
}
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.