Skip to content

Commit

Permalink
QPR-11975 fix past payment dates
Browse files Browse the repository at this point in the history
QuantLib PR: lballabio#1775
  • Loading branch information
pcaspers committed Aug 27, 2023
1 parent 88c3a2c commit 00d2fce
Showing 2 changed files with 29 additions and 29 deletions.
55 changes: 27 additions & 28 deletions ql/cashflows/lineartsrpricer.cpp
Original file line number Diff line number Diff line change
@@ -26,8 +26,8 @@
#include <ql/cashflows/iborcoupon.hpp>
#include <ql/cashflows/lineartsrpricer.hpp>
#include <ql/indexes/iborindex.hpp>
#include <ql/instruments/vanillaswap.hpp>
#include <ql/instruments/overnightindexedswap.hpp>
#include <ql/instruments/vanillaswap.hpp>
#include <ql/math/integrals/kronrodintegral.hpp>
#include <ql/math/solvers1d/brent.hpp>
#include <ql/pricingengines/blackformula.hpp>
@@ -123,23 +123,31 @@ namespace QuantLib {

today_ = QuantLib::Settings::instance().evaluationDate();

if (paymentDate_ > today_ && !couponDiscountCurve_.empty())
couponDiscountRatio_ =
couponDiscountCurve_->discount(paymentDate_) /
discountCurve_->discount(paymentDate_);
else
couponDiscountRatio_ = 1.;
Real couponCurvePaymentDiscount;
if (!couponDiscountCurve_.empty() && paymentDate_ > couponDiscountCurve_->referenceDate()) {
couponCurvePaymentDiscount = couponDiscountCurve_->discount(paymentDate_);
} else {
couponCurvePaymentDiscount = 1.0;
}

if (paymentDate_ > discountCurve_->referenceDate()) {
discountCurvePaymentDiscount_ = discountCurve_->discount(paymentDate_);
} else {
discountCurvePaymentDiscount_ = 1.0;
}


spreadLegValue_ = spread_ * coupon_->accrualPeriod() *
discountCurve_->discount(paymentDate_) *
couponDiscountRatio_ = couponCurvePaymentDiscount / discountCurvePaymentDiscount_;

spreadLegValue_ = spread_ * coupon_->accrualPeriod() * discountCurvePaymentDiscount_ *
couponDiscountRatio_;

if (fixingDate_ > today_) {

swapTenor_ = swapIndex_->tenor();

Leg swapFixedLeg;
if(auto on = boost::dynamic_pointer_cast<OvernightIndexedSwapIndex>(swapIndex_)) {
if(auto on = ext::dynamic_pointer_cast<OvernightIndexedSwapIndex>(swapIndex_)) {
onSwap_ = on->underlyingSwap(fixingDate_);
swapRateValue_ = onSwap_->fairRate();
annuity_ = 1.0E4 * std::fabs(onSwap_->fixedLegBPS());
@@ -371,8 +379,7 @@ namespace QuantLib {

Rate LinearTsrPricer::swapletRate() const {
return swapletPrice() /
(coupon_->accrualPeriod() *
discountCurve_->discount(paymentDate_) * couponDiscountRatio_);
(coupon_->accrualPeriod() * discountCurvePaymentDiscount_ * couponDiscountRatio_);
}

Real LinearTsrPricer::capletPrice(Rate effectiveCap) const {
@@ -381,10 +388,8 @@ namespace QuantLib {
// the fixing is determined
const Rate Rs = std::max(
coupon_->swapIndex()->fixing(fixingDate_) - effectiveCap, 0.);
Rate price =
(gearing_ * Rs) *
(coupon_->accrualPeriod() *
discountCurve_->discount(paymentDate_) * couponDiscountRatio_);
Rate price = (gearing_ * Rs) * (coupon_->accrualPeriod() *
discountCurvePaymentDiscount_ * couponDiscountRatio_);
return price;
} else {
Real capletPrice = optionletPrice(Option::Call, effectiveCap);
@@ -394,8 +399,7 @@ namespace QuantLib {

Rate LinearTsrPricer::capletRate(Rate effectiveCap) const {
return capletPrice(effectiveCap) /
(coupon_->accrualPeriod() *
discountCurve_->discount(paymentDate_) * couponDiscountRatio_);
(coupon_->accrualPeriod() * discountCurvePaymentDiscount_ * couponDiscountRatio_);
}

Real LinearTsrPricer::floorletPrice(Rate effectiveFloor) const {
@@ -404,10 +408,8 @@ namespace QuantLib {
// the fixing is determined
const Rate Rs = std::max(
effectiveFloor - coupon_->swapIndex()->fixing(fixingDate_), 0.);
Rate price =
(gearing_ * Rs) *
(coupon_->accrualPeriod() *
discountCurve_->discount(paymentDate_) * couponDiscountRatio_);
Rate price = (gearing_ * Rs) * (coupon_->accrualPeriod() *
discountCurvePaymentDiscount_ * couponDiscountRatio_);
return price;
} else {
Real floorletPrice = optionletPrice(Option::Put, effectiveFloor);
@@ -417,8 +419,7 @@ namespace QuantLib {

Rate LinearTsrPricer::floorletRate(Rate effectiveFloor) const {
return floorletPrice(effectiveFloor) /
(coupon_->accrualPeriod() *
discountCurve_->discount(paymentDate_) * couponDiscountRatio_);
(coupon_->accrualPeriod() * discountCurvePaymentDiscount_ * couponDiscountRatio_);
}

Real LinearTsrPricer::swapletPrice() const {
@@ -427,14 +428,12 @@ namespace QuantLib {
const Rate Rs = coupon_->swapIndex()->fixing(fixingDate_);
Rate price =
(gearing_ * Rs + spread_) *
(coupon_->accrualPeriod() *
discountCurve_->discount(paymentDate_) * couponDiscountRatio_);
(coupon_->accrualPeriod() * discountCurvePaymentDiscount_ * couponDiscountRatio_);
return price;
} else {
Real atmCapletPrice = optionletPrice(Option::Call, swapRateValue_);
Real atmFloorletPrice = optionletPrice(Option::Put, swapRateValue_);
return gearing_ * (coupon_->accrualPeriod() *
discountCurve_->discount(paymentDate_) *
return gearing_ * (coupon_->accrualPeriod() * discountCurvePaymentDiscount_ *
swapRateValue_ * couponDiscountRatio_ +
atmCapletPrice - atmFloorletPrice) +
spreadLegValue_;
3 changes: 2 additions & 1 deletion ql/cashflows/lineartsrpricer.hpp
Original file line number Diff line number Diff line change
@@ -233,7 +233,8 @@ namespace QuantLib {
Real gearing_, spread_;

Period swapTenor_;
Real spreadLegValue_, swapRateValue_, couponDiscountRatio_, annuity_;
Real spreadLegValue_, swapRateValue_, couponDiscountRatio_, discountCurvePaymentDiscount_,
annuity_;

ext::shared_ptr<SwapIndex> swapIndex_;
ext::shared_ptr<VanillaSwap> swap_;

0 comments on commit 00d2fce

Please sign in to comment.