Skip to content

Commit

Permalink
Allow setting conventions and per-leg EOM in MakeOIS
Browse files Browse the repository at this point in the history
Closes #1875
  • Loading branch information
eltoder committed Jan 17, 2024
1 parent 9b052b1 commit 20dadbc
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 12 deletions.
69 changes: 58 additions & 11 deletions ql/instruments/makeois.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
}
Expand All @@ -97,20 +102,23 @@ namespace QuantLib {
Schedule fixedSchedule(startDate, endDate,
Period(fixedPaymentFrequency),
fixedCalendar_,
ModifiedFollowing,
ModifiedFollowing,
fixedConvention_,
fixedTerminationDateConvention_,
fixedRule,
usedEndOfMonth);
fixedEndOfMonth);
ext::optional<Schedule> 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_;
Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 13 additions & 1 deletion ql/instruments/makeois.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 20dadbc

Please sign in to comment.