Quantlib passing a date vector to Schedule class

自作多情 提交于 2019-12-11 08:09:36

问题


I appreciate that Quantlib Schedule class can take a date vector as constructor. I have successfully built a schedule via this way. However, when I pass this schedule to vanillaswap constructor, the code starts to generate error on function bool Schedule::isRegular(Size i) const in schedule.cpp. Here is part of my code related to this error:

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());

When I run my code, it fails due to this isRegular_.size() return 0.

I found this link is useful: http://www.implementingquantlib.com/2014/11/odds-and-ends-date-calculations.html

However, I am not sure if I am complete understand the last paragraph about how to fix this problem. Is there anyone can give me an example here?

Many thanks


回答1:


Since a few releases, the constructor that takes a vector of dates has been expanded (as suggested in the link you quoted) to take additional parameters. It is now declared as:

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));

so you can pass any missing information that the schedule is not able to figure out from the dates; for example, you can pass isRegular as vector<bool>(n, true) where n is the number of dates in the schedule (assuming the periods are regular, of course; in case you have a short or long coupon, you should put a false in the vector at the corresponding position).



来源:https://stackoverflow.com/questions/40770485/quantlib-passing-a-date-vector-to-schedule-class

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!