32 const Date& startDate,
35 const ext::shared_ptr<IborIndex>& index,
39 const Date& refPeriodStart,
40 const Date& refPeriodEnd,
42 const Date& exCouponDate)
44 fixingDays, index, gearing, couponSpread,
45 refPeriodStart, refPeriodEnd, dayCounter,
47 rateSpread_(rateSpread) {
64 for (
Size i = 0; i <
n_; ++i)
71 for (
Size i = 0; i <
n_; ++i)
93 ext::shared_ptr<IborIndex> index = ext::dynamic_pointer_cast<IborIndex>(
coupon_->
index());
102 Size n = fixingDates.size();
105 for (
Size i = 0; i <
n; i++) {
111 QL_FAIL(
"SubPeriodsPricer::swapletPrice not implemented");
115 QL_FAIL(
"SubPeriodsPricer::capletPrice not implemented");
119 QL_FAIL(
"SubPeriodsPricer::capletRate not implemented");
123 QL_FAIL(
"SubPeriodsPricer::floorletPrice not implemented");
127 QL_FAIL(
"SubPeriodsPricer::floorletRate not implemented");
134 const std::vector<Time>& subPeriodFractions =
coupon_->
dt();
135 Real aggregateFactor = 0.0;
136 for (
Size i = 0; i < nCount; i++) {
147 Real compoundFactor = 1.0;
148 const std::vector<Time>& subPeriodFractions =
coupon_->
dt();
150 for (
Size i = 0; i < nCount; i++) {
159 : schedule_(
std::move(schedule)), index_(
std::move(i)), paymentCalendar_(schedule_.calendar()) {
204 gearings_ = std::vector<Real>(1, gearing);
249 SubPeriodsLeg::operator
Leg()
const {
251 Calendar calendar = schedule_.calendar();
252 Date refStart, start, refEnd, end, exCouponDate;
255 Size n = schedule_.size() - 1;
256 QL_REQUIRE(!notionals_.empty(),
"no notional given");
258 "too many nominals (" << notionals_.size() <<
"), only " <<
n <<
" required");
260 "too many gearings (" << gearings_.size() <<
"), only " <<
n <<
" required");
262 "too many coupon spreads (" << couponSpreads_.size() <<
"), only " <<
n <<
" required");
264 "too many rate spreads (" << rateSpreads_.size() <<
"), only " <<
n <<
" required");
266 "too many fixing days (" << fixingDays_.size() <<
"), only " <<
n <<
" required");
268 for (
Size i = 0; i <
n; ++i) {
269 refStart = start = schedule_.date(i);
270 refEnd = end = schedule_.date(i + 1);
271 paymentDate = paymentCalendar_.
advance(end, paymentLag_,
Days, paymentAdjustment_);
273 if (i == 0 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1))
274 refStart = calendar.
adjust(end - schedule_.tenor(), paymentAdjustment_);
275 if (i ==
n - 1 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1))
276 refEnd = calendar.
adjust(start + schedule_.tenor(), paymentAdjustment_);
277 if (exCouponPeriod_ !=
Period()) {
278 if (exCouponCalendar_.empty()) {
279 exCouponDate = calendar.
advance(paymentDate, -exCouponPeriod_,
280 exCouponAdjustment_, exCouponEndOfMonth_);
282 exCouponDate = exCouponCalendar_.
advance(
283 paymentDate, -exCouponPeriod_, exCouponAdjustment_, exCouponEndOfMonth_);
287 paymentDate,
detail::get(notionals_, i, notionals_.back()), start, end,
288 detail::get(fixingDays_, i, index_->fixingDays()), index_,
290 detail::get(rateSpreads_, i, 0.0), refStart, refEnd, paymentDayCounter_,
294 switch (averagingMethod_) {
304 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 &)
const std::vector< Date > & dates() const
std::vector< Date > fixingDates_
Spread rateSpread() const
rate spread
void accept(AcyclicVisitor &) override
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())
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 overnight coupons
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_
RateAveraging::Type averagingMethod_
SubPeriodsLeg(Schedule schedule, ext::shared_ptr< IborIndex > index)
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_
Real capletPrice(Rate effectiveCap) const override
Rate floorletRate(Rate effectiveFloor) const override
std::vector< Real > subPeriodFixings_
const SubPeriodsCoupon * coupon_
void initialize(const FloatingRateCoupon &coupon) override
Real floorletPrice(Rate effectiveFloor) const override
Rate swapletPrice() const override
Rate capletRate(Rate effectiveCap) const override
Visitor for a specific class
virtual void visit(T &)=0
#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
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
Interest-rate term structure.