gpt4 book ai didi

C++ : use of class and constructor

转载 作者:行者123 更新时间:2023-11-28 07:46:39 25 4
gpt4 key购买 nike

我正在粗略地使用 QuantLib 库中的 QuantLib::TimeSeries 类。我的问题与 QuantLib 及其复杂性无关,但我认为在更一般的 C++ 类使用中。

描述了 QuantLib::TimeSeries here .在我的代码中(目前完全不返回任何内容),我在 std::vector 中提供了一系列日期,并在 std::vector 中提供了一系列价格。 QuantLib::TimeSeries 对象应该将日期和价格联系在一起。

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

如果有人提供指导,帮助我完成这项工作,我将不胜感激。

谢谢。

最佳答案

我认为你的困难线应该是这样的:

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

来自您链接的文档:

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

第一个参数是你存储的类型,在你的例子中是double,第二个参数可能是容器用来作为实现的类型,它已经有一个默认实现,所以不需要任何东西。

关于C++ : use of class and constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14791496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com