diff --git a/ql/cashflows/couponpricer.cpp b/ql/cashflows/couponpricer.cpp index beaf87b66b..cad334d68e 100644 --- a/ql/cashflows/couponpricer.cpp +++ b/ql/cashflows/couponpricer.cpp @@ -253,7 +253,7 @@ namespace QuantLib { public Visitor, public Visitor, public Visitor, - public Visitor { + public Visitor { private: ext::shared_ptr pricer_; public: @@ -274,7 +274,7 @@ namespace QuantLib { void visit(DigitalCmsCoupon& c) override; void visit(DigitalCmsSpreadCoupon& c) override; void visit(RangeAccrualFloatersCoupon& c) override; - void visit(SubPeriodsCoupon& c) override; + void visit(MultipleResetsCoupon& c) override; }; void PricerSetter::visit(CashFlow&) { @@ -386,12 +386,11 @@ namespace QuantLib { c.setPricer(rangeAccrualPricer); } - void PricerSetter::visit(SubPeriodsCoupon& c) { - const ext::shared_ptr subPeriodsPricer = - ext::dynamic_pointer_cast(pricer_); - QL_REQUIRE(subPeriodsPricer, - "pricer not compatible with sub-period coupon"); - c.setPricer(subPeriodsPricer); + void PricerSetter::visit(MultipleResetsCoupon& c) { + const ext::shared_ptr pricer = + ext::dynamic_pointer_cast(pricer_); + QL_REQUIRE(pricer, "pricer not compatible with multiple-resets coupon"); + c.setPricer(pricer); } void setCouponPricersFirstMatching(const Leg& leg, diff --git a/ql/cashflows/subperiodcoupon.cpp b/ql/cashflows/subperiodcoupon.cpp index f28c4cf50f..79b2a08241 100644 --- a/ql/cashflows/subperiodcoupon.cpp +++ b/ql/cashflows/subperiodcoupon.cpp @@ -27,18 +27,18 @@ namespace QuantLib { - SubPeriodsCoupon::SubPeriodsCoupon(const Date& paymentDate, - Real nominal, - const Schedule& resetSchedule, - Natural fixingDays, - const ext::shared_ptr& index, - Real gearing, - Rate couponSpread, - Rate rateSpread, - const Date& refPeriodStart, - const Date& refPeriodEnd, - const DayCounter& dayCounter, - const Date& exCouponDate) + MultipleResetsCoupon::MultipleResetsCoupon(const Date& paymentDate, + Real nominal, + const Schedule& resetSchedule, + Natural fixingDays, + const ext::shared_ptr& index, + Real gearing, + Rate couponSpread, + Rate rateSpread, + const Date& refPeriodStart, + const Date& refPeriodEnd, + const DayCounter& dayCounter, + const Date& exCouponDate) : FloatingRateCoupon(paymentDate, nominal, resetSchedule.front(), resetSchedule.back(), fixingDays, index, gearing, couponSpread, @@ -64,19 +64,19 @@ namespace QuantLib { dt_[i] = dc.yearFraction(valueDates_[i], valueDates_[i + 1]); } - SubPeriodsCoupon::SubPeriodsCoupon(const Date& paymentDate, - Real nominal, - const Date& startDate, - const Date& endDate, - Natural fixingDays, - const ext::shared_ptr& index, - Real gearing, - Rate couponSpread, - Rate rateSpread, - const Date& refPeriodStart, - const Date& refPeriodEnd, - const DayCounter& dayCounter, - const Date& exCouponDate) + MultipleResetsCoupon::MultipleResetsCoupon(const Date& paymentDate, + Real nominal, + const Date& startDate, + const Date& endDate, + Natural fixingDays, + const ext::shared_ptr& index, + Real gearing, + Rate couponSpread, + Rate rateSpread, + const Date& refPeriodStart, + const Date& refPeriodEnd, + const DayCounter& dayCounter, + const Date& exCouponDate) : FloatingRateCoupon(paymentDate, nominal, startDate, endDate, fixingDays, index, gearing, couponSpread, refPeriodStart, refPeriodEnd, dayCounter, @@ -109,22 +109,22 @@ namespace QuantLib { dt_[i] = dc.yearFraction(valueDates_[i], valueDates_[i + 1]); } - void SubPeriodsCoupon::accept(AcyclicVisitor& v) { - auto* v1 = dynamic_cast*>(&v); + void MultipleResetsCoupon::accept(AcyclicVisitor& v) { + auto* v1 = dynamic_cast*>(&v); if (v1 != nullptr) v1->visit(*this); else FloatingRateCoupon::accept(v); } - Date SubPeriodsCoupon::fixingDate(const Date& valueDate) const { + Date MultipleResetsCoupon::fixingDate(const Date& valueDate) const { Date fixingDate = index_->fixingCalendar().advance(valueDate, -static_cast(fixingDays_), Days); return fixingDate; } - void SubPeriodsPricer::initialize(const FloatingRateCoupon& coupon) { - coupon_ = dynamic_cast(&coupon); + void MultipleResetsPricer::initialize(const FloatingRateCoupon& coupon) { + coupon_ = dynamic_cast(&coupon); QL_REQUIRE(coupon_, "sub-periods coupon required"); ext::shared_ptr index = ext::dynamic_pointer_cast(coupon_->index()); @@ -144,27 +144,27 @@ namespace QuantLib { } } - Real SubPeriodsPricer::swapletPrice() const { - QL_FAIL("SubPeriodsPricer::swapletPrice not implemented"); + Real MultipleResetsPricer::swapletPrice() const { + QL_FAIL("MultipleResetsPricer::swapletPrice not implemented"); } - Real SubPeriodsPricer::capletPrice(Rate) const { - QL_FAIL("SubPeriodsPricer::capletPrice not implemented"); + Real MultipleResetsPricer::capletPrice(Rate) const { + QL_FAIL("MultipleResetsPricer::capletPrice not implemented"); } - Rate SubPeriodsPricer::capletRate(Rate) const { - QL_FAIL("SubPeriodsPricer::capletRate not implemented"); + Rate MultipleResetsPricer::capletRate(Rate) const { + QL_FAIL("MultipleResetsPricer::capletRate not implemented"); } - Real SubPeriodsPricer::floorletPrice(Rate) const { - QL_FAIL("SubPeriodsPricer::floorletPrice not implemented"); + Real MultipleResetsPricer::floorletPrice(Rate) const { + QL_FAIL("MultipleResetsPricer::floorletPrice not implemented"); } - Rate SubPeriodsPricer::floorletRate(Rate) const { - QL_FAIL("SubPeriodsPricer::floorletRate not implemented"); + Rate MultipleResetsPricer::floorletRate(Rate) const { + QL_FAIL("MultipleResetsPricer::floorletRate not implemented"); } - Real AveragingRatePricer::swapletRate() const { + Real AveragingMultipleResetsPricer::swapletRate() const { // past or future fixing is managed in InterestRateIndex::fixing() Size nCount = subPeriodFixings_.size(); @@ -178,7 +178,7 @@ namespace QuantLib { return coupon_->gearing() * rate + coupon_->spread(); } - Real CompoundingRatePricer::swapletRate() const { + Real CompoundingMultipleResetsPricer::swapletRate() const { // past or future fixing is managed in InterestRateIndex::fixing() Real compoundFactor = 1.0; @@ -324,7 +324,7 @@ namespace QuantLib { } } - cashflows.push_back(ext::make_shared( + cashflows.push_back(ext::make_shared( paymentDate, detail::get(notionals_, i, notionals_.back()), subSchedule, detail::get(fixingDays_, i, index_->fixingDays()), index_, detail::get(gearings_, i, 1.0), detail::get(couponSpreads_, i, 0.0), @@ -334,10 +334,10 @@ namespace QuantLib { switch (averagingMethod_) { case RateAveraging::Simple: - setCouponPricer(cashflows, ext::make_shared()); + setCouponPricer(cashflows, ext::make_shared()); break; case RateAveraging::Compound: - setCouponPricer(cashflows, ext::make_shared()); + setCouponPricer(cashflows, ext::make_shared()); break; default: QL_FAIL("unknown compounding convention (" << Integer(averagingMethod_) << ")"); @@ -476,7 +476,7 @@ namespace QuantLib { paymentDate, -exCouponPeriod_, exCouponAdjustment_, exCouponEndOfMonth_); } } - cashflows.push_back(ext::shared_ptr(new SubPeriodsCoupon( + cashflows.push_back(ext::shared_ptr(new MultipleResetsCoupon( paymentDate, detail::get(notionals_, i, notionals_.back()), start, end, detail::get(fixingDays_, i, index_->fixingDays()), index_, detail::get(gearings_, i, 1.0), detail::get(couponSpreads_, i, 0.0), @@ -485,16 +485,14 @@ namespace QuantLib { } switch (averagingMethod_) { - case RateAveraging::Simple: - setCouponPricer(cashflows, - ext::shared_ptr(new AveragingRatePricer)); - break; - case RateAveraging::Compound: - setCouponPricer(cashflows, ext::shared_ptr( - new CompoundingRatePricer)); - break; - default: - QL_FAIL("unknown compounding convention (" << Integer(averagingMethod_) << ")"); + case RateAveraging::Simple: + setCouponPricer(cashflows, ext::make_shared()); + break; + case RateAveraging::Compound: + setCouponPricer(cashflows, ext::make_shared()); + break; + default: + QL_FAIL("unknown compounding convention (" << Integer(averagingMethod_) << ")"); } return cashflows; } diff --git a/ql/cashflows/subperiodcoupon.hpp b/ql/cashflows/subperiodcoupon.hpp index 140a5e138b..7268789e1c 100644 --- a/ql/cashflows/subperiodcoupon.hpp +++ b/ql/cashflows/subperiodcoupon.hpp @@ -39,7 +39,7 @@ namespace QuantLib { /*! %Coupon paying a rate calculated by compounding or averaging multiple fixings during its accrual period. */ - class SubPeriodsCoupon: public FloatingRateCoupon { + class MultipleResetsCoupon : public FloatingRateCoupon { public: /*! \param resetSchedule the schedule for the multiple resets. The first and last dates are also the start and end dates of the coupon. @@ -51,36 +51,36 @@ namespace QuantLib { \param rateSpread an optional spread added to each of the underlying fixings. \param gearing an optional multiplier for the final coupon rate. */ - SubPeriodsCoupon(const Date& paymentDate, - Real nominal, - const Schedule& resetSchedule, - Natural fixingDays, - const ext::shared_ptr& index, - Real gearing = 1.0, - Rate couponSpread = 0.0, - Rate rateSpread = 0.0, - const Date& refPeriodStart = Date(), - const Date& refPeriodEnd = Date(), - const DayCounter& dayCounter = DayCounter(), - const Date& exCouponDate = Date()); + MultipleResetsCoupon(const Date& paymentDate, + Real nominal, + const Schedule& resetSchedule, + Natural fixingDays, + const ext::shared_ptr& index, + Real gearing = 1.0, + Rate couponSpread = 0.0, + Rate rateSpread = 0.0, + const Date& refPeriodStart = Date(), + const Date& refPeriodEnd = Date(), + const DayCounter& dayCounter = DayCounter(), + const Date& exCouponDate = Date()); /*! \deprecated Use the other constructor. Deprecated in version 1.37. */ [[deprecated("Use the other constructor")]] - SubPeriodsCoupon(const Date& paymentDate, - Real nominal, - const Date& startDate, - const Date& endDate, - Natural fixingDays, - const ext::shared_ptr& index, - Real gearing = 1.0, - Rate couponSpread = 0.0, - Rate rateSpread = 0.0, - const Date& refPeriodStart = Date(), - const Date& refPeriodEnd = Date(), - const DayCounter& dayCounter = DayCounter(), - const Date& exCouponDate = Date()); + MultipleResetsCoupon(const Date& paymentDate, + Real nominal, + const Date& startDate, + const Date& endDate, + Natural fixingDays, + const ext::shared_ptr& index, + Real gearing = 1.0, + Rate couponSpread = 0.0, + Rate rateSpread = 0.0, + const Date& refPeriodStart = Date(), + const Date& refPeriodEnd = Date(), + const DayCounter& dayCounter = DayCounter(), + const Date& exCouponDate = Date()); //! \name Inspectors //@{ @@ -111,7 +111,14 @@ namespace QuantLib { Rate rateSpread_; }; - class SubPeriodsPricer: public FloatingRateCouponPricer { + /*! \deprecated Renamed to MultipleResetsCoupon. + Deprecated in version 1.37. + */ + [[deprecated("Renamed to MultipleResetsCoupon")]] + typedef MultipleResetsCoupon SubPeriodsCoupon; + + + class MultipleResetsPricer: public FloatingRateCouponPricer { public: Rate swapletPrice() const override; Real capletPrice(Rate effectiveCap) const override; @@ -121,20 +128,38 @@ namespace QuantLib { void initialize(const FloatingRateCoupon& coupon) override; protected: - const SubPeriodsCoupon* coupon_; + const MultipleResetsCoupon* coupon_; std::vector subPeriodFixings_; }; - class AveragingRatePricer: public SubPeriodsPricer { + /*! \deprecated Renamed to MultipleResetsPricer. + Deprecated in version 1.37. + */ + [[deprecated("Renamed to MultipleResetsPricer")]] + typedef MultipleResetsPricer SubPeriodsPricer; + + class AveragingMultipleResetsPricer: public MultipleResetsPricer { public: Real swapletRate() const override; }; - class CompoundingRatePricer: public SubPeriodsPricer { + /*! \deprecated Renamed to AveragingMultipleResetsPricer. + Deprecated in version 1.37. + */ + [[deprecated("Renamed to AveragingMultipleResetsPricer")]] + typedef AveragingMultipleResetsPricer AveragingRatePricer; + + class CompoundingMultipleResetsPricer: public MultipleResetsPricer { public: Real swapletRate() const override; }; + /*! \deprecated Renamed to CompoundingMultipleResetsPricer. + Deprecated in version 1.37. + */ + [[deprecated("Renamed to CompoundingMultipleResetsPricer")]] + typedef CompoundingMultipleResetsPricer CompoundingRatePricer; + //! helper class building a sequence of multiple-reset coupons class MultipleResetsLeg { diff --git a/ql/instruments/zerocouponswap.cpp b/ql/instruments/zerocouponswap.cpp index 92eea77a7d..2e6591b9e1 100644 --- a/ql/instruments/zerocouponswap.cpp +++ b/ql/instruments/zerocouponswap.cpp @@ -27,6 +27,7 @@ namespace QuantLib { namespace { + ext::shared_ptr compoundedSubPeriodicCoupon(const Date& paymentDate, const Date& startDate, @@ -41,12 +42,12 @@ namespace QuantLib { .withConvention(index->businessDayConvention()) .backwards() .endOfMonth(index->endOfMonth()); - auto floatCpn = ext::make_shared( + auto floatCpn = ext::make_shared( paymentDate, nominal, schedule, index->fixingDays(), index); - floatCpn->setPricer( - ext::shared_ptr(new CompoundingRatePricer)); + floatCpn->setPricer(ext::make_shared()); return floatCpn; } + } ZeroCouponSwap::ZeroCouponSwap(Type type, diff --git a/test-suite/subperiodcoupons.cpp b/test-suite/subperiodcoupons.cpp index 11a8b61c5a..277e7570e4 100644 --- a/test-suite/subperiodcoupons.cpp +++ b/test-suite/subperiodcoupons.cpp @@ -29,7 +29,7 @@ using namespace boost::unit_test_framework; BOOST_FIXTURE_TEST_SUITE(QuantLibTests, TopLevelFixture) -BOOST_AUTO_TEST_SUITE(SubPeriodsCouponTests) +BOOST_AUTO_TEST_SUITE(MultipleResetsCouponTests) struct CommonVars { @@ -78,20 +78,20 @@ struct CommonVars { .withFixingDays(euribor->fixingDays()); } - ext::shared_ptr createSubPeriodsCoupon(const Schedule& schedule, - Spread rateSpread = 0.0, - RateAveraging::Type averaging = RateAveraging::Compound) { + ext::shared_ptr createMultipleResetsCoupon(const Schedule& schedule, + Spread rateSpread = 0.0, + RateAveraging::Type averaging = RateAveraging::Compound) { Calendar paymentCalendar = euribor->fixingCalendar(); BusinessDayConvention paymentBdc = euribor->businessDayConvention(); Date paymentDate = paymentCalendar.advance(schedule.back(), 1 * Days, paymentBdc); Date exCouponDate = paymentCalendar.advance(paymentDate, -2 * Days, paymentBdc); - auto cpn = ext::make_shared( + auto cpn = ext::make_shared( paymentDate, 1.0, schedule, euribor->fixingDays(), euribor, 1.0, 0.0, rateSpread, Date(), Date(), DayCounter(), exCouponDate); if (averaging == RateAveraging::Compound) - cpn->setPricer(ext::make_shared()); + cpn->setPricer(ext::make_shared()); else - cpn->setPricer(ext::make_shared()); + cpn->setPricer(ext::make_shared()); return cpn; } @@ -147,7 +147,7 @@ BOOST_AUTO_TEST_CASE(testRegularCompoundedForwardStartingCouponWithMultipleSubPe Schedule schedule = vars.createSchedule(start, end); Leg iborLeg = vars.createIborLeg(schedule, spread); - auto subPeriodCpn = vars.createSubPeriodsCoupon(schedule, spread, RateAveraging::Compound); + auto subPeriodCpn = vars.createMultipleResetsCoupon(schedule, spread, RateAveraging::Compound); const Real tolerance = 1.0e-14; @@ -183,7 +183,7 @@ BOOST_AUTO_TEST_CASE(testRegularAveragedForwardStartingCouponWithMultipleSubPeri Schedule schedule = vars.createSchedule(start, end); Leg iborLeg = vars.createIborLeg(schedule, spread); - auto subPeriodCpn = vars.createSubPeriodsCoupon(schedule, spread, RateAveraging::Simple); + auto subPeriodCpn = vars.createMultipleResetsCoupon(schedule, spread, RateAveraging::Simple); const Real tolerance = 1.0e-14; @@ -218,10 +218,10 @@ BOOST_AUTO_TEST_CASE(testExCouponCashFlow) { Date paymentDate = paymentCalendar.advance(end, 2 * Days); Date exCouponDate = paymentCalendar.advance(end, -2 * Days); - auto cpn = ext::make_shared( + auto cpn = ext::make_shared( paymentDate, 1.0, schedule, 2, vars.euribor, 1.0, 0.0, 0.0, Date(), Date(), DayCounter(), exCouponDate); - cpn->setPricer(ext::make_shared()); + cpn->setPricer(ext::make_shared()); Real npv = CashFlows::npv({cpn}, **vars.euriborHandle, false, vars.today, vars.today); @@ -347,7 +347,7 @@ BOOST_AUTO_TEST_CASE(testSubPeriodsLegRegression) { .withAveragingMethod(RateAveraging::Compound); for (const auto& cf : leg) { - auto c = ext::dynamic_pointer_cast(cf); + auto c = ext::dynamic_pointer_cast(cf); if (c->fixingDates().size() != 3) BOOST_ERROR("Unexpected number of fixing dates (" << c->fixingDates().size() << ") " "in coupon paying on " << c->date()); diff --git a/test-suite/zerocouponswap.cpp b/test-suite/zerocouponswap.cpp index daef6bcaa7..21dd6854ce 100644 --- a/test-suite/zerocouponswap.cpp +++ b/test-suite/zerocouponswap.cpp @@ -67,15 +67,15 @@ struct CommonVars { ext::shared_ptr(new DiscountingSwapEngine(euriborHandle)); } - ext::shared_ptr createSubPeriodsCoupon(const Date& start, const Date& end) const { + ext::shared_ptr createMultipleResetsCoupon(const Date& start, const Date& end) const { Date paymentDate = calendar.advance(end, paymentDelay * Days, businessConvention); Schedule schedule = MakeSchedule() .from(start).to(end) .withTenor(euribor->tenor()) .withCalendar(euribor->fixingCalendar()); - auto cpn = ext::make_shared( + auto cpn = ext::make_shared( paymentDate, baseNominal, schedule, settlementDays, euribor); - cpn->setPricer(ext::shared_ptr(new CompoundingRatePricer())); + cpn->setPricer(ext::make_shared()); return cpn; } @@ -133,7 +133,7 @@ void checkReplicationOfZeroCouponSwapNPV(const Date& start, paymentDate < vars.settlement ? 0.0 : vars.euriborHandle->discount(paymentDate); Real expectedFixedLegNPV = -type * discountAtPayment * vars.finalPayment; - auto subPeriodCpn = vars.createSubPeriodsCoupon(start, end); + auto subPeriodCpn = vars.createMultipleResetsCoupon(start, end); Real expectedFloatLegNPV = paymentDate < vars.settlement ? 0.0 : Real(Integer(type) * discountAtPayment * subPeriodCpn->amount()); @@ -287,7 +287,7 @@ BOOST_AUTO_TEST_CASE(testExpectedCashFlowsInLegs) { Date paymentDate = vars.calendar.advance(end, vars.paymentDelay * Days, vars.businessConvention); - auto subPeriodCpn = vars.createSubPeriodsCoupon(start, end); + auto subPeriodCpn = vars.createMultipleResetsCoupon(start, end); if ((std::fabs(fixedCashFlow->amount() - zcSwap->fixedPayment()) > tolerance) || (fixedCashFlow->date() != paymentDate))