34 const ext::shared_ptr<IborIndex>& index,
38 const Date& refPeriodStart,
39 const Date& refPeriodEnd,
41 const Date& exCouponDate)
43 resetSchedule.front(), resetSchedule.back(),
44 fixingDays, index, gearing, couponSpread,
45 refPeriodStart, refPeriodEnd, dayCounter,
47 rateSpread_(rateSpread) {
56 for (
Size i = 0; i <
n_; ++i)
63 for (
Size i = 0; i <
n_; ++i)
69 const Date& startDate,
72 const ext::shared_ptr<IborIndex>& index,
76 const Date& refPeriodStart,
77 const Date& refPeriodEnd,
79 const Date& exCouponDate)
81 fixingDays, index, gearing, couponSpread,
82 refPeriodStart, refPeriodEnd, dayCounter,
84 rateSpread_(rateSpread) {
101 for (
Size i = 0; i <
n_; ++i)
108 for (
Size i = 0; i <
n_; ++i)
130 ext::shared_ptr<IborIndex> index = ext::dynamic_pointer_cast<IborIndex>(
coupon_->
index());
139 Size n = fixingDates.size();
142 for (
Size i = 0; i <
n; i++) {
148 QL_FAIL(
"MultipleResetsPricer::swapletPrice not implemented");
152 QL_FAIL(
"MultipleResetsPricer::capletPrice not implemented");
156 QL_FAIL(
"MultipleResetsPricer::capletRate not implemented");
160 QL_FAIL(
"MultipleResetsPricer::floorletPrice not implemented");
164 QL_FAIL(
"MultipleResetsPricer::floorletRate not implemented");
171 const std::vector<Time>& subPeriodFractions =
coupon_->
dt();
172 Real aggregateFactor = 0.0;
173 for (
Size i = 0; i < nCount; i++) {
184 Real compoundFactor = 1.0;
185 const std::vector<Time>& subPeriodFractions =
coupon_->
dt();
187 for (
Size i = 0; i < nCount; i++) {
198 ext::shared_ptr<IborIndex> index,
199 Size resetsPerCoupon)
200 : schedule_(
std::move(schedule)), index_(
std::move(index)), resetsPerCoupon_(resetsPerCoupon),
205 "number of resets per coupon does not divide exactly number of periods in schedule");
249 gearings_ = std::vector<Real>(1, gearing);
294 MultipleResetsLeg::operator
Leg()
const {
296 Calendar calendar = schedule_.calendar();
298 Size n = (schedule_.size() - 1) / resetsPerCoupon_;
299 QL_REQUIRE(!notionals_.empty(),
"no notional given");
301 "too many nominals (" << notionals_.size() <<
"), only " <<
n <<
" required");
303 "too many gearings (" << gearings_.size() <<
"), only " <<
n <<
" required");
305 "too many coupon spreads (" << couponSpreads_.size() <<
"), only " <<
n <<
" required");
307 "too many rate spreads (" << rateSpreads_.size() <<
"), only " <<
n <<
" required");
309 "too many fixing days (" << fixingDays_.size() <<
"), only " <<
n <<
" required");
311 for (
Size i = 0; i <
n; ++i) {
312 Date start = schedule_.date(i * resetsPerCoupon_);
313 Date end = schedule_.date((i + 1) * resetsPerCoupon_);
314 auto subSchedule = schedule_.after(start).until(end);
317 if (exCouponPeriod_ !=
Period()) {
318 if (exCouponCalendar_.empty()) {
319 exCouponDate = calendar.
advance(paymentDate, -exCouponPeriod_,
320 exCouponAdjustment_, exCouponEndOfMonth_);
322 exCouponDate = exCouponCalendar_.
advance(
323 paymentDate, -exCouponPeriod_, exCouponAdjustment_, exCouponEndOfMonth_);
327 cashflows.push_back(ext::make_shared<MultipleResetsCoupon>(
328 paymentDate,
detail::get(notionals_, i, notionals_.back()), subSchedule,
329 detail::get(fixingDays_, i, index_->fixingDays()), index_,
331 detail::get(rateSpreads_, i, 0.0), start, end, paymentDayCounter_,
335 switch (averagingMethod_) {
337 setCouponPricer(cashflows, ext::make_shared<AveragingMultipleResetsPricer>());
340 setCouponPricer(cashflows, ext::make_shared<CompoundingMultipleResetsPricer>());
343 QL_FAIL(
"unknown compounding convention (" <<
Integer(averagingMethod_) <<
")");
397 gearings_ = std::vector<Real>(1, gearing);
442 SubPeriodsLeg::operator
Leg()
const {
444 Calendar calendar = schedule_.calendar();
445 Date refStart, start, refEnd, end, exCouponDate;
448 Size n = schedule_.size() - 1;
449 QL_REQUIRE(!notionals_.empty(),
"no notional given");
451 "too many nominals (" << notionals_.size() <<
"), only " <<
n <<
" required");
453 "too many gearings (" << gearings_.size() <<
"), only " <<
n <<
" required");
455 "too many coupon spreads (" << couponSpreads_.size() <<
"), only " <<
n <<
" required");
457 "too many rate spreads (" << rateSpreads_.size() <<
"), only " <<
n <<
" required");
459 "too many fixing days (" << fixingDays_.size() <<
"), only " <<
n <<
" required");
461 for (
Size i = 0; i <
n; ++i) {
462 refStart = start = schedule_.date(i);
463 refEnd = end = schedule_.date(i + 1);
466 if (i == 0 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1))
467 refStart = calendar.
adjust(end - schedule_.tenor(), paymentAdjustment_);
468 if (i ==
n - 1 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1))
469 refEnd = calendar.
adjust(start + schedule_.tenor(), paymentAdjustment_);
470 if (exCouponPeriod_ !=
Period()) {
471 if (exCouponCalendar_.empty()) {
472 exCouponDate = calendar.
advance(paymentDate, -exCouponPeriod_,
473 exCouponAdjustment_, exCouponEndOfMonth_);
475 exCouponDate = exCouponCalendar_.
advance(
476 paymentDate, -exCouponPeriod_, exCouponAdjustment_, exCouponEndOfMonth_);
480 paymentDate,
detail::get(notionals_, i, notionals_.back()), start, end,
481 detail::get(fixingDays_, i, index_->fixingDays()), index_,
483 detail::get(rateSpreads_, i, 0.0), refStart, refEnd, paymentDayCounter_,
487 switch (averagingMethod_) {
489 setCouponPricer(cashflows, ext::make_shared<AveragingMultipleResetsPricer>());
492 setCouponPricer(cashflows, ext::make_shared<CompoundingMultipleResetsPricer>());
495 QL_FAIL(
"unknown compounding convention (" <<
Integer(averagingMethod_) <<
")");
Cash flow vector builders.
degenerate base class for the Acyclic Visitor pattern
Real swapletRate() const override
Date adjust(const Date &, BusinessDayConvention convention=Following) const
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
Real swapletRate() const override
Time accrualPeriod() const
accrual period as fraction of year
static Date advance(const Date &d, Integer units, TimeUnit)
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
base floating-rate coupon class
ext::shared_ptr< InterestRateIndex > index_
void accept(AcyclicVisitor &) override
Real gearing() const
index gearing, i.e. multiplicative coefficient for the index
const ext::shared_ptr< InterestRateIndex > & index() const
floating index
Spread spread() const
spread paid over the fixing of the underlying index
MakeSchedule & withConvention(BusinessDayConvention)
MakeSchedule & backwards()
MakeSchedule & to(const Date &terminationDate)
MakeSchedule & withTenor(const Period &)
MakeSchedule & from(const Date &effectiveDate)
MakeSchedule & endOfMonth(bool flag=true)
MakeSchedule & withCalendar(const Calendar &)
std::vector< Date > fixingDates_
Spread rateSpread() const
rate spread
void accept(AcyclicVisitor &) override
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())
std::vector< Date > valueDates_
const std::vector< Time > & dt() const
accrual (compounding) periods
const std::vector< Date > & fixingDates() const
fixing dates for the rates to be compounded
Date fixingDate() const override
the date when the coupon is fully determined
helper class building a sequence of multiple-reset coupons
BusinessDayConvention paymentAdjustment_
MultipleResetsLeg & withPaymentLag(Integer lag)
BusinessDayConvention exCouponAdjustment_
std::vector< Spread > couponSpreads_
Calendar paymentCalendar_
MultipleResetsLeg & withPaymentCalendar(const Calendar &)
MultipleResetsLeg & withExCouponPeriod(const Period &, const Calendar &, BusinessDayConvention, bool endOfMonth=false)
MultipleResetsLeg(Schedule fullResetSchedule, ext::shared_ptr< IborIndex > index, Size resetsPerCoupon)
std::vector< Real > notionals_
MultipleResetsLeg & withNotionals(Real notional)
MultipleResetsLeg & withPaymentDayCounter(const DayCounter &)
RateAveraging::Type averagingMethod_
MultipleResetsLeg & withAveragingMethod(RateAveraging::Type averagingMethod)
MultipleResetsLeg & withCouponSpreads(Spread spread)
std::vector< Natural > fixingDays_
MultipleResetsLeg & withGearings(Real gearing)
Calendar exCouponCalendar_
std::vector< Spread > rateSpreads_
MultipleResetsLeg & withFixingDays(Natural fixingDays)
MultipleResetsLeg & withRateSpreads(Spread spread)
MultipleResetsLeg & withPaymentAdjustment(BusinessDayConvention)
std::vector< Real > gearings_
DayCounter paymentDayCounter_
ext::shared_ptr< IborIndex > index_
Real capletPrice(Rate effectiveCap) const override
Rate floorletRate(Rate effectiveFloor) const override
std::vector< Real > subPeriodFixings_
void initialize(const FloatingRateCoupon &coupon) override
const MultipleResetsCoupon * coupon_
Real floorletPrice(Rate effectiveFloor) const override
Rate swapletPrice() const override
Rate capletRate(Rate effectiveCap) const override
const std::vector< Date > & dates() const
SubPeriodsLeg & withAveragingMethod(RateAveraging::Type averagingMethod)
SubPeriodsLeg & withExCouponPeriod(const Period &, const Calendar &, BusinessDayConvention, bool endOfMonth=false)
BusinessDayConvention paymentAdjustment_
BusinessDayConvention exCouponAdjustment_
std::vector< Spread > couponSpreads_
Calendar paymentCalendar_
SubPeriodsLeg & withPaymentLag(Integer lag)
SubPeriodsLeg & withNotionals(Real notional)
std::vector< Real > notionals_
SubPeriodsLeg(Schedule schedule, ext::shared_ptr< IborIndex > index)
RateAveraging::Type averagingMethod_
SubPeriodsLeg & withRateSpreads(Spread spread)
std::vector< Natural > fixingDays_
Calendar exCouponCalendar_
std::vector< Spread > rateSpreads_
SubPeriodsLeg & withCouponSpreads(Spread spread)
SubPeriodsLeg & withGearings(Real gearing)
SubPeriodsLeg & withFixingDays(Natural fixingDays)
SubPeriodsLeg & withPaymentAdjustment(BusinessDayConvention)
SubPeriodsLeg & withPaymentDayCounter(const DayCounter &)
std::vector< Real > gearings_
SubPeriodsLeg & withPaymentCalendar(const Calendar &)
DayCounter paymentDayCounter_
ext::shared_ptr< IborIndex > index_
Visitor for a specific class
virtual void visit(T &)=0
Calendar paymentCalendar_
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
BusinessDayConvention
Business Day conventions.
unsigned QL_INTEGER Natural
positive integer
QL_INTEGER Integer
integer number
Real Spread
spreads on interest rates
std::size_t Size
size of a container
base class for Inter-Bank-Offered-Rate indexes
Coupon compounding or averaging multiple fixings.
T get(const std::vector< T > &v, Size i, U defaultValue)
void setCouponPricer(const Leg &leg, const ext::shared_ptr< FloatingRateCouponPricer > &pricer)
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
ext::shared_ptr< BlackVolTermStructure > v
#define QL_DEPRECATED_DISABLE_WARNING
#define QL_DEPRECATED_ENABLE_WARNING
Interest-rate term structure.