gpt4 book ai didi

c++ - Quantlib 将日期 vector 传递给 Schedule 类

转载 作者:行者123 更新时间:2023-11-30 03:36:20 25 4
gpt4 key购买 nike

我很欣赏 Quantlib Schedule 类可以将日期 vector 作为构造函数。我已经通过这种方式成功地建立了一个时间表。但是,当我将此计划传递给 vanillaswap 构造函数时,代码开始在 schedule.cpp 中的函数 bool Schedule::isRegular(Size i) const 上生成错误。这是我与此错误相关的部分代码:

vector<Date> fixedDates;
vector<Date> floatDates;

fixedDates.push_back(Date(15, April, 2016));
fixedDates.push_back(Date(18, April, 2017));
floatDates.push_back(Date(15, April, 2016));
floatDates.push_back(Date(15, July, 2016));
floatDates.push_back(Date(17, October, 2016));
floatDates.push_back(Date(17, January, 2017));
floatDates.push_back(Date(18, April, 2017));

Schedule fixedSchedule(fixedDates);
Schedule floatSchedule(floatDates);

VanillaSwap::Type swapType = VanillaSwap::Payer;
VanillaSwap swap(swapType, nominal, fixedSchedule, fixedRate, Actual365Fixed(), floatSchedule, libor, spread, Actual365Fixed());

当我运行我的代码时,由于 isRegular_.size() 返回 0 而失败。

我发现这个链接很有用: http://www.implementingquantlib.com/2014/11/odds-and-ends-date-calculations.html

但是,我不确定我是否完全理解关于如何解决此问题的最后一段。有没有人可以给我举个例子?

非常感谢

最佳答案

自从几个版本以来,采用日期 vector 的构造函数已经扩展(如您引用的链接中所建议的那样)以采用其他参数。现在声明为:

Schedule(const std::vector<Date>&,
const Calendar& calendar = NullCalendar(),
const BusinessDayConvention
convention = Unadjusted,
boost::optional<BusinessDayConvention>
terminationDateConvention = boost::none,
const boost::optional<Period> tenor = boost::none,
boost::optional<DateGeneration::Rule> rule = boost::none,
boost::optional<bool> endOfMonth = boost::none,
const std::vector<bool>& isRegular = std::vector<bool>(0));

这样您就可以传递日程表无法从日期中找出的任何缺失信息;例如,您可以传递 isRegular作为vector<bool>(n, true)其中 n是时间表中的日期数(当然假设周期是固定的;如果你有短期或长期优惠券,你应该在相应位置的 vector 中放置一个 false)。

关于c++ - Quantlib 将日期 vector 传递给 Schedule 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40770485/

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