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

Capped or floored CPI coupon. More...

#include <qle/cashflows/cpicoupon.hpp>

+ Inheritance diagram for CappedFlooredCPICoupon:
+ Collaboration diagram for CappedFlooredCPICoupon:

Public Member Functions

 CappedFlooredCPICoupon (const ext::shared_ptr< CPICoupon > &underlying, Date startDate=Date(), Rate cap=Null< Rate >(), Rate floor=Null< Rate >())
 
virtual Rate rate () const override
 
ext::shared_ptr< CPICouponunderlying () const
 
Observer interface
void update () override
 
- Public Member Functions inherited from CPICoupon
 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(), bool subtractInflationNominal=false)
 
 CPICoupon (Real baseCPI, const Date &baseDate, 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(), bool subtractInflationNominal=false)
 
virtual Rate rate () const override
 
bool subtractInflationNotional ()
 

Visitability

ext::shared_ptr< CPICouponunderlying_
 
ext::shared_ptr< CPICapFloor > cpiCap_
 
ext::shared_ptr< CPICapFloor > cpiFloor_
 
Date startDate_
 
bool isFloored_
 
bool isCapped_
 
Rate cap_
 
Rate floor_
 
virtual void accept (AcyclicVisitor &v) override
 
bool isCapped () const
 
bool isFloored () const
 
virtual void setCommon (Rate cap, Rate floor)
 

Additional Inherited Members

- Protected Attributes inherited from CPICoupon
bool subtractInflationNominal_
 

Detailed Description

Capped or floored CPI coupon.

Extended QuantLib::CPICoupon

Definition at line 99 of file cpicoupon.hpp.

Constructor & Destructor Documentation

◆ CappedFlooredCPICoupon()

CappedFlooredCPICoupon ( const ext::shared_ptr< CPICoupon > &  underlying,
Date  startDate = Date(),
Rate  cap = Null<Rate>(),
Rate  floor = Null<Rate>() 
)

Definition at line 72 of file cpicoupon.cpp.

74 : CPICoupon(underlying->baseCPI(), underlying->baseDate(), underlying->date(), underlying->nominal(), underlying->accrualStartDate(),
75 underlying->accrualEndDate(), underlying->cpiIndex(),
76 underlying->observationLag(), underlying->observationInterpolation(), underlying->dayCounter(),
77 underlying->fixedRate(), underlying->referencePeriodStart(),
78 underlying->referencePeriodEnd(), underlying->exCouponDate(), underlying->subtractInflationNotional()),
79 underlying_(underlying), startDate_(startDate), isFloored_(false), isCapped_(false) {
80
81 setCommon(cap, floor);
82 registerWith(underlying);
83
84 Calendar cal = underlying->cpiIndex()->fixingCalendar(); // not used by the CPICapFloor engine
85 BusinessDayConvention conv = Unadjusted; // not used by the CPICapFloor engine
86
87 if (isCapped_) {
88 Rate effectiveCap = cap_;
89 cpiCap_ = QuantLib::ext::make_shared<CPICapFloor>(
90 Option::Call, underlying_->nominal(), startDate_, underlying_->baseCPI(), underlying_->date(), cal, conv,
91 cal, conv, effectiveCap, underlying_->cpiIndex(), underlying_->observationLag(),
92 underlying_->observationInterpolation());
93 // std::cout << "Capped/Floored CPI Coupon" << std::endl
94 // << " nominal = " << underlying_->nominal() << std::endl
95 // << " paymentDate = " << QuantLib::io::iso_date(underlying_->date()) << std::endl
96 // << " startDate = " << QuantLib::io::iso_date(startDate_) << std::endl
97 // << " baseCPI = " << underlying_->baseCPI() << std::endl
98 // << " lag = " << underlying_->observationLag() << std::endl
99 // << " interpolation = " << underlying_->observationInterpolation() << std::endl;
100 }
101 if (isFloored_) {
102 Rate effectiveFloor = floor_;
103 cpiFloor_ = QuantLib::ext::make_shared<CPICapFloor>(
104 Option::Put, underlying_->nominal(), startDate_, underlying_->baseCPI(), underlying_->date(), cal, conv,
105 cal, conv, effectiveFloor, underlying_->cpiIndex(),
106 underlying_->observationLag(),
107 underlying_->observationInterpolation());
108 }
109}
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(), bool subtractInflationNominal=false)
Definition: cpicoupon.hpp:37
ext::shared_ptr< CPICapFloor > cpiCap_
Definition: cpicoupon.hpp:124
virtual void setCommon(Rate cap, Rate floor)
Definition: cpicoupon.cpp:43
ext::shared_ptr< CPICoupon > underlying() const
Definition: cpicoupon.hpp:105
ext::shared_ptr< CPICoupon > underlying_
Definition: cpicoupon.hpp:123
ext::shared_ptr< CPICapFloor > cpiFloor_
Definition: cpicoupon.hpp:124
+ Here is the call graph for this function:

Member Function Documentation

◆ rate()

Rate rate ( ) const
overridevirtual

Reimplemented from CPICoupon.

Definition at line 111 of file cpicoupon.cpp.

111 {
112 // rate = fixedRate * capped/floored index
113 QuantLib::ext::shared_ptr<CappedFlooredCPICouponPricer> blackPricer =
114 QuantLib::ext::dynamic_pointer_cast<CappedFlooredCPICouponPricer>(pricer_);
115 QL_REQUIRE(blackPricer, "BlackCPICouponPricer or BachelierCPICouponPricer expected");
116 Real capValue = 0.0, floorValue = 0.0;
117 if (isCapped_) {
118 cpiCap_->setPricingEngine(blackPricer->engine());
119 capValue = cpiCap_->NPV();
120 }
121 if (isFloored_) {
122 cpiFloor_->setPricingEngine(blackPricer->engine());
123 floorValue = cpiFloor_->NPV();
124 }
125 Real discount = blackPricer->yieldCurve()->discount(underlying_->date());
126 Real nominal = underlying_->nominal();
127 // normalize, multiplication with nominal, year fraction, discount follows
128 Real capAmount = capValue / (nominal * discount);
129 Real floorAmount = floorValue / (nominal * discount);
130
131 Rate swapletRate = underlying_->rate();
132 // apply gearing
133 Rate floorletRate = floorAmount * underlying_->fixedRate();
134 Rate capletRate = capAmount * underlying_->fixedRate();
135 // long floor, short cap
136 Rate totalRate = swapletRate + floorletRate - capletRate;
137
138 return totalRate;
139}
const QuantLib::ext::shared_ptr< FloatingRateCouponPricer > pricer_

◆ underlying()

ext::shared_ptr< CPICoupon > underlying ( ) const

Definition at line 105 of file cpicoupon.hpp.

105{ return underlying_; }
+ Here is the caller graph for this function:

◆ update()

void update ( )
override

Definition at line 141 of file cpicoupon.cpp.

141{ notifyObservers(); }

◆ accept()

void accept ( AcyclicVisitor &  v)
overridevirtual

Definition at line 143 of file cpicoupon.cpp.

143 {
144 Visitor<CappedFlooredCPICoupon>* v1 = dynamic_cast<Visitor<CappedFlooredCPICoupon>*>(&v);
145 if (v1 != 0)
146 v1->visit(*this);
147 else
148 CPICoupon::accept(v);
149}

◆ isCapped()

bool isCapped ( ) const

Definition at line 117 of file cpicoupon.hpp.

117{ return isCapped_; }

◆ isFloored()

bool isFloored ( ) const

Definition at line 118 of file cpicoupon.hpp.

118{ return isFloored_; }

◆ setCommon()

void setCommon ( Rate  cap,
Rate  floor 
)
protectedvirtual

Definition at line 43 of file cpicoupon.cpp.

43 {
44
45 isCapped_ = false;
46 isFloored_ = false;
47
48 if (fixedRate_ > 0) {
49 if (cap != Null<Rate>()) {
50 isCapped_ = true;
51 cap_ = cap;
52 }
53 if (floor != Null<Rate>()) {
54 floor_ = floor;
55 isFloored_ = true;
56 }
57 } else {
58 if (cap != Null<Rate>()) {
59 floor_ = cap;
60 isFloored_ = true;
61 }
62 if (floor != Null<Rate>()) {
63 isCapped_ = true;
64 cap_ = floor;
65 }
66 }
67 if (isCapped_ && isFloored_) {
68 QL_REQUIRE(cap >= floor, "cap level (" << cap << ") less than floor level (" << floor << ")");
69 }
70}
+ Here is the caller graph for this function:

Member Data Documentation

◆ underlying_

ext::shared_ptr<CPICoupon> underlying_
protected

Definition at line 123 of file cpicoupon.hpp.

◆ cpiCap_

ext::shared_ptr<CPICapFloor> cpiCap_
protected

Definition at line 124 of file cpicoupon.hpp.

◆ cpiFloor_

ext::shared_ptr<CPICapFloor> cpiFloor_
protected

Definition at line 124 of file cpicoupon.hpp.

◆ startDate_

Date startDate_
protected

Definition at line 125 of file cpicoupon.hpp.

◆ isFloored_

bool isFloored_
protected

Definition at line 126 of file cpicoupon.hpp.

◆ isCapped_

bool isCapped_
protected

Definition at line 126 of file cpicoupon.hpp.

◆ cap_

Rate cap_
protected

Definition at line 127 of file cpicoupon.hpp.

◆ floor_

Rate floor_
protected

Definition at line 127 of file cpicoupon.hpp.