33 const Date& paymentDate,
35 const Date& startDate,
37 const ext::shared_ptr<ZeroInflationIndex>& index,
38 const Period& observationLag,
42 const Date& refPeriodStart,
43 const Date& refPeriodEnd,
44 const Date& exCouponDate)
45 :
CPICoupon(baseCPI,
Date(), paymentDate, nominal, startDate, endDate,
46 index, observationLag, observationInterpolation, dayCounter,
47 fixedRate, refPeriodStart, refPeriodEnd, exCouponDate) {}
50 const Date& paymentDate,
52 const Date& startDate,
54 const ext::shared_ptr<ZeroInflationIndex>& index,
55 const Period& observationLag,
59 const Date& refPeriodStart,
60 const Date& refPeriodEnd,
61 const Date& exCouponDate)
63 index, observationLag, observationInterpolation, dayCounter,
64 fixedRate, refPeriodStart, refPeriodEnd, exCouponDate) {}
68 const Date& paymentDate,
70 const Date& startDate,
72 const ext::shared_ptr<ZeroInflationIndex>& index,
73 const Period& observationLag,
77 const Date& refPeriodStart,
78 const Date& refPeriodEnd,
79 const Date& exCouponDate)
81 index, observationLag, dayCounter,
82 refPeriodStart, refPeriodEnd, exCouponDate),
83 baseCPI_(baseCPI), fixedRate_(fixedRate),
84 observationInterpolation_(observationInterpolation), baseDate_(baseDate) {
88 "baseCPI and baseDate can not be both null, provide a valid baseCPI or baseDate");
90 "|baseCPI_| < 1e-16, future divide-by-zero problem");
105 auto pricer = ext::dynamic_pointer_cast<CPICouponPricer>(
pricer_);
107 pricer->initialize(*
this);
132 const ext::shared_ptr<InflationCouponPricer>&pricer)
const {
133 return static_cast<bool>(
134 ext::dynamic_pointer_cast<CPICouponPricer>(
pricer));
140 const ext::shared_ptr<ZeroInflationIndex>& index,
141 const Date& baseDate,
143 const Date& observationDate,
144 const Period& observationLag,
146 const Date& paymentDate,
148 :
IndexedCashFlow(notional, index, baseDate, observationDate - observationLag, paymentDate, growthOnly),
149 baseFixing_(baseFixing), observationDate_(observationDate), observationLag_(observationLag),
150 interpolation_(interpolation), frequency_(index ? index->frequency() :
NoFrequency) {
154 "baseCPI and baseDate can not be both null, provide a valid baseCPI or baseDate");
156 "|baseCPI_| < 1e-16, future divide-by-zero problem");
161 if (base !=
Date()) {
164 QL_FAIL(
"no base date specified");
180 ext::shared_ptr<ZeroInflationIndex> index,
182 const Period& observationLag)
183 : schedule_(
std::move(schedule)), index_(
std::move(index)), baseCPI_(baseCPI),
235 caps_ = std::vector<Rate>(1,cap);
245 floors_ = std::vector<Rate>(1,floor);
272 CPILeg::operator
Leg()
const {
274 QL_REQUIRE(!notionals_.empty(),
"no notional given");
275 Size n = schedule_.size()-1;
279 Date baseDate = baseDate_;
284 QL_REQUIRE(!fixedRates_.empty(),
"no fixedRates given");
287 baseDate = schedule_.date(0) - observationLag_;
290 Date refStart, start, refEnd, end;
292 for (
Size i=0; i<
n; ++i) {
293 refStart = start = schedule_.date(i);
294 refEnd = end = schedule_.date(i+1);
298 if (exCouponPeriod_ !=
Period())
300 exCouponDate = exCouponCalendar_.
advance(paymentDate,
303 exCouponEndOfMonth_);
306 if (i==0 && schedule_.hasIsRegular() && !schedule_.isRegular(i+1)) {
308 refStart = schedule_.calendar().adjust(end - schedule_.tenor(), bdc);
310 if (i==
n-1 && schedule_.hasIsRegular() && !schedule_.isRegular(i+1)) {
312 refEnd = schedule_.calendar().adjust(start + schedule_.tenor(), bdc);
316 leg.push_back(ext::make_shared<FixedRateCoupon>
319 paymentDayCounter_, start, end, refStart, refEnd, exCouponDate));
322 leg.push_back(ext::make_shared<CPICoupon>
328 index_, observationLag_,
329 observationInterpolation_,
332 refStart, refEnd, exCouponDate));
334 QL_FAIL(
"caps/floors on CPI coupons not implemented.");
342 leg.push_back(ext::make_shared<CPICashFlow>
345 schedule_.date(
n), observationLag_, observationInterpolation_,
346 paymentDate, subtractInflationNominal_));
Cash flow vector builders.
degenerate base class for the Acyclic Visitor pattern
CPICashFlow(Real notional, const ext::shared_ptr< ZeroInflationIndex > &index, const Date &baseDate, Real baseFixing, const Date &observationDate, const Period &observationLag, CPI::InterpolationType interpolation, const Date &paymentDate, bool growthOnly=false)
ext::shared_ptr< ZeroInflationIndex > cpiIndex() const
CPI::InterpolationType interpolation_
Date baseDate() const override
you may not have a valid date
Real baseFixing() const override
value used on base date
Real indexFixing() const override
Coupon paying the performance of a CPI (zero inflation) index
bool checkPricerImpl(const ext::shared_ptr< InflationCouponPricer > &) const override
makes sure you were given the correct type of pricer
CPICoupon(Real baseCPI, const Date &paymentDate, Real nominal, const Date &startDate, const Date &endDate, const ext::shared_ptr< ZeroInflationIndex > &index, const Period &observationLag, CPI::InterpolationType observationInterpolation, const DayCounter &dayCounter, Real fixedRate, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date(), const Date &exCouponDate=Date())
Rate baseCPI() const
base value for the CPI index
ext::shared_ptr< ZeroInflationIndex > cpiIndex() const
index used
CPI::InterpolationType observationInterpolation() const
how do you observe the index? as-is, flat, linear?
void accept(AcyclicVisitor &) override
Rate indexRatio(Date d) const
the ratio between the index fixing at the passed date and the base CPI
Date baseDate() const
base date for the base fixing of the CPI index
Real accruedAmount(const Date &) const override
accrued amount at the given date
Helper class building a sequence of capped/floored CPI coupons.
CPILeg & withNotionals(Real notional)
BusinessDayConvention paymentAdjustment_
std::vector< Rate > caps_
CPILeg & withPaymentAdjustment(BusinessDayConvention)
BusinessDayConvention exCouponAdjustment_
CPILeg & withSubtractInflationNominal(bool)
Calendar paymentCalendar_
CPILeg & withBaseDate(const Date &baseDate)
CPILeg & withFixedRates(Real fixedRate)
CPILeg & withExCouponPeriod(const Period &, const Calendar &, BusinessDayConvention, bool endOfMonth=false)
std::vector< Real > notionals_
CPILeg & withCaps(Rate cap)
CPILeg & withPaymentDayCounter(const DayCounter &)
CPILeg & withPaymentCalendar(const Calendar &)
CPILeg & withFloors(Rate floor)
CPILeg(Schedule schedule, ext::shared_ptr< ZeroInflationIndex > index, Real baseCPI, const Period &observationLag)
std::vector< Real > fixedRates_
CPI::InterpolationType observationInterpolation_
Calendar exCouponCalendar_
std::vector< Rate > floors_
bool subtractInflationNominal_
CPILeg & withObservationInterpolation(CPI::InterpolationType)
DayCounter paymentDayCounter_
Date adjust(const Date &, BusinessDayConvention convention=Following) const
virtual Real nominal() const
Time accruedPeriod(const Date &) const
accrued period as fraction of year at the given date
static Date advance(const Date &d, Integer units, TimeUnit)
Cash flow dependent on an index ratio.
virtual Date baseDate() const
virtual ext::shared_ptr< Index > index() const
Base inflation-coupon class.
ext::shared_ptr< InflationCouponPricer > pricer_
ext::shared_ptr< InflationIndex > index_
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.
30/360 day count convention
Visitor for a specific class
virtual void visit(T &)=0
Coupon paying a zero-inflation index.
zero inflation-coupon pricer
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.
@ NoFrequency
null frequency
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 laggedFixing(const ext::shared_ptr< ZeroInflationIndex > &index, const Date &date, const Period &observationLag, InterpolationType interpolationType)
interpolated inflation fixing
InterpolationType
when you observe an index, how do you interpolate between fixings?