Quantlib 将日期向量传递给 Schedule class
Quantlib passing a date vector to Schedule class
我很欣赏 Quantlib Schedule class 可以将日期向量作为构造函数。我已经通过这种方式成功地建立了一个时间表。但是,当我将此计划传递给 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()
return 0.
我发现这个 link 很有用:
http://www.implementingquantlib.com/2014/11/odds-and-ends-date-calculations.html
但是,我不确定我是否完全理解关于如何解决此问题的最后一段。有谁可以给我举个例子吗?
非常感谢
自从几个版本以来,采用日期向量的构造函数已经扩展(如您引用的 link 中所建议的那样)以采用其他参数。现在声明为:
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
).
我很欣赏 Quantlib Schedule class 可以将日期向量作为构造函数。我已经通过这种方式成功地建立了一个时间表。但是,当我将此计划传递给 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()
return 0.
我发现这个 link 很有用: http://www.implementingquantlib.com/2014/11/odds-and-ends-date-calculations.html
但是,我不确定我是否完全理解关于如何解决此问题的最后一段。有谁可以给我举个例子吗?
非常感谢
自从几个版本以来,采用日期向量的构造函数已经扩展(如您引用的 link 中所建议的那样)以采用其他参数。现在声明为:
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
).