Skip to content

Commit

Permalink
Renamed classes
Browse files Browse the repository at this point in the history
  • Loading branch information
lballabio committed Oct 15, 2024
1 parent 003e743 commit af7a595
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 114 deletions.
15 changes: 7 additions & 8 deletions ql/cashflows/couponpricer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ namespace QuantLib {
public Visitor<DigitalCmsCoupon>,
public Visitor<DigitalCmsSpreadCoupon>,
public Visitor<RangeAccrualFloatersCoupon>,
public Visitor<SubPeriodsCoupon> {
public Visitor<MultipleResetsCoupon> {
private:
ext::shared_ptr<FloatingRateCouponPricer> pricer_;
public:
Expand All @@ -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&) {
Expand Down Expand Up @@ -386,12 +386,11 @@ namespace QuantLib {
c.setPricer(rangeAccrualPricer);
}

void PricerSetter::visit(SubPeriodsCoupon& c) {
const ext::shared_ptr<SubPeriodsPricer> subPeriodsPricer =
ext::dynamic_pointer_cast<SubPeriodsPricer>(pricer_);
QL_REQUIRE(subPeriodsPricer,
"pricer not compatible with sub-period coupon");
c.setPricer(subPeriodsPricer);
void PricerSetter::visit(MultipleResetsCoupon& c) {
const ext::shared_ptr<MultipleResetsPricer> pricer =
ext::dynamic_pointer_cast<MultipleResetsPricer>(pricer_);
QL_REQUIRE(pricer, "pricer not compatible with multiple-resets coupon");
c.setPricer(pricer);
}

void setCouponPricersFirstMatching(const Leg& leg,
Expand Down
110 changes: 54 additions & 56 deletions ql/cashflows/subperiodcoupon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@

namespace QuantLib {

SubPeriodsCoupon::SubPeriodsCoupon(const Date& paymentDate,
Real nominal,
const Schedule& resetSchedule,
Natural fixingDays,
const ext::shared_ptr<IborIndex>& 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<IborIndex>& 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,
Expand All @@ -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<IborIndex>& 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<IborIndex>& 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,
Expand Down Expand Up @@ -109,22 +109,22 @@ namespace QuantLib {
dt_[i] = dc.yearFraction(valueDates_[i], valueDates_[i + 1]);
}

void SubPeriodsCoupon::accept(AcyclicVisitor& v) {
auto* v1 = dynamic_cast<Visitor<SubPeriodsCoupon>*>(&v);
void MultipleResetsCoupon::accept(AcyclicVisitor& v) {
auto* v1 = dynamic_cast<Visitor<MultipleResetsCoupon>*>(&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<Integer>(fixingDays_), Days);
return fixingDate;
}

void SubPeriodsPricer::initialize(const FloatingRateCoupon& coupon) {
coupon_ = dynamic_cast<const SubPeriodsCoupon*>(&coupon);
void MultipleResetsPricer::initialize(const FloatingRateCoupon& coupon) {
coupon_ = dynamic_cast<const MultipleResetsCoupon*>(&coupon);
QL_REQUIRE(coupon_, "sub-periods coupon required");

ext::shared_ptr<IborIndex> index = ext::dynamic_pointer_cast<IborIndex>(coupon_->index());
Expand All @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -324,7 +324,7 @@ namespace QuantLib {
}
}

cashflows.push_back(ext::make_shared<SubPeriodsCoupon>(
cashflows.push_back(ext::make_shared<MultipleResetsCoupon>(
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),
Expand All @@ -334,10 +334,10 @@ namespace QuantLib {

switch (averagingMethod_) {
case RateAveraging::Simple:
setCouponPricer(cashflows, ext::make_shared<AveragingRatePricer>());
setCouponPricer(cashflows, ext::make_shared<AveragingMultipleResetsPricer>());
break;
case RateAveraging::Compound:
setCouponPricer(cashflows, ext::make_shared<CompoundingRatePricer>());
setCouponPricer(cashflows, ext::make_shared<CompoundingMultipleResetsPricer>());
break;
default:
QL_FAIL("unknown compounding convention (" << Integer(averagingMethod_) << ")");
Expand Down Expand Up @@ -476,7 +476,7 @@ namespace QuantLib {
paymentDate, -exCouponPeriod_, exCouponAdjustment_, exCouponEndOfMonth_);
}
}
cashflows.push_back(ext::shared_ptr<CashFlow>(new SubPeriodsCoupon(
cashflows.push_back(ext::shared_ptr<CashFlow>(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),
Expand All @@ -485,16 +485,14 @@ namespace QuantLib {
}

switch (averagingMethod_) {
case RateAveraging::Simple:
setCouponPricer(cashflows,
ext::shared_ptr<FloatingRateCouponPricer>(new AveragingRatePricer));
break;
case RateAveraging::Compound:
setCouponPricer(cashflows, ext::shared_ptr<FloatingRateCouponPricer>(
new CompoundingRatePricer));
break;
default:
QL_FAIL("unknown compounding convention (" << Integer(averagingMethod_) << ")");
case RateAveraging::Simple:
setCouponPricer(cashflows, ext::make_shared<AveragingMultipleResetsPricer>());
break;
case RateAveraging::Compound:
setCouponPricer(cashflows, ext::make_shared<CompoundingMultipleResetsPricer>());
break;
default:
QL_FAIL("unknown compounding convention (" << Integer(averagingMethod_) << ")");
}
return cashflows;
}
Expand Down
85 changes: 55 additions & 30 deletions ql/cashflows/subperiodcoupon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<IborIndex>& 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<IborIndex>& 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<IborIndex>& 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<IborIndex>& 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
//@{
Expand Down Expand Up @@ -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;
Expand All @@ -121,20 +128,38 @@ namespace QuantLib {
void initialize(const FloatingRateCoupon& coupon) override;

protected:
const SubPeriodsCoupon* coupon_;
const MultipleResetsCoupon* coupon_;
std::vector<Real> 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 {
Expand Down
7 changes: 4 additions & 3 deletions ql/instruments/zerocouponswap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace QuantLib {

namespace {

ext::shared_ptr<CashFlow>
compoundedSubPeriodicCoupon(const Date& paymentDate,
const Date& startDate,
Expand All @@ -41,12 +42,12 @@ namespace QuantLib {
.withConvention(index->businessDayConvention())
.backwards()
.endOfMonth(index->endOfMonth());
auto floatCpn = ext::make_shared<SubPeriodsCoupon>(
auto floatCpn = ext::make_shared<MultipleResetsCoupon>(
paymentDate, nominal, schedule, index->fixingDays(), index);
floatCpn->setPricer(
ext::shared_ptr<FloatingRateCouponPricer>(new CompoundingRatePricer));
floatCpn->setPricer(ext::make_shared<CompoundingMultipleResetsPricer>());
return floatCpn;
}

}

ZeroCouponSwap::ZeroCouponSwap(Type type,
Expand Down
Loading

0 comments on commit af7a595

Please sign in to comment.