32 const Date& startDate,
35 const ext::shared_ptr<YoYInflationIndex>& yoyIndex,
36 const Period& observationLag,
41 const Date& refPeriodStart,
42 const Date& refPeriodEnd)
44 fixingDays, yoyIndex, observationLag,
45 dayCounter, refPeriodStart, refPeriodEnd),
46 yoyIndex_(yoyIndex), interpolation_(interpolation), gearing_(gearing), spread_(spread) {}
51 const Date& startDate,
54 const ext::shared_ptr<YoYInflationIndex>& yoyIndex,
55 const Period& observationLag,
59 const Date& refPeriodStart,
60 const Date& refPeriodEnd)
62 fixingDays, yoyIndex, observationLag,
CPI::AsIndex,
63 dayCounter, gearing, spread, refPeriodStart, refPeriodEnd) {}
75 const ext::shared_ptr<InflationCouponPricer>&pricer)
const {
76 return static_cast<bool>(
77 ext::dynamic_pointer_cast<YoYInflationCouponPricer>(
pricer));
87 ext::shared_ptr<YoYInflationIndex> index,
88 const Period& observationLag,
90 : schedule_(
std::move(schedule)), index_(
std::move(index)), observationLag_(observationLag),
95 ext::shared_ptr<YoYInflationIndex> index,
96 const Period& observationLag)
131 gearings_ = std::vector<Real>(1,gearing);
141 spreads_ = std::vector<Spread>(1,spread);
151 caps_ = std::vector<Rate>(1,cap);
161 floors_ = std::vector<Rate>(1,floor);
171 yoyInflationLeg::operator
Leg()
const {
173 Size n = schedule_.size()-1;
174 QL_REQUIRE(!paymentDayCounter_.empty(),
"no payment daycounter given");
175 QL_REQUIRE(!notionals_.empty(),
"no notional given");
177 "too many nominals (" << notionals_.size() <<
178 "), only " <<
n <<
" required");
180 "too many gearings (" << gearings_.size() <<
181 "), only " <<
n <<
" required");
183 "too many spreads (" << spreads_.size() <<
184 "), only " <<
n <<
" required");
186 "too many caps (" << caps_.size() <<
187 "), only " <<
n <<
" required");
189 "too many floors (" << floors_.size() <<
190 "), only " <<
n <<
" required");
192 Leg leg; leg.reserve(
n);
196 Date refStart, start, refEnd, end;
198 for (
Size i=0; i<
n; ++i) {
199 refStart = start = schedule_.date(i);
200 refEnd = end = schedule_.date(i+1);
201 Date paymentDate = calendar.
adjust(end, paymentAdjustment_);
202 if (i==0 && schedule_.hasIsRegular() && !schedule_.isRegular(i+1)) {
204 refStart = schedule_.calendar().adjust(end - schedule_.tenor(), bdc);
206 if (i==
n-1 && schedule_.hasIsRegular() && !schedule_.isRegular(i+1)) {
208 refEnd = schedule_.calendar().adjust(start + schedule_.tenor(), bdc);
211 leg.push_back(ext::make_shared<FixedRateCoupon>(
217 start, end, refStart, refEnd));
220 leg.push_back(ext::make_shared<YoYInflationCoupon>(
233 leg.push_back(ext::make_shared<CappedFlooredYoYInflationCoupon>(
253 if (caps_.empty() && floors_.empty())
caplet and floorlet pricing for YoY inflation coupons
Cash flow vector builders.
degenerate base class for the Acyclic Visitor pattern
Date adjust(const Date &, BusinessDayConvention convention=Following) const
const Date & accrualEndDate() const
end of the accrual period
Base inflation-coupon class.
ext::shared_ptr< InflationCouponPricer > pricer() const
void accept(AcyclicVisitor &) override
Period observationLag() const
how the coupon observes the index
template class providing a null value for a given type.
Visitor for a specific class
virtual void visit(T &)=0
Coupon paying a YoY-inflation type index
bool checkPricerImpl(const ext::shared_ptr< InflationCouponPricer > &) const override
makes sure you were given the correct type of pricer
Rate indexFixing() const override
fixing of the underlying index, as observed by the coupon
CPI::InterpolationType interpolation_
void accept(AcyclicVisitor &) override
const ext::shared_ptr< YoYInflationIndex > & yoyIndex() const
YoYInflationCoupon(const Date &paymentDate, Real nominal, const Date &startDate, const Date &endDate, Natural fixingDays, const ext::shared_ptr< YoYInflationIndex > &index, const Period &observationLag, CPI::InterpolationType interpolation, const DayCounter &dayCounter, Real gearing=1.0, Spread spread=0.0, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date())
Helper class building a sequence of capped/floored yoy inflation coupons.
BusinessDayConvention paymentAdjustment_
std::vector< Rate > caps_
yoyInflationLeg & withSpreads(Spread spread)
yoyInflationLeg & withFloors(Rate floor)
yoyInflationLeg & withPaymentAdjustment(BusinessDayConvention)
yoyInflationLeg & withNotionals(Real notional)
yoyInflationLeg & withGearings(Real gearing)
std::vector< Real > notionals_
std::vector< Spread > spreads_
yoyInflationLeg & withPaymentDayCounter(const DayCounter &)
std::vector< Natural > fixingDays_
yoyInflationLeg & withCaps(Rate cap)
std::vector< Rate > floors_
yoyInflationLeg(Schedule schedule, Calendar cal, ext::shared_ptr< YoYInflationIndex > index, const Period &observationLag, CPI::InterpolationType interpolation)
yoyInflationLeg & withFixingDays(Natural fixingDays)
std::vector< Real > gearings_
DayCounter paymentDayCounter_
Calendar paymentCalendar_
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
BusinessDayConvention
Business Day conventions.
unsigned QL_INTEGER Natural
positive integer
Real Spread
spreads on interest rates
std::size_t Size
size of a container
Coupon paying a variable index-based rate.
T get(const std::vector< T > &v, Size i, U defaultValue)
Rate effectiveFixedRate(const std::vector< Spread > &spreads, const std::vector< Rate > &caps, const std::vector< Rate > &floors, Size i)
bool noOption(const std::vector< Rate > &caps, const std::vector< Rate > &floors, Size i)
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
static Real laggedYoYRate(const ext::shared_ptr< YoYInflationIndex > &index, const Date &date, const Period &observationLag, InterpolationType interpolationType)
interpolated year-on-year inflation rate
InterpolationType
when you observe an index, how do you interpolate between fixings?