diff --git a/ql/instruments/makeois.cpp b/ql/instruments/makeois.cpp index eef85a1a1e7..8f2949d2bc2 100644 --- a/ql/instruments/makeois.cpp +++ b/ql/instruments/makeois.cpp @@ -63,16 +63,21 @@ namespace QuantLib { } // OIS end of month default - bool usedEndOfMonth = - isDefaultEOM_ ? overnightCalendar_.isEndOfMonth(startDate) : endOfMonth_; + bool fixedEndOfMonth, overnightEndOfMonth; + if (isDefaultEOM_) { + fixedEndOfMonth = overnightEndOfMonth = overnightCalendar_.isEndOfMonth(startDate); + } else { + fixedEndOfMonth = fixedEndOfMonth_; + overnightEndOfMonth = overnightEndOfMonth_; + } Date endDate = terminationDate_; if (endDate == Date()) { - if (usedEndOfMonth) + if (overnightEndOfMonth) endDate = overnightCalendar_.advance(startDate, swapTenor_, ModifiedFollowing, - usedEndOfMonth); + overnightEndOfMonth); else endDate = startDate + swapTenor_; } @@ -97,20 +102,23 @@ namespace QuantLib { Schedule fixedSchedule(startDate, endDate, Period(fixedPaymentFrequency), fixedCalendar_, - ModifiedFollowing, - ModifiedFollowing, + fixedConvention_, + fixedTerminationDateConvention_, fixedRule, - usedEndOfMonth); + fixedEndOfMonth); ext::optional overnightSchedule; if (fixedPaymentFrequency != overnightPaymentFrequency || fixedRule != overnightRule || + fixedConvention_ != overnightConvention_ || + fixedTerminationDateConvention_ != overnightTerminationDateConvention_ || + fixedEndOfMonth != overnightEndOfMonth || fixedCalendar_ != overnightCalendar_) { overnightSchedule.emplace(startDate, endDate, Period(overnightPaymentFrequency), overnightCalendar_, - ModifiedFollowing, - ModifiedFollowing, + overnightConvention_, + overnightTerminationDateConvention_, overnightRule, - usedEndOfMonth); + overnightEndOfMonth); } Rate usedFixedRate = fixedRate_; @@ -266,8 +274,47 @@ namespace QuantLib { return *this; } + MakeOIS& MakeOIS::withConvention(BusinessDayConvention bdc) { + return withFixedLegConvention(bdc).withOvernightLegConvention(bdc); + } + + MakeOIS& MakeOIS::withFixedLegConvention(BusinessDayConvention bdc) { + fixedConvention_ = bdc; + return *this; + } + + MakeOIS& MakeOIS::withOvernightLegConvention(BusinessDayConvention bdc) { + overnightConvention_ = bdc; + return *this; + } + + MakeOIS& MakeOIS::withTerminationDateConvention(BusinessDayConvention bdc) { + withFixedLegTerminationDateConvention(bdc); + return withOvernightLegTerminationDateConvention(bdc); + } + + MakeOIS& MakeOIS::withFixedLegTerminationDateConvention(BusinessDayConvention bdc) { + fixedTerminationDateConvention_ = bdc; + return *this; + } + + MakeOIS& MakeOIS::withOvernightLegTerminationDateConvention(BusinessDayConvention bdc) { + overnightTerminationDateConvention_ = bdc; + return *this; + } + MakeOIS& MakeOIS::withEndOfMonth(bool flag) { - endOfMonth_ = flag; + return withFixedLegEndOfMonth(flag).withOvernightLegEndOfMonth(flag); + } + + MakeOIS& MakeOIS::withFixedLegEndOfMonth(bool flag) { + fixedEndOfMonth_ = flag; + isDefaultEOM_ = false; + return *this; + } + + MakeOIS& MakeOIS::withOvernightLegEndOfMonth(bool flag) { + overnightEndOfMonth_ = flag; isDefaultEOM_ = false; return *this; } diff --git a/ql/instruments/makeois.hpp b/ql/instruments/makeois.hpp index 6c39b9a69e7..6e59d33d1bc 100644 --- a/ql/instruments/makeois.hpp +++ b/ql/instruments/makeois.hpp @@ -66,7 +66,15 @@ namespace QuantLib { MakeOIS& withFixedLegCalendar(const Calendar& cal); MakeOIS& withOvernightLegCalendar(const Calendar& cal); + MakeOIS& withConvention(BusinessDayConvention bdc); + MakeOIS& withFixedLegConvention(BusinessDayConvention bdc); + MakeOIS& withOvernightLegConvention(BusinessDayConvention bdc); + MakeOIS& withTerminationDateConvention(BusinessDayConvention bdc); + MakeOIS& withFixedLegTerminationDateConvention(BusinessDayConvention bdc); + MakeOIS& withOvernightLegTerminationDateConvention(BusinessDayConvention bdc); MakeOIS& withEndOfMonth(bool flag = true); + MakeOIS& withFixedLegEndOfMonth(bool flag = true); + MakeOIS& withOvernightLegEndOfMonth(bool flag = true); MakeOIS& withFixedLegDayCount(const DayCounter& dc); @@ -97,9 +105,13 @@ namespace QuantLib { BusinessDayConvention paymentAdjustment_ = Following; Integer paymentLag_ = 0; + BusinessDayConvention fixedConvention_ = ModifiedFollowing, + fixedTerminationDateConvention_ = ModifiedFollowing, + overnightConvention_ = ModifiedFollowing, + overnightTerminationDateConvention_ = ModifiedFollowing; DateGeneration::Rule fixedRule_ = DateGeneration::Backward; DateGeneration::Rule overnightRule_ = DateGeneration::Backward; - bool endOfMonth_ = false, isDefaultEOM_ = true; + bool fixedEndOfMonth_ = false, overnightEndOfMonth_ = false, isDefaultEOM_ = true; Swap::Type type_ = Swap::Payer; Real nominal_ = 1.0;