35 const Date& paymentDate,
37 const Date& startDate,
39 const ext::shared_ptr<ZeroInflationIndex>& index,
40 const Period& observationLag,
44 const Date& refPeriodStart,
45 const Date& refPeriodEnd,
46 const Date& exCouponDate)
47 :
CPICoupon(baseCPI, paymentDate, nominal, startDate, endDate, index,
48 observationLag, observationInterpolation, dayCounter,
49 fixedRate, 0.0, refPeriodStart, refPeriodEnd, exCouponDate) {}
52 const Date& paymentDate,
54 const Date& startDate,
56 const ext::shared_ptr<ZeroInflationIndex>& index,
57 const Period& observationLag,
61 const Date& refPeriodStart,
62 const Date& refPeriodEnd,
63 const Date& exCouponDate)
64 :
CPICoupon(baseDate, paymentDate, nominal, startDate, endDate, index,
65 observationLag, observationInterpolation, dayCounter,
66 fixedRate, 0.0, refPeriodStart, refPeriodEnd, exCouponDate) {}
70 const Date& paymentDate,
72 const Date& startDate,
74 const ext::shared_ptr<ZeroInflationIndex>& index,
75 const Period& observationLag,
79 const Date& refPeriodStart,
80 const Date& refPeriodEnd,
81 const Date& exCouponDate)
82 :
CPICoupon(baseCPI, baseDate, paymentDate, nominal, startDate, endDate, index,
83 observationLag, observationInterpolation, dayCounter,
84 fixedRate, 0.0, refPeriodStart, refPeriodEnd, exCouponDate) {}
87 const Date& paymentDate,
89 const Date& startDate,
91 const ext::shared_ptr<ZeroInflationIndex>& index,
92 const Period& observationLag,
97 const Date& refPeriodStart,
98 const Date& refPeriodEnd,
99 const Date& exCouponDate)
100 :
CPICoupon(baseCPI,
Null<
Date>(), paymentDate, nominal, startDate, endDate, index,
101 observationLag, observationInterpolation, dayCounter,
102 fixedRate, spread, refPeriodStart, refPeriodEnd, exCouponDate) {}
105 const Date& paymentDate,
107 const Date& startDate,
109 const ext::shared_ptr<ZeroInflationIndex>& index,
110 const Period& observationLag,
115 const Date& refPeriodStart,
116 const Date& refPeriodEnd,
117 const Date& exCouponDate)
118 :
CPICoupon(
Null<
Real>(), baseDate, paymentDate, nominal, startDate, endDate, index,
119 observationLag, observationInterpolation, dayCounter,
120 fixedRate, spread, refPeriodStart, refPeriodEnd, exCouponDate) {}
123 const Date& baseDate,
124 const Date& paymentDate,
126 const Date& startDate,
128 const ext::shared_ptr<ZeroInflationIndex>& index,
129 const Period& observationLag,
134 const Date& refPeriodStart,
135 const Date& refPeriodEnd,
136 const Date& exCouponDate)
138 index, observationLag, dayCounter,
139 refPeriodStart, refPeriodEnd, exCouponDate),
140 baseCPI_(baseCPI), fixedRate_(fixedRate), spread_(spread),
141 observationInterpolation_(observationInterpolation), baseDate_(baseDate) {
146 "baseCPI and baseDate can not be both null, provide a valid baseCPI or baseDate");
148 "|baseCPI_| < 1e-16, future divide-by-zero problem");
165 auto pricer = ext::dynamic_pointer_cast<CPICouponPricer>(
pricer_);
167 pricer->initialize(*
this);
192 const ext::shared_ptr<InflationCouponPricer>&pricer)
const {
193 return static_cast<bool>(
194 ext::dynamic_pointer_cast<CPICouponPricer>(
pricer));
200 const ext::shared_ptr<ZeroInflationIndex>& index,
201 const Date& baseDate,
203 const Date& observationDate,
204 const Period& observationLag,
206 const Date& paymentDate,
208 :
IndexedCashFlow(notional, index, baseDate, observationDate - observationLag, paymentDate, growthOnly),
209 baseFixing_(baseFixing), observationDate_(observationDate), observationLag_(observationLag),
210 interpolation_(interpolation), frequency_(index ? index->frequency() :
NoFrequency) {
214 "baseCPI and baseDate can not be both null, provide a valid baseCPI or baseDate");
216 "|baseCPI_| < 1e-16, future divide-by-zero problem");
221 if (base !=
Date()) {
224 QL_FAIL(
"no base date specified");
253 return notional() * (I1 / I0 - 1.0);
259 ext::shared_ptr<ZeroInflationIndex> index,
261 const Period& observationLag)
262 : schedule_(
std::move(schedule)), index_(
std::move(index)), baseCPI_(baseCPI),
264 paymentCalendar_(schedule_.calendar()),
315 spreads_ = std::vector<Spread>(1,spread);
325 caps_ = std::vector<Rate>(1,cap);
335 floors_ = std::vector<Rate>(1,floor);
362 CPILeg::operator
Leg()
const {
364 QL_REQUIRE(!notionals_.empty(),
"no notional given");
365 Size n = schedule_.size()-1;
369 Date baseDate = baseDate_;
374 QL_REQUIRE(!fixedRates_.empty() || !spreads_.empty(),
375 "no fixedRates or spreads given");
378 baseDate = schedule_.date(0) - observationLag_;
381 Date refStart, start, refEnd, end;
383 for (
Size i=0; i<
n; ++i) {
384 refStart = start = schedule_.date(i);
385 refEnd = end = schedule_.date(i+1);
386 Date paymentDate = paymentCalendar_.adjust(end, paymentAdjustment_);
389 if (exCouponPeriod_ !=
Period())
391 exCouponDate = exCouponCalendar_.
advance(paymentDate,
394 exCouponEndOfMonth_);
397 if (i==0 && schedule_.hasIsRegular() && !schedule_.isRegular(i+1)) {
399 refStart = schedule_.calendar().adjust(end - schedule_.tenor(), bdc);
401 if (i==
n-1 && schedule_.hasIsRegular() && !schedule_.isRegular(i+1)) {
403 refEnd = schedule_.calendar().adjust(start + schedule_.tenor(), bdc);
406 leg.push_back(ext::make_shared<FixedRateCoupon>
409 paymentDayCounter_, start, end, refStart, refEnd, exCouponDate));
413 leg.push_back(ext::make_shared<CPICoupon>
419 index_, observationLag_,
420 observationInterpolation_,
424 refStart, refEnd, exCouponDate));
427 QL_FAIL(
"caps/floors on CPI coupons not implemented.");
434 Date paymentDate = paymentCalendar_.adjust(schedule_.date(
n), paymentAdjustment_);
435 leg.push_back(ext::make_shared<CPICashFlow>
438 schedule_.date(
n), observationLag_, observationInterpolation_,
439 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 amount() const override
returns the amount of the cash flow
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
void accept(AcyclicVisitor &) override
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?
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 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_
std::vector< Spread > spreads_
CPILeg & withCaps(Rate cap)
CPILeg & withPaymentDayCounter(const DayCounter &)
CPILeg & withPaymentCalendar(const Calendar &)
CPILeg & withSpreads(Spread spread)
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_
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 fixingDate() const
virtual Real notional() const
virtual Real baseFixing() const
virtual Date baseDate() const
virtual bool growthOnly() 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
#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
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
#define QL_DEPRECATED_DISABLE_WARNING
#define QL_DEPRECATED_ENABLE_WARNING
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?