Quantlib将日期向量传递给Schedule类

时间:2016-11-23 17:11:06

标签: c++ quantlib

我很欣赏Quantlib Schedule类可以将日期向量作为构造函数。我已经通过这种方式成功建立了一个时间表。但是,当我将此计划传递给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

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

非常感谢

1 个答案:

答案 0 :(得分:1)

由于一些版本,带有日期向量的构造函数已经扩展(如您引用的链接中所示)以获取其他参数。它现在声明为:

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是时间表中的日期数(假设时间段是常规的;如果您有短期或长期优惠券,你应该在对应的位置放一个false