Skip to content

Commit c493cf9

Browse files
committed
QPR-11232 add explicit payment dates to fixed rate leg
1 parent e03787a commit c493cf9

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

ql/cashflows/fixedratecoupon.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,29 @@ namespace QuantLib {
169169
return *this;
170170
}
171171

172+
FixedRateLeg& FixedRateLeg::withPaymentDates(const std::vector<Date>& paymentDates) {
173+
paymentDates_ = paymentDates;
174+
return *this;
175+
}
176+
177+
172178
FixedRateLeg::operator Leg() const {
173179

174180
QL_REQUIRE(!couponRates_.empty(), "no coupon rates given");
175181
QL_REQUIRE(!notionals_.empty(), "no notional given");
182+
QL_REQUIRE(paymentDates_.empty() || paymentDates.size() == schedule_.size() - 1,
183+
"Expected the number of explicit payment dates ("
184+
<< paymentDates_.size() << ") to equal the number of calculation periods ("
185+
<< schedule_.size() - 1 << ")");
176186

177187
Leg leg;
178188
leg.reserve(schedule_.size()-1);
179189

180190
// first period might be short or long
181191
Date start = schedule_.date(0), end = schedule_.date(1);
182-
Date paymentDate = paymentCalendar_.advance(end, paymentLag_, Days, paymentAdjustment_);
192+
Date paymentDate = paymentDates_.empty() ? paymentCalendar_.advance(end, paymentLag_, Days,
193+
paymentAdjustment_) :
194+
paymentDates_[0];
183195
Date exCouponDate;
184196
InterestRate rate = couponRates_[0];
185197
Real nominal = notionals_[0];
@@ -208,7 +220,10 @@ namespace QuantLib {
208220
// regular periods
209221
for (Size i=2; i<schedule_.size()-1; ++i) {
210222
start = end; end = schedule_.date(i);
211-
Date paymentDate = paymentCalendar_.advance(end, paymentLag_, Days, paymentAdjustment_);
223+
Date paymentDate =
224+
paymentDates_.empty() ?
225+
paymentCalendar_.advance(end, paymentLag_, Days, paymentAdjustment_) :
226+
paymentDates_[i - 1];
212227
if (exCouponPeriod_ != Period())
213228
{
214229
exCouponDate = exCouponCalendar_.advance(paymentDate,
@@ -232,7 +247,10 @@ namespace QuantLib {
232247
// last period might be short or long
233248
Size N = schedule_.size();
234249
start = end; end = schedule_.date(N-1);
235-
Date paymentDate = paymentCalendar_.advance(end, paymentLag_, Days, paymentAdjustment_);
250+
Date paymentDate =
251+
paymentDates_.empty() ?
252+
paymentCalendar_.advance(end, paymentLag_, Days, paymentAdjustment_) :
253+
paymentDates_[N - 2];
236254
if (exCouponPeriod_ != Period())
237255
{
238256
exCouponDate = exCouponCalendar_.advance(paymentDate,

ql/cashflows/fixedratecoupon.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ namespace QuantLib {
106106
const Calendar&,
107107
BusinessDayConvention,
108108
bool endOfMonth = false);
109+
FixedRateLeg& withPaymentDates(const std::vector<Date>& paymentDates);
109110
operator Leg() const;
110111
private:
111112
Schedule schedule_;
@@ -119,6 +120,7 @@ namespace QuantLib {
119120
Calendar exCouponCalendar_;
120121
BusinessDayConvention exCouponAdjustment_ = Following;
121122
bool exCouponEndOfMonth_ = false;
123+
std::vector<Date> paymentDates_;
122124
};
123125

124126
inline void FixedRateCoupon::accept(AcyclicVisitor& v) {

0 commit comments

Comments
 (0)