Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
CPILeg Class Reference

Helper class building a sequence of capped/floored CPI coupons. More...

#include <qle/cashflows/cpicoupon.hpp>

+ Collaboration diagram for CPILeg:

Public Member Functions

 CPILeg (const Schedule &schedule, const ext::shared_ptr< ZeroInflationIndex > &index, const Handle< YieldTermStructure > &rateCurve, const Real baseCPI, const Period &observationLag)
 
CPILegwithNotionals (Real notional)
 
CPILegwithNotionals (const std::vector< Real > &notionals)
 
CPILegwithFixedRates (Real fixedRate)
 
CPILegwithFixedRates (const std::vector< Real > &fixedRates)
 
CPILegwithPaymentDayCounter (const DayCounter &)
 
CPILegwithPaymentAdjustment (BusinessDayConvention)
 
CPILegwithPaymentCalendar (const Calendar &)
 
CPILegwithPaymentLag (Natural lag)
 
CPILegwithFixingDays (Natural fixingDays)
 
CPILegwithFixingDays (const std::vector< Natural > &fixingDays)
 
CPILegwithObservationInterpolation (CPI::InterpolationType)
 
CPILegwithSubtractInflationNominal (bool)
 
CPILegwithCaps (Rate cap)
 
CPILegwithCaps (const std::vector< Rate > &caps)
 
CPILegwithFloors (Rate floor)
 
CPILegwithFloors (const std::vector< Rate > &floors)
 
CPILegwithFinalFlowCap (Rate cap)
 
CPILegwithFinalFlowFloor (Rate floor)
 
CPILegwithExCouponPeriod (const Period &, const Calendar &, BusinessDayConvention, bool endOfMonth=false)
 
CPILegwithStartDate (const Date &startDate)
 
CPILegwithObservationLag (const Period &observationLag)
 
CPILegwithSubtractInflationNominalAllCoupons (bool subtractInflationNominalAllCoupons)
 
CPILegwithBaseDate (const Date &baseDate)
 
 operator Leg () const
 

Private Attributes

Schedule schedule_
 
ext::shared_ptr< ZeroInflationIndex > index_
 
Handle< YieldTermStructure > rateCurve_
 
Real baseCPI_
 
Period observationLag_
 
std::vector< Real > notionals_
 
std::vector< Real > fixedRates_
 
DayCounter paymentDayCounter_
 
BusinessDayConvention paymentAdjustment_
 
Calendar paymentCalendar_
 
Natural paymentLag_
 
std::vector< Natural > fixingDays_
 
CPI::InterpolationType observationInterpolation_
 
bool subtractInflationNominal_
 
std::vector< Rate > caps_
 
std::vector< Rate > floors_
 
double finalFlowCap_
 
double finalFlowFloor_
 
Period exCouponPeriod_
 
Calendar exCouponCalendar_
 
BusinessDayConvention exCouponAdjustment_
 
bool exCouponEndOfMonth_
 
bool subtractInflationNominalAllCoupons_
 
Date startDate_
 
Date baseDate_
 

Detailed Description

Helper class building a sequence of capped/floored CPI coupons.

Also allowing for the inflated notional at the end... especially if there is only one date in the schedule. If a fixedRate is zero you get a FixedRateCoupon, otherwise you get a ZeroInflationCoupon.

payoff is: spread + fixedRate x index

Definition at line 138 of file cpicoupon.hpp.

Constructor & Destructor Documentation

◆ CPILeg()

CPILeg ( const Schedule &  schedule,
const ext::shared_ptr< ZeroInflationIndex > &  index,
const Handle< YieldTermStructure > &  rateCurve,
const Real  baseCPI,
const Period &  observationLag 
)

Definition at line 225 of file cpicoupon.cpp.

227 : schedule_(schedule), index_(index), rateCurve_(rateCurve), baseCPI_(baseCPI), observationLag_(observationLag),
228 paymentDayCounter_(Thirty360(Thirty360::BondBasis)), paymentAdjustment_(ModifiedFollowing), paymentCalendar_(schedule.calendar()),
229 fixingDays_(std::vector<Natural>(1, 0)), observationInterpolation_(CPI::AsIndex), subtractInflationNominal_(true),
230 finalFlowCap_(Null<Real>()), finalFlowFloor_(Null<Real>()), subtractInflationNominalAllCoupons_(false),
231 startDate_(schedule_.dates().front()) {
232 QL_REQUIRE(schedule_.dates().size() > 0, "empty schedule passed to CPILeg");
233}
Schedule schedule_
Definition: cpicoupon.hpp:168
BusinessDayConvention paymentAdjustment_
Definition: cpicoupon.hpp:176
Period observationLag_
Definition: cpicoupon.hpp:172
Calendar paymentCalendar_
Definition: cpicoupon.hpp:177
ext::shared_ptr< ZeroInflationIndex > index_
Definition: cpicoupon.hpp:169
Handle< YieldTermStructure > rateCurve_
Definition: cpicoupon.hpp:170
double finalFlowCap_
Definition: cpicoupon.hpp:183
std::vector< Natural > fixingDays_
Definition: cpicoupon.hpp:179
CPI::InterpolationType observationInterpolation_
Definition: cpicoupon.hpp:180
bool subtractInflationNominalAllCoupons_
Definition: cpicoupon.hpp:188
double finalFlowFloor_
Definition: cpicoupon.hpp:183
bool subtractInflationNominal_
Definition: cpicoupon.hpp:181
DayCounter paymentDayCounter_
Definition: cpicoupon.hpp:175

Member Function Documentation

◆ withNotionals() [1/2]

CPILeg & withNotionals ( Real  notional)

Definition at line 250 of file cpicoupon.cpp.

250 {
251 notionals_ = std::vector<Real>(1, notional);
252 return *this;
253}
std::vector< Real > notionals_
Definition: cpicoupon.hpp:173
+ Here is the caller graph for this function:

◆ withNotionals() [2/2]

CPILeg & withNotionals ( const std::vector< Real > &  notionals)

Definition at line 255 of file cpicoupon.cpp.

255 {
256 notionals_ = notionals;
257 return *this;
258}

◆ withFixedRates() [1/2]

CPILeg & withFixedRates ( Real  fixedRate)

Definition at line 240 of file cpicoupon.cpp.

240 {
241 fixedRates_ = std::vector<Real>(1, fixedRate);
242 return *this;
243}
std::vector< Real > fixedRates_
Definition: cpicoupon.hpp:174
+ Here is the caller graph for this function:

◆ withFixedRates() [2/2]

CPILeg & withFixedRates ( const std::vector< Real > &  fixedRates)

Definition at line 245 of file cpicoupon.cpp.

245 {
246 fixedRates_ = fixedRates;
247 return *this;
248}

◆ withPaymentDayCounter()

CPILeg & withPaymentDayCounter ( const DayCounter &  dayCounter)

Definition at line 265 of file cpicoupon.cpp.

265 {
266 paymentDayCounter_ = dayCounter;
267 return *this;
268}

◆ withPaymentAdjustment()

CPILeg & withPaymentAdjustment ( BusinessDayConvention  convention)

Definition at line 270 of file cpicoupon.cpp.

270 {
271 paymentAdjustment_ = convention;
272 return *this;
273}

◆ withPaymentCalendar()

CPILeg & withPaymentCalendar ( const Calendar &  cal)

Definition at line 275 of file cpicoupon.cpp.

275 {
276 paymentCalendar_ = cal;
277 return *this;
278}
+ Here is the caller graph for this function:

◆ withPaymentLag()

CPILeg & withPaymentLag ( Natural  lag)

Definition at line 280 of file cpicoupon.cpp.

280 {
281 paymentLag_ = lag;
282 return *this;
283}
Natural paymentLag_
Definition: cpicoupon.hpp:178
+ Here is the caller graph for this function:

◆ withFixingDays() [1/2]

CPILeg & withFixingDays ( Natural  fixingDays)

Definition at line 285 of file cpicoupon.cpp.

285 {
286 fixingDays_ = std::vector<Natural>(1, fixingDays);
287 return *this;
288}

◆ withFixingDays() [2/2]

CPILeg & withFixingDays ( const std::vector< Natural > &  fixingDays)

Definition at line 290 of file cpicoupon.cpp.

290 {
291 fixingDays_ = fixingDays;
292 return *this;
293}

◆ withObservationInterpolation()

CPILeg & withObservationInterpolation ( CPI::InterpolationType  interp)

Definition at line 235 of file cpicoupon.cpp.

235 {
237 return *this;
238}

◆ withSubtractInflationNominal()

CPILeg & withSubtractInflationNominal ( bool  growthOnly)

Definition at line 260 of file cpicoupon.cpp.

260 {
261 subtractInflationNominal_ = growthOnly;
262 return *this;
263}

◆ withCaps() [1/2]

CPILeg & withCaps ( Rate  cap)

Definition at line 295 of file cpicoupon.cpp.

295 {
296 caps_ = std::vector<Rate>(1, cap);
297 return *this;
298}
std::vector< Rate > caps_
Definition: cpicoupon.hpp:182

◆ withCaps() [2/2]

CPILeg & withCaps ( const std::vector< Rate > &  caps)

Definition at line 300 of file cpicoupon.cpp.

300 {
301 caps_ = caps;
302 return *this;
303}

◆ withFloors() [1/2]

CPILeg & withFloors ( Rate  floor)

Definition at line 305 of file cpicoupon.cpp.

305 {
306 floors_ = std::vector<Rate>(1, floor);
307 return *this;
308}
std::vector< Rate > floors_
Definition: cpicoupon.hpp:182

◆ withFloors() [2/2]

CPILeg & withFloors ( const std::vector< Rate > &  floors)

Definition at line 320 of file cpicoupon.cpp.

320 {
321 floors_ = floors;
322 return *this;
323}

◆ withFinalFlowCap()

CPILeg & withFinalFlowCap ( Rate  cap)

Definition at line 310 of file cpicoupon.cpp.

310 {
311 finalFlowCap_ = cap;
312 return *this;
313}

◆ withFinalFlowFloor()

CPILeg & withFinalFlowFloor ( Rate  floor)

Definition at line 315 of file cpicoupon.cpp.

315 {
316 finalFlowFloor_ = floor;
317 return *this;
318}

◆ withExCouponPeriod()

CPILeg & withExCouponPeriod ( const Period &  period,
const Calendar &  cal,
BusinessDayConvention  convention,
bool  endOfMonth = false 
)

Definition at line 335 of file cpicoupon.cpp.

336 {
337 exCouponPeriod_ = period;
338 exCouponCalendar_ = cal;
339 exCouponAdjustment_ = convention;
340 exCouponEndOfMonth_ = endOfMonth;
341 return *this;
342}
BusinessDayConvention exCouponAdjustment_
Definition: cpicoupon.hpp:186
bool exCouponEndOfMonth_
Definition: cpicoupon.hpp:187
Period exCouponPeriod_
Definition: cpicoupon.hpp:184
Calendar exCouponCalendar_
Definition: cpicoupon.hpp:185

◆ withStartDate()

CPILeg & withStartDate ( const Date &  startDate)

Definition at line 325 of file cpicoupon.cpp.

325 {
326 startDate_ = startDate;
327 return *this;
328}

◆ withObservationLag()

CPILeg & withObservationLag ( const Period &  observationLag)

Definition at line 330 of file cpicoupon.cpp.

330 {
331 observationLag_ = observationLag;
332 return *this;
333}

◆ withSubtractInflationNominalAllCoupons()

CPILeg & withSubtractInflationNominalAllCoupons ( bool  subtractInflationNominalAllCoupons)

Definition at line 344 of file cpicoupon.cpp.

344 {
345 subtractInflationNominalAllCoupons_ = subtractInflationNominalAllCoupons;
346 return *this;
347}

◆ withBaseDate()

CPILeg & withBaseDate ( const Date &  baseDate)

◆ operator Leg()

operator Leg ( ) const

Definition at line 349 of file cpicoupon.cpp.

349 {
350
351 QL_REQUIRE(!notionals_.empty(), "no notional given");
352 Size n = schedule_.size() - 1;
353 Leg leg;
354 leg.reserve(n + 1); // +1 for notional, we always have some sort ...
355 Date baseDate = baseDate_ == Date() ? startDate_ - observationLag_ : baseDate_;
356 if (n > 0) {
357 QL_REQUIRE(!fixedRates_.empty(), "no fixedRates given");
358
359 Date refStart, start, refEnd, end;
360
361 for (Size i = 0; i < n; ++i) {
362 refStart = start = schedule_.date(i);
363 refEnd = end = schedule_.date(i + 1);
364 Date paymentDate = paymentCalendar_.advance(end, paymentLag_, Days, paymentAdjustment_);
365
366 Date exCouponDate;
367 if (exCouponPeriod_ != Period()) {
368 exCouponDate =
370 }
371
372 if (i == 0 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1)) {
373 BusinessDayConvention bdc = schedule_.businessDayConvention();
374 refStart = schedule_.calendar().adjust(end - schedule_.tenor(), bdc);
375 }
376 if (i == n - 1 && schedule_.hasIsRegular() && !schedule_.isRegular(i + 1)) {
377 BusinessDayConvention bdc = schedule_.businessDayConvention();
378 refEnd = schedule_.calendar().adjust(start + schedule_.tenor(), bdc);
379 }
380
381 auto coup = ext::make_shared<CPICoupon>(
382 baseCPI_, // all have same base for ratio
383 baseDate, paymentDate, detail::get(notionals_, i, 0.0), start, end, index_, observationLag_,
385 refStart, refEnd, exCouponDate, subtractInflationNominalAllCoupons_);
386
387 // set a pricer for the underlying coupon straight away because it only provides computation - not data
388 auto pricer = ext::make_shared<CPICouponPricer>(Handle<YieldTermStructure>(rateCurve_));
389 coup->setPricer(pricer);
390
391 if (detail::noOption(caps_, floors_, i)) { // just swaplet
392 leg.push_back(coup);
393 } else { // cap/floorlet
394 auto cfCoup = ext::make_shared<CappedFlooredCPICoupon>(
395 coup, startDate_, detail::get(caps_, i, Null<Rate>()), detail::get(floors_, i, Null<Rate>()));
396 // in this case we need to set the "outer" pricer later that handles cap and floor
397 leg.push_back(cfCoup);
398 }
399 }
400 }
401
402 // in CPI legs you always have a notional flow of some sort
403
404 // Previous implementations didn't differentiate the observation and payment dates
405 Date observationDate = paymentCalendar_.adjust(schedule_.date(n), paymentAdjustment_);
406 Date paymentDate = paymentCalendar_.advance(schedule_.date(n), paymentLag_, Days, paymentAdjustment_);
407
408 ext::shared_ptr<CPICashFlow> xnl = ext::make_shared<CPICashFlow>(
409 detail::get(notionals_, n, 0.0), index_, baseDate, baseCPI_, observationDate, observationLag_,
411
412 if (finalFlowCap_ == Null<Real>() && finalFlowFloor_ == Null<Real>()) {
413 leg.push_back(xnl);
414 } else {
415 ext::shared_ptr<CappedFlooredCPICashFlow> cfxnl = ext::make_shared<CappedFlooredCPICashFlow>(
417 leg.push_back(cfxnl);
418 }
419
420 return leg;
421}

Member Data Documentation

◆ schedule_

Schedule schedule_
private

Definition at line 168 of file cpicoupon.hpp.

◆ index_

ext::shared_ptr<ZeroInflationIndex> index_
private

Definition at line 169 of file cpicoupon.hpp.

◆ rateCurve_

Handle<YieldTermStructure> rateCurve_
private

Definition at line 170 of file cpicoupon.hpp.

◆ baseCPI_

Real baseCPI_
private

Definition at line 171 of file cpicoupon.hpp.

◆ observationLag_

Period observationLag_
private

Definition at line 172 of file cpicoupon.hpp.

◆ notionals_

std::vector<Real> notionals_
private

Definition at line 173 of file cpicoupon.hpp.

◆ fixedRates_

std::vector<Real> fixedRates_
private

Definition at line 174 of file cpicoupon.hpp.

◆ paymentDayCounter_

DayCounter paymentDayCounter_
private

Definition at line 175 of file cpicoupon.hpp.

◆ paymentAdjustment_

BusinessDayConvention paymentAdjustment_
private

Definition at line 176 of file cpicoupon.hpp.

◆ paymentCalendar_

Calendar paymentCalendar_
private

Definition at line 177 of file cpicoupon.hpp.

◆ paymentLag_

Natural paymentLag_
private

Definition at line 178 of file cpicoupon.hpp.

◆ fixingDays_

std::vector<Natural> fixingDays_
private

Definition at line 179 of file cpicoupon.hpp.

◆ observationInterpolation_

CPI::InterpolationType observationInterpolation_
private

Definition at line 180 of file cpicoupon.hpp.

◆ subtractInflationNominal_

bool subtractInflationNominal_
private

Definition at line 181 of file cpicoupon.hpp.

◆ caps_

std::vector<Rate> caps_
private

Definition at line 182 of file cpicoupon.hpp.

◆ floors_

std::vector<Rate> floors_
private

Definition at line 182 of file cpicoupon.hpp.

◆ finalFlowCap_

double finalFlowCap_
private

Definition at line 183 of file cpicoupon.hpp.

◆ finalFlowFloor_

double finalFlowFloor_
private

Definition at line 183 of file cpicoupon.hpp.

◆ exCouponPeriod_

Period exCouponPeriod_
private

Definition at line 184 of file cpicoupon.hpp.

◆ exCouponCalendar_

Calendar exCouponCalendar_
private

Definition at line 185 of file cpicoupon.hpp.

◆ exCouponAdjustment_

BusinessDayConvention exCouponAdjustment_
private

Definition at line 186 of file cpicoupon.hpp.

◆ exCouponEndOfMonth_

bool exCouponEndOfMonth_
private

Definition at line 187 of file cpicoupon.hpp.

◆ subtractInflationNominalAllCoupons_

bool subtractInflationNominalAllCoupons_
private

Definition at line 188 of file cpicoupon.hpp.

◆ startDate_

Date startDate_
private

Definition at line 191 of file cpicoupon.hpp.

◆ baseDate_

Date baseDate_
private

Definition at line 193 of file cpicoupon.hpp.