Skip to content

Commit

Permalink
Merge pull request #1256.
Browse files Browse the repository at this point in the history
Check for ex-trading date in `Coupon::accruedPeriod`
  • Loading branch information
lballabio committed Dec 2, 2021
2 parents eaf0315 + 44fd1a8 commit 38a6c45
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 27 deletions.
3 changes: 3 additions & 0 deletions ql/cashflows/coupon.cpp
Expand Up @@ -57,6 +57,9 @@ namespace QuantLib {
Time Coupon::accruedPeriod(const Date& d) const {
if (d <= accrualStartDate_ || d > paymentDate_) {
return 0.0;
} else if (tradingExCoupon(d)) {
return -dayCounter().yearFraction(d, std::max(d, accrualEndDate_),
refPeriodStart_, refPeriodEnd_);
} else {
return dayCounter().yearFraction(accrualStartDate_,
std::min(d, accrualEndDate_),
Expand Down
11 changes: 1 addition & 10 deletions ql/cashflows/floatingratecoupon.cpp
Expand Up @@ -70,17 +70,8 @@ namespace QuantLib {
if (d <= accrualStartDate_ || d > paymentDate_) {
// out of coupon range
return 0.0;
} else if (tradingExCoupon(d)) {
return -nominal() * rate() *
dayCounter().yearFraction(d, std::max(d, accrualEndDate_),
refPeriodStart_, refPeriodEnd_);
} else {
// usual case
return nominal() * rate() *
dayCounter().yearFraction(accrualStartDate_,
std::min(d, accrualEndDate_),
refPeriodStart_,
refPeriodEnd_);
return nominal() * rate() * accruedPeriod(d);
}
}

Expand Down
16 changes: 2 additions & 14 deletions ql/cashflows/inflationcoupon.cpp
Expand Up @@ -73,20 +73,8 @@ namespace QuantLib {
Real InflationCoupon::accruedAmount(const Date& d) const {
if (d <= accrualStartDate_ || d > paymentDate_) {
return 0.0;
}else if (tradingExCoupon(d)) {
return -nominal() * rate() *
dayCounter().yearFraction(d,
std::max(d, accrualEndDate_),
refPeriodStart_,
refPeriodEnd_);
}
else {
return nominal() * rate() *
dayCounter().yearFraction(accrualStartDate_,
std::min(d, accrualEndDate_),
refPeriodStart_,
refPeriodEnd_);

} else {
return nominal() * rate() * accruedPeriod(d);
}
}

Expand Down
4 changes: 1 addition & 3 deletions ql/cashflows/overnightindexedcoupon.cpp
Expand Up @@ -235,9 +235,7 @@ namespace QuantLib {
// out of coupon range
return 0.0;
} else if (tradingExCoupon(d)) {
return -nominal() * averageRate(d) *
dayCounter().yearFraction(d, std::max(d, accrualEndDate_), refPeriodStart_,
refPeriodEnd_);
return nominal() * averageRate(d) * accruedPeriod(d);
} else {
// usual case
return nominal() * averageRate(std::min(d, accrualEndDate_)) * accruedPeriod(d);
Expand Down

0 comments on commit 38a6c45

Please sign in to comment.