Ben10 Ben10 - 1 year ago 59
C++ Question

Quantlib passing a date vector to Schedule class

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
return 0.

I found this link is useful:

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

Answer Source

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,
                 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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download