Skip to content

Commit

Permalink
Allow setting conventions and per-leg EOM in MakeOIS (#1890)
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Jan 31, 2024
2 parents c6e9323 + ff1124a commit eb68e03
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 23 deletions.
88 changes: 66 additions & 22 deletions ql/instruments/makeois.cpp
Expand Up @@ -23,7 +23,6 @@
#include <ql/instruments/makeois.hpp>
#include <ql/pricingengines/swap/discountingswapengine.hpp>
#include <ql/indexes/iborindex.hpp>
#include <ql/optional.hpp>
#include <ql/time/schedule.hpp>

namespace QuantLib {
Expand Down Expand Up @@ -63,16 +62,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_;
}
Expand All @@ -97,29 +101,26 @@ namespace QuantLib {
Schedule fixedSchedule(startDate, endDate,
Period(fixedPaymentFrequency),
fixedCalendar_,
ModifiedFollowing,
ModifiedFollowing,
fixedConvention_,
fixedTerminationDateConvention_,
fixedRule,
usedEndOfMonth);
ext::optional<Schedule> overnightSchedule;
if (fixedPaymentFrequency != overnightPaymentFrequency || fixedRule != overnightRule ||
fixedCalendar_ != overnightCalendar_) {
overnightSchedule.emplace(startDate, endDate,
Period(overnightPaymentFrequency),
overnightCalendar_,
ModifiedFollowing,
ModifiedFollowing,
overnightRule,
usedEndOfMonth);
}
fixedEndOfMonth);

Schedule overnightSchedule(startDate, endDate,
Period(overnightPaymentFrequency),
overnightCalendar_,
overnightConvention_,
overnightTerminationDateConvention_,
overnightRule,
overnightEndOfMonth);

Rate usedFixedRate = fixedRate_;
if (fixedRate_ == Null<Rate>()) {
OvernightIndexedSwap temp(type_, nominal_,
fixedSchedule,
0.0, // fixed rate
fixedDayCount_,
overnightSchedule ? *overnightSchedule : fixedSchedule,
overnightSchedule,
overnightIndex_, overnightSpread_,
paymentLag_, paymentAdjustment_,
paymentCalendar_, telescopicValueDates_);
Expand All @@ -143,7 +144,7 @@ namespace QuantLib {
OvernightIndexedSwap(type_, nominal_,
fixedSchedule,
usedFixedRate, fixedDayCount_,
overnightSchedule ? *overnightSchedule : fixedSchedule,
overnightSchedule,
overnightIndex_, overnightSpread_,
paymentLag_, paymentAdjustment_,
paymentCalendar_, telescopicValueDates_,
Expand Down Expand Up @@ -223,6 +224,10 @@ namespace QuantLib {
return *this;
}

MakeOIS& MakeOIS::withCalendar(const Calendar& cal) {
return withFixedLegCalendar(cal).withOvernightLegCalendar(cal);
}

MakeOIS& MakeOIS::withFixedLegCalendar(const Calendar& cal) {
fixedCalendar_ = cal;
return *this;
Expand Down Expand Up @@ -266,8 +271,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;
}
Expand Down
15 changes: 14 additions & 1 deletion ql/instruments/makeois.hpp
Expand Up @@ -63,10 +63,19 @@ namespace QuantLib {
MakeOIS& withPaymentAdjustment(BusinessDayConvention convention);
MakeOIS& withPaymentLag(Integer lag);
MakeOIS& withPaymentCalendar(const Calendar& cal);
MakeOIS& withCalendar(const Calendar& cal);
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);

Expand Down Expand Up @@ -97,9 +106,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;
Expand Down

0 comments on commit eb68e03

Please sign in to comment.