简体   繁体   中英

C++ : use of class and constructor

I am having a rough using the QuantLib::TimeSeries class from the QuantLib library. My problem doesn't relate to QuantLib and its intricacies, but in more general C++ class use I think.

The QuantLib::TimeSeries is described here . In my code (that returns absolutely nothing for now), I provide a series of dates in a std::vector and a series of prices contained in std::vector. The QuantLib::TimeSeries object is supposed to tie together the dates and the prices.

#include<ql\quantlib.hpp>

int main()
{
    std::vector<QuantLib::Date> dates;
    std::vector<std::double> quotes;

        dates.push_back(Date(12,Nov, 2012));
    dates.push_back(Date(13,Nov, 2012));
    dates.push_back(Date(14,Nov, 2012));

    quotes.push_back(40.05);
    quotes.push_back(40.84);
    quotes.push_back(41.03);


    // Below is the line I am stuck at 
    QuantLib::TimeSeries<std::vector<QuantLib::Date>, std::vector<double>> series(dates.begin(), dates.end(), quotes.begin());

    // Now do something with all the stuff above
    // ... ...

    return 0;
}

I would appreciate someone provided guidance, helping me to make this work.

Thank you.

I think that your difficult line should be just something like:

QuantLib::TimeSeries<double> series(dates.begin(), dates.end(), quotes.begin());

From the documentation you linked:

template<class T, class Container = std::map<Date, T>>
class QuantLib::TimeSeries< T, Container >;

The first parameter is the type you store, in your case double and the second is probably one the container used to use as implementation, and it already has a default implementation, so nothing is needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM