2

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

Ben10
  • 121
  • 1
  • 13

1 Answers1

3

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

Luigi Ballabio
  • 4,128
  • 21
  • 29
  • With QuantLib 1.16 I'm trying to implement a `FixedRateBond` with a custom schedule with the Python bindings. I cannot make it work, it keeps throwing `full interface (tenor) not available` upon instantiating the `FixedRateBond`. What I'm passing as a schedule is `ql.Schedule(interest_payment_dates, ql.NullCalendar(), ql.Unadjusted, None, None, None, True, np.repeat(False, len(interest_payment_dates)-1).tolist())` with `interest_payment_dates` being an array of some `Date`s. How come this arrises? – Clawish Dec 02 '19 at 10:32