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

#include <qle/termstructures/capfloorhelper.hpp>

+ Inheritance diagram for CapFloorHelper:
+ Collaboration diagram for CapFloorHelper:

Public Types

enum  Type { Cap , Floor , Automatic }
 
enum  QuoteType { Premium , Volatility }
 Enum to indicate the type of the quote provided with the CapFloorHelper. More...
 

Public Member Functions

 CapFloorHelper (Type type, const QuantLib::Period &tenor, QuantLib::Rate strike, const QuantLib::Handle< QuantLib::Quote > &quote, const QuantLib::ext::shared_ptr< QuantLib::IborIndex > &iborIndex, const QuantLib::Handle< QuantLib::YieldTermStructure > &discountingCurve, bool moving=true, const QuantLib::Date &effectiveDate=QuantLib::Date(), QuoteType quoteType=Premium, QuantLib::VolatilityType quoteVolatilityType=QuantLib::Normal, QuantLib::Real quoteDisplacement=0.0, bool endOfMonth=false, bool firstCapletExcluded=true)
 
Inspectors
QuantLib::ext::shared_ptr< QuantLib::CapFloor > capFloor () const
 Return the cap floor instrument underlying the helper. More...
 
BootstrapHelper interface
QuantLib::Real impliedQuote () const override
 Returns the capFloor_ instrument's premium. More...
 
void setTermStructure (QuantLib::OptionletVolatilityStructure *ovts) override
 Sets the helper's OptionletVolatilityStructure to ovts and sets up the pricing engine for capFloor_. More...
 

Visitability

Type type_
 
QuantLib::Period tenor_
 
QuantLib::Rate strike_
 
QuantLib::ext::shared_ptr< QuantLib::IborIndex > iborIndex_
 
QuantLib::Handle< QuantLib::YieldTermStructure > discountHandle_
 
bool moving_
 
QuantLib::Date effectiveDate_
 
QuoteType quoteType_
 
QuantLib::VolatilityType quoteVolatilityType_
 
QuantLib::Real quoteDisplacement_
 
bool endOfMonth_
 
bool firstCapletExcluded_
 
QuantLib::Handle< QuantLib::Quote > rawQuote_
 
bool initialised_
 
QuantLib::ext::shared_ptr< QuantLib::CapFloor > capFloor_
 The underlying instrument. More...
 
QuantLib::RelinkableHandle< QuantLib::OptionletVolatilityStructure > ovtsHandle_
 The OptionletVolatilityStructure Handle that we link to the capFloor_ instrument. More...
 
QuantLib::ext::shared_ptr< QuantLib::CapFloor > capFloorCopy_
 A copy of the underlying instrument that is used in the npv method. More...
 
void accept (QuantLib::AcyclicVisitor &) override
 
void initializeDates () override
 RelativeDateBootstrapHelper interface. More...
 
QuantLib::Real npv (QuantLib::Real quote)
 A method to calculate the cap floor premium from a flat cap floor volatility value. More...
 

Detailed Description

Helper for bootstrapping optionlet volatilities from cap floor volatilities. The helper has a date schedule that is relative to the global evaluation date.

Definition at line 38 of file capfloorhelper.hpp.

Member Enumeration Documentation

◆ Type

enum Type

Enum to indicate whether the instrument underlying the helper is a Cap, a Floor or should be chosen automatically. If Automatic is chosen and the quote type is volatility, the instrument's ATM rate is queried and if it is greater than the strike, the instrument is a Floor otherwise it is a Cap.

Enumerator
Cap 
Floor 
Automatic 

Definition at line 45 of file capfloorhelper.hpp.

◆ QuoteType

enum QuoteType

Enum to indicate the type of the quote provided with the CapFloorHelper.

Enumerator
Premium 
Volatility 

Definition at line 48 of file capfloorhelper.hpp.

Constructor & Destructor Documentation

◆ CapFloorHelper()

CapFloorHelper ( Type  type,
const QuantLib::Period &  tenor,
QuantLib::Rate  strike,
const QuantLib::Handle< QuantLib::Quote > &  quote,
const QuantLib::ext::shared_ptr< QuantLib::IborIndex > &  iborIndex,
const QuantLib::Handle< QuantLib::YieldTermStructure > &  discountingCurve,
bool  moving = true,
const QuantLib::Date &  effectiveDate = QuantLib::Date(),
QuoteType  quoteType = Premium,
QuantLib::VolatilityType  quoteVolatilityType = QuantLib::Normal,
QuantLib::Real  quoteDisplacement = 0.0,
bool  endOfMonth = false,
bool  firstCapletExcluded = true 
)

Constructor

Parameters
typeThe CapFloorHelper type as described above
tenorThe underlying cap floor instrument's tenor
strikeThe underlying cap floor instrument's strike. Setting this to Null<Real>() indicates that the ATM strike for the given tenor should be used.
quoteThe quoted premium or implied volatility for the underlying cap floor instrument
iborIndexThe IborIndex underlying the cap floor instrument
discountingCurveThe curve used for discounting the cap floor instrument cashflows
movingIf this is true, the helper's schedule is relative to the global evaluation date and is updated if the global evaluation date is updated. If false, the helper has a fixed schedule relative to the effectiveDate that does not change with changes in the global evaluation date.
effectiveDateThe effective date of the underlying cap floor instrument. If this is the empty QuantLib::Date(), the effective date is determined from the global evaluation date.
quoteTypeThe quote type
quoteVolatilityTypeIf the quote type is Volatility, this indicates the volatility type of the quote
quoteDisplacementIf the quote type is Volatility and the volatility type is ShiftedLognormal, this provides the shift size associated with the quote.
endOfMonthWhether or not to use end of month adjustment when generating the cap floor schedule
firstCapletExcludedWhether or not to exclude the first caplet in the underlying cap floor instrument

Definition at line 39 of file capfloorhelper.cpp.

45 : RelativeDateBootstrapHelper<OptionletVolatilityStructure>(
46 Handle<Quote>(QuantLib::ext::make_shared<DerivedQuote<QuantLib::ext::function<Real(Real)> > >(
47 quote, QuantLib::ext::bind(&CapFloorHelper::npv, this, QuantLib::ext::placeholders::_1)))),
48 type_(type), tenor_(tenor), strike_(strike), iborIndex_(iborIndex), discountHandle_(discountingCurve),
49 moving_(moving), effectiveDate_(effectiveDate), quoteType_(quoteType), quoteVolatilityType_(quoteVolatilityType),
50 quoteDisplacement_(quoteDisplacement), endOfMonth_(endOfMonth), firstCapletExcluded_(firstCapletExcluded),
51 rawQuote_(quote), initialised_(false) {
52
53 if (quoteType_ == Premium) {
54 QL_REQUIRE(type_ != Automatic, "Cannot have CapFloorHelper type 'Automatic' with quote type of Premium");
55 }
56
57 QL_REQUIRE(!(moving_ && effectiveDate_ != Date()),
58 "A fixed effective date does not make sense for a moving helper");
59
60 registerWith(iborIndex_);
61 registerWith(discountHandle_);
62
64 initialised_ = true;
65}
QuantLib::Handle< QuantLib::Quote > rawQuote_
QuantLib::Real npv(QuantLib::Real quote)
A method to calculate the cap floor premium from a flat cap floor volatility value.
QuantLib::ext::shared_ptr< QuantLib::IborIndex > iborIndex_
QuantLib::Real quoteDisplacement_
void initializeDates() override
RelativeDateBootstrapHelper interface.
QuantLib::VolatilityType quoteVolatilityType_
QuantLib::Handle< QuantLib::YieldTermStructure > discountHandle_
+ Here is the call graph for this function:

Member Function Documentation

◆ capFloor()

QuantLib::ext::shared_ptr< QuantLib::CapFloor > capFloor ( ) const

Return the cap floor instrument underlying the helper.

Definition at line 83 of file capfloorhelper.hpp.

83{ return capFloor_; }
QuantLib::ext::shared_ptr< QuantLib::CapFloor > capFloor_
The underlying instrument.

◆ impliedQuote()

Real impliedQuote ( ) const
override

Returns the capFloor_ instrument's premium.

Definition at line 158 of file capfloorhelper.cpp.

158 {
159 QL_REQUIRE(termStructure_ != 0, "CapFloorHelper's optionlet volatility term structure has not been set");
160 capFloor_->deepUpdate();
161 return capFloor_->NPV();
162}

◆ setTermStructure()

void setTermStructure ( QuantLib::OptionletVolatilityStructure *  ovts)
override

Sets the helper's OptionletVolatilityStructure to ovts and sets up the pricing engine for capFloor_.

Definition at line 105 of file capfloorhelper.cpp.

105 {
106
107 if (strike_ == Null<Real>()) {
108 // If the strike is Null<Real>(), we want an ATM helper
109 Rate atm = capFloor_->atmRate(**discountHandle_);
110 capFloor_ = MakeCapFloor(capFloor_->type(), tenor_, iborIndex_, atm, 0 * Days)
111 .withEndOfMonth(endOfMonth_)
112 .withEffectiveDate(effectiveDate_, firstCapletExcluded_);
113 capFloorCopy_ = MakeCapFloor(capFloor_->type(), tenor_, iborIndex_, atm, 0 * Days)
114 .withEndOfMonth(endOfMonth_)
115 .withEffectiveDate(effectiveDate_, firstCapletExcluded_);
116
118 // If the helper is set to automatically choose the underlying instrument type, do it now based on the ATM rate
119 Rate atm = capFloor_->atmRate(**discountHandle_);
120 CapFloor::Type capFloorType = atm > strike_ ? CapFloor::Floor : CapFloor::Cap;
121 if (capFloor_->type() != capFloorType) {
122 capFloor_ = MakeCapFloor(capFloorType, tenor_, iborIndex_, strike_, 0 * Days)
123 .withEndOfMonth(endOfMonth_)
124 .withEffectiveDate(effectiveDate_, firstCapletExcluded_);
125 capFloorCopy_ = MakeCapFloor(capFloorType, tenor_, iborIndex_, strike_, 0 * Days)
126 .withEndOfMonth(endOfMonth_)
127 .withEffectiveDate(effectiveDate_, firstCapletExcluded_);
128 }
129 }
130
131 // Set this helper's optionlet volatility structure
132 QuantLib::ext::shared_ptr<OptionletVolatilityStructure> temp(ovts, null_deleter());
133 ovtsHandle_.linkTo(temp, false);
134
135 // Set the term structure pointer member variable in the base class
136 RelativeDateBootstrapHelper<OptionletVolatilityStructure>::setTermStructure(ovts);
137
138 // Set this helper's pricing engine depending on the type of the optionlet volatilities
139 if (ovts->volatilityType() == ShiftedLognormal) {
140 capFloor_->setPricingEngine(QuantLib::ext::make_shared<BlackCapFloorEngine>(discountHandle_, ovtsHandle_));
141 } else {
142 capFloor_->setPricingEngine(QuantLib::ext::make_shared<BachelierCapFloorEngine>(discountHandle_, ovtsHandle_));
143 }
144
145 // If the quote type is not a premium, we will need to use capFloorCopy_ to return the premium from the volatility
146 // quote
147 if (quoteType_ != Premium) {
148 if (quoteVolatilityType_ == ShiftedLognormal) {
149 capFloorCopy_->setPricingEngine(QuantLib::ext::make_shared<BlackCapFloorEngine>(
151 } else {
152 capFloorCopy_->setPricingEngine(
153 QuantLib::ext::make_shared<BachelierCapFloorEngine>(discountHandle_, rawQuote_, ovtsHandle_->dayCounter()));
154 }
155 }
156}
QuantLib::ext::shared_ptr< QuantLib::CapFloor > capFloorCopy_
A copy of the underlying instrument that is used in the npv method.
QuantLib::RelinkableHandle< QuantLib::OptionletVolatilityStructure > ovtsHandle_
The OptionletVolatilityStructure Handle that we link to the capFloor_ instrument.

◆ accept()

void accept ( QuantLib::AcyclicVisitor &  )
override

Definition at line 164 of file capfloorhelper.cpp.

164 {
165 if (Visitor<CapFloorHelper>* v1 = dynamic_cast<Visitor<CapFloorHelper>*>(&v))
166 v1->visit(*this);
167 else
168 RelativeDateBootstrapHelper<OptionletVolatilityStructure>::accept(v);
169}

◆ initializeDates()

void initializeDates ( )
overrideprivate

RelativeDateBootstrapHelper interface.

Definition at line 67 of file capfloorhelper.cpp.

67 {
68
69 if (!initialised_ || moving_) {
70 CapFloor::Type capFloorType = CapFloor::Cap;
72 capFloorType = CapFloor::Floor;
73 }
74
75 // Initialise the instrument and a copy
76 // The strike can be Null<Real>() to indicate an ATM cap floor helper
77 Rate dummyStrike = strike_ == Null<Real>() ? 0.01 : strike_;
78 capFloor_ = MakeCapFloor(capFloorType, tenor_, iborIndex_, dummyStrike, 0 * Days)
79 .withEndOfMonth(endOfMonth_)
80 .withEffectiveDate(effectiveDate_, firstCapletExcluded_);
81 capFloorCopy_ = MakeCapFloor(capFloorType, tenor_, iborIndex_, dummyStrike, 0 * Days)
82 .withEndOfMonth(endOfMonth_)
83 .withEffectiveDate(effectiveDate_, firstCapletExcluded_);
84
85 // Maturity date is just the maturity date of the cap floor
86 maturityDate_ = capFloor_->maturityDate();
87
88 // We need the leg underlying the cap floor to determine the remaining date members
89 const Leg& leg = capFloor_->floatingLeg();
90
91 // Earliest date is the first optionlet fixing date
92 QuantLib::ext::shared_ptr<CashFlow> cf = leg.front();
93 QuantLib::ext::shared_ptr<FloatingRateCoupon> frc = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(cf);
94 QL_REQUIRE(frc, "Expected the first cashflow on the cap floor instrument to be a FloatingRateCoupon");
95 earliestDate_ = frc->fixingDate();
96
97 // Remaining dates are each equal to the fixing date on the final optionlet
98 cf = leg.back();
99 frc = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(cf);
100 QL_REQUIRE(frc, "Expected the final cashflow on the cap floor instrument to be a FloatingRateCoupon");
101 pillarDate_ = latestDate_ = latestRelevantDate_ = frc->fixingDate();
102 }
103}
+ Here is the caller graph for this function:

◆ npv()

Real npv ( QuantLib::Real  quote)
private

A method to calculate the cap floor premium from a flat cap floor volatility value.

Definition at line 171 of file capfloorhelper.cpp.

171 {
172 if (quoteType_ == Premium) {
173 return quoteValue;
174 } else {
175 // If the quote value is a volatility, return the premium
176 return capFloorCopy_->NPV();
177 }
178}

Member Data Documentation

◆ type_

Type type_
private

Definition at line 105 of file capfloorhelper.hpp.

◆ tenor_

QuantLib::Period tenor_
private

Definition at line 106 of file capfloorhelper.hpp.

◆ strike_

QuantLib::Rate strike_
private

Definition at line 107 of file capfloorhelper.hpp.

◆ iborIndex_

QuantLib::ext::shared_ptr<QuantLib::IborIndex> iborIndex_
private

Definition at line 108 of file capfloorhelper.hpp.

◆ discountHandle_

QuantLib::Handle<QuantLib::YieldTermStructure> discountHandle_
private

Definition at line 109 of file capfloorhelper.hpp.

◆ moving_

bool moving_
private

Definition at line 110 of file capfloorhelper.hpp.

◆ effectiveDate_

QuantLib::Date effectiveDate_
private

Definition at line 111 of file capfloorhelper.hpp.

◆ quoteType_

QuoteType quoteType_
private

Definition at line 112 of file capfloorhelper.hpp.

◆ quoteVolatilityType_

QuantLib::VolatilityType quoteVolatilityType_
private

Definition at line 113 of file capfloorhelper.hpp.

◆ quoteDisplacement_

QuantLib::Real quoteDisplacement_
private

Definition at line 114 of file capfloorhelper.hpp.

◆ endOfMonth_

bool endOfMonth_
private

Definition at line 115 of file capfloorhelper.hpp.

◆ firstCapletExcluded_

bool firstCapletExcluded_
private

Definition at line 116 of file capfloorhelper.hpp.

◆ rawQuote_

QuantLib::Handle<QuantLib::Quote> rawQuote_
private

Definition at line 117 of file capfloorhelper.hpp.

◆ initialised_

bool initialised_
private

Definition at line 118 of file capfloorhelper.hpp.

◆ capFloor_

QuantLib::ext::shared_ptr<QuantLib::CapFloor> capFloor_
private

The underlying instrument.

Definition at line 121 of file capfloorhelper.hpp.

◆ ovtsHandle_

QuantLib::RelinkableHandle<QuantLib::OptionletVolatilityStructure> ovtsHandle_
private

The OptionletVolatilityStructure Handle that we link to the capFloor_ instrument.

Definition at line 124 of file capfloorhelper.hpp.

◆ capFloorCopy_

QuantLib::ext::shared_ptr<QuantLib::CapFloor> capFloorCopy_
private

A copy of the underlying instrument that is used in the npv method.

Definition at line 127 of file capfloorhelper.hpp.