22#include <ql/cashflows/cashflowvectors.hpp>
23#include <ql/cashflows/cpicoupon.hpp>
24#include <ql/cashflows/cpicouponpricer.hpp>
25#include <ql/cashflows/inflationcoupon.hpp>
26#include <ql/time/daycounters/thirty360.hpp>
32 QL_DEPRECATED_DISABLE_WARNING
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) {
143 QL_REQUIRE(
index_,
"no index provided");
146 "baseCPI and baseDate can not be both null, provide a valid baseCPI or baseDate");
148 "|baseCPI_| < 1e-16, future divide-by-zero problem");
151 QL_DEPRECATED_ENABLE_WARNING
165 auto pricer = ext::dynamic_pointer_cast<CPICouponPricer>(
pricer_);
166 QL_REQUIRE(
pricer,
"pricer not set or of wrong type");
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) {
211 QL_REQUIRE(
index,
"no index provided");
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_(schedule), index_(
std::move(index)), baseCPI_(baseCPI),
264 paymentCalendar_(schedule.calendar()),
316 spreads_ = std::vector<Spread>(1,spread);
326 caps_ = std::vector<Rate>(1,cap);
336 floors_ = std::vector<Rate>(1,floor);
363 CPILeg::operator
Leg()
const {
365 QL_REQUIRE(!notionals_.empty(),
"no notional given");
366 Size n = schedule_.size()-1;
370 Date baseDate = baseDate_;
375 QL_REQUIRE(!fixedRates_.empty() || !spreads_.empty(),
376 "no fixedRates or spreads given");
379 baseDate = schedule_.date(0) - observationLag_;
382 Date refStart, start, refEnd, end;
384 for (
Size i=0; i<n; ++i) {
385 refStart = start = schedule_.date(i);
386 refEnd = end = schedule_.date(i+1);
387 Date paymentDate = paymentCalendar_.adjust(end, paymentAdjustment_);
390 if (exCouponPeriod_ !=
Period())
392 exCouponDate = exCouponCalendar_.
advance(paymentDate,
395 exCouponEndOfMonth_);
398 if (i==0 && schedule_.hasIsRegular() && !schedule_.isRegular(i+1)) {
400 refStart = schedule_.calendar().adjust(end - schedule_.tenor(), bdc);
402 if (i==n-1 && schedule_.hasIsRegular() && !schedule_.isRegular(i+1)) {
404 refEnd = schedule_.calendar().adjust(start + schedule_.tenor(), bdc);
407 leg.push_back(ext::make_shared<FixedRateCoupon>
410 paymentDayCounter_, start, end, refStart, refEnd, exCouponDate));
413 QL_DEPRECATED_DISABLE_WARNING
414 leg.push_back(ext::make_shared<CPICoupon>
420 index_, observationLag_,
421 observationInterpolation_,
425 refStart, refEnd, exCouponDate));
426 QL_DEPRECATED_ENABLE_WARNING
428 QL_FAIL(
"caps/floors on CPI coupons not implemented.");
435 Date paymentDate = paymentCalendar_.adjust(schedule_.date(n), paymentAdjustment_);
436 leg.push_back(ext::make_shared<CPICashFlow>
439 schedule_.date(n), observationLag_, observationInterpolation_,
440 paymentDate, subtractInflationNominal_));
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)
std::vector< Real > fixedRates_
CPILeg(const Schedule &schedule, ext::shared_ptr< ZeroInflationIndex > index, Real baseCPI, const Period &observationLag)
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
BusinessDayConvention
Business Day conventions.
@ NoFrequency
null frequency
Real Spread
spreads on interest rates
std::size_t Size
size of a container
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.
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?