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

#include <qle/termstructures/oiscapfloorhelper.hpp>

+ Inheritance diagram for OISCapFloorHelper:
+ Collaboration diagram for OISCapFloorHelper:

Public Member Functions

 OISCapFloorHelper (CapFloorHelper::Type type, const QuantLib::Period &tenor, const QuantLib::Period &rateComputationPeriod, QuantLib::Rate strike, const QuantLib::Handle< QuantLib::Quote > &quote, const QuantLib::ext::shared_ptr< QuantLib::OvernightIndex > &index, const QuantLib::Handle< QuantLib::YieldTermStructure > &discountingCurve, bool moving=true, const QuantLib::Date &effectiveDate=QuantLib::Date(), CapFloorHelper::QuoteType quoteType=CapFloorHelper::Premium, QuantLib::VolatilityType quoteVolatilityType=QuantLib::Normal, QuantLib::Real quoteDisplacement=0.0)
 OISCapFloorHelper, similar to CapFloorHelper. More...
 
Leg capFloor () const
 
void setTermStructure (QuantLib::OptionletVolatilityStructure *ovts) override
 
QuantLib::Real impliedQuote () const override
 
void accept (QuantLib::AcyclicVisitor &) override
 

Private Member Functions

void initializeDates () override
 
QuantLib::Real npv (QuantLib::Real quote)
 A method to calculate the cap floor premium from a flat cap floor volatility value. More...
 

Private Attributes

CapFloorHelper::Type type_
 
QuantLib::Period tenor_
 
QuantLib::Period rateComputationPeriod_
 
QuantLib::Rate strike_
 
QuantLib::ext::shared_ptr< QuantLib::OvernightIndex > index_
 
QuantLib::Handle< QuantLib::YieldTermStructure > discountHandle_
 
bool moving_
 
QuantLib::Date effectiveDate_
 
CapFloorHelper::QuoteType quoteType_
 
QuantLib::VolatilityType quoteVolatilityType_
 
QuantLib::Real quoteDisplacement_
 
QuantLib::Handle< QuantLib::Quote > rawQuote_
 
bool initialised_
 
Leg capFloor_
 
QuantLib::RelinkableHandle< QuantLib::OptionletVolatilityStructure > ovtsHandle_
 
Leg capFloorCopy_
 

Detailed Description

Definition at line 33 of file oiscapfloorhelper.hpp.

Constructor & Destructor Documentation

◆ OISCapFloorHelper()

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

OISCapFloorHelper, similar to CapFloorHelper.

Definition at line 37 of file oiscapfloorhelper.cpp.

44 : RelativeDateBootstrapHelper<OptionletVolatilityStructure>(
45 Handle<Quote>(QuantLib::ext::make_shared<DerivedQuote<QuantLib::ext::function<Real(Real)>>>(
46 quote, QuantLib::ext::bind(&OISCapFloorHelper::npv, this, QuantLib::ext::placeholders::_1)))),
47 type_(type), tenor_(tenor), rateComputationPeriod_(rateComputationPeriod), strike_(strike), index_(index),
48 discountHandle_(discountingCurve), moving_(moving), effectiveDate_(effectiveDate), quoteType_(quoteType),
49 quoteVolatilityType_(quoteVolatilityType), quoteDisplacement_(quoteDisplacement), rawQuote_(quote),
50 initialised_(false) {
51
53 QL_REQUIRE(type_ != CapFloorHelper::Automatic,
54 "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(index_);
61 registerWith(discountHandle_);
62
64 initialised_ = true;
65}
QuantLib::Handle< QuantLib::Quote > rawQuote_
QuantLib::Period rateComputationPeriod_
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::OvernightIndex > index_
CapFloorHelper::QuoteType quoteType_
QuantLib::VolatilityType quoteVolatilityType_
QuantLib::Handle< QuantLib::YieldTermStructure > discountHandle_
+ Here is the call graph for this function:

Member Function Documentation

◆ capFloor()

Leg capFloor ( ) const

Definition at line 47 of file oiscapfloorhelper.hpp.

◆ setTermStructure()

void setTermStructure ( QuantLib::OptionletVolatilityStructure *  ovts)
override

Definition at line 103 of file oiscapfloorhelper.cpp.

103 {
104
105 if (strike_ == Null<Real>()) {
106 // If the strike is Null<Real>(), we want an ATM helper
107 Rate atm = CashFlows::atmRate(getOisCapFloorUnderlying(capFloor_), **discountHandle_, false);
108 CapFloor::Type capFloorType = type_ == CapFloorHelper::Cap ? CapFloor::Cap : CapFloor::Floor;
109 capFloor_ = MakeOISCapFloor(capFloorType, tenor_, index_, rateComputationPeriod_, atm)
110 .withTelescopicValueDates(true)
111 .withEffectiveDate(effectiveDate_);
112 capFloorCopy_ = MakeOISCapFloor(capFloorType, tenor_, index_, rateComputationPeriod_, atm)
113 .withTelescopicValueDates(true)
114 .withEffectiveDate(effectiveDate_);
116 // If the helper is set to automatically choose the underlying instrument type, do it now based on the ATM rate
117 Rate atm = CashFlows::atmRate(getOisCapFloorUnderlying(capFloor_), **discountHandle_, false);
118 CapFloor::Type capFloorType = atm > strike_ ? CapFloor::Floor : CapFloor::Cap;
119 capFloor_ = MakeOISCapFloor(capFloorType, tenor_, index_, rateComputationPeriod_, strike_)
120 .withTelescopicValueDates(true)
121 .withEffectiveDate(effectiveDate_);
122 capFloorCopy_ = MakeOISCapFloor(capFloorType, tenor_, index_, rateComputationPeriod_, strike_)
123 .withTelescopicValueDates(true)
124 .withEffectiveDate(effectiveDate_);
125 for (auto const& c : capFloor_) {
126 auto cpn = QuantLib::ext::dynamic_pointer_cast<Coupon>(c);
127 }
128 }
129
130 QuantLib::ext::shared_ptr<OptionletVolatilityStructure> temp(ovts, null_deleter());
131 ovtsHandle_.linkTo(temp, false);
132 RelativeDateBootstrapHelper<OptionletVolatilityStructure>::setTermStructure(ovts);
133
134 auto pricer = QuantLib::ext::make_shared<BlackOvernightIndexedCouponPricer>(ovtsHandle_);
135 for (auto c : capFloor_) {
136 auto f = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(c);
137 if (f) {
138 f->setPricer(pricer);
139 }
140 }
141
142 // If the quote type is not a premium, we will need to use capFloorCopy_ to return the premium from the volatility
143 // quote
145 Handle<OptionletVolatilityStructure> constOvts;
146 if (quoteVolatilityType_ == ShiftedLognormal) {
147 constOvts = Handle<OptionletVolatilityStructure>(QuantLib::ext::make_shared<ConstantOptionletVolatility>(
148 0, NullCalendar(), Unadjusted, rawQuote_, Actual365Fixed(), ShiftedLognormal, quoteDisplacement_));
149 } else {
150 constOvts = Handle<OptionletVolatilityStructure>(QuantLib::ext::make_shared<ConstantOptionletVolatility>(
151 0, NullCalendar(), Unadjusted, rawQuote_, Actual365Fixed(), Normal));
152 }
153 auto pricer = QuantLib::ext::make_shared<BlackOvernightIndexedCouponPricer>(constOvts, true);
154 for (auto c : capFloorCopy_) {
155 auto f = QuantLib::ext::dynamic_pointer_cast<FloatingRateCoupon>(c);
156 if (f) {
157 f->setPricer(pricer);
158 }
159 }
160 }
161}
QuantLib::RelinkableHandle< QuantLib::OptionletVolatilityStructure > ovtsHandle_
Leg getOisCapFloorUnderlying(const Leg &oisCapFloor)
get the underlying ON coupons from an OIS cf
+ Here is the call graph for this function:

◆ impliedQuote()

Real impliedQuote ( ) const
override

Definition at line 163 of file oiscapfloorhelper.cpp.

163 {
164 QL_REQUIRE(termStructure_ != 0, "CapFloorHelper's optionlet volatility term structure has not been set");
165 for (auto c : capFloor_) {
166 auto f = QuantLib::ext::dynamic_pointer_cast<LazyObject>(c);
167 if (f) {
168 f->deepUpdate();
169 }
170 }
171 return CashFlows::npv(capFloor_, **discountHandle_, false);
172}

◆ accept()

void accept ( QuantLib::AcyclicVisitor &  )
override

Definition at line 174 of file oiscapfloorhelper.cpp.

174 {
175 if (Visitor<OISCapFloorHelper>* v1 = dynamic_cast<Visitor<OISCapFloorHelper>*>(&v))
176 v1->visit(*this);
177 else
178 RelativeDateBootstrapHelper<OptionletVolatilityStructure>::accept(v);
179}

◆ initializeDates()

void initializeDates ( )
overrideprivate

Definition at line 67 of file oiscapfloorhelper.cpp.

67 {
68
69 if (!initialised_ || moving_) {
70
71 Date today = Settings::instance().evaluationDate();
72
73 CapFloor::Type capFloorType = type_ == CapFloorHelper::Cap ? CapFloor::Cap : CapFloor::Floor;
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_ = MakeOISCapFloor(capFloorType, tenor_, index_, rateComputationPeriod_, dummyStrike)
79 .withEffectiveDate(effectiveDate_)
80 .withTelescopicValueDates(true);
81 capFloorCopy_ = MakeOISCapFloor(capFloorType, tenor_, index_, rateComputationPeriod_, dummyStrike)
82 .withEffectiveDate(effectiveDate_)
83 .withTelescopicValueDates(true);
84
85 QL_REQUIRE(!capFloor_.empty(), "OISCapFloorHelper: got empty leg.");
86
87 maturityDate_ = CashFlows::maturityDate(capFloor_);
88
89 // Earliest date is the first optionlet fixing date
90 auto cfon = QuantLib::ext::dynamic_pointer_cast<CappedFlooredOvernightIndexedCoupon>(capFloor_.front());
91 QL_REQUIRE(cfon, "OISCapFloorHelper: Expected the first cashflow on the ois cap floor instrument to be a "
92 "CappedFlooredOvernightIndexedCoupon");
93 earliestDate_ = std::max(today, cfon->underlying()->fixingDates().front());
94
95 // Remaining dates are each equal to the fixing date on the final optionlet
96 auto cfon2 = QuantLib::ext::dynamic_pointer_cast<CappedFlooredOvernightIndexedCoupon>(capFloor_.back());
97 QL_REQUIRE(cfon2, "OISCapFloorHelper: Expected the final cashflow on the cap floor instrument to be a "
98 "CappedFlooredOvernightIndexedCoupon");
99 pillarDate_ = latestDate_ = latestRelevantDate_ = cfon2->underlying()->fixingDates().back();
100 }
101}
+ Here is the call graph for this function:
+ 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 181 of file oiscapfloorhelper.cpp.

181 {
183 return quoteValue;
184 } else {
185 // If the quote value is a volatility, return the premium
186 return CashFlows::npv(capFloorCopy_, **discountHandle_, false);
187 }
188}

Member Data Documentation

◆ type_

CapFloorHelper::Type type_
private

Definition at line 56 of file oiscapfloorhelper.hpp.

◆ tenor_

QuantLib::Period tenor_
private

Definition at line 57 of file oiscapfloorhelper.hpp.

◆ rateComputationPeriod_

QuantLib::Period rateComputationPeriod_
private

Definition at line 58 of file oiscapfloorhelper.hpp.

◆ strike_

QuantLib::Rate strike_
private

Definition at line 59 of file oiscapfloorhelper.hpp.

◆ index_

QuantLib::ext::shared_ptr<QuantLib::OvernightIndex> index_
private

Definition at line 60 of file oiscapfloorhelper.hpp.

◆ discountHandle_

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

Definition at line 61 of file oiscapfloorhelper.hpp.

◆ moving_

bool moving_
private

Definition at line 62 of file oiscapfloorhelper.hpp.

◆ effectiveDate_

QuantLib::Date effectiveDate_
private

Definition at line 63 of file oiscapfloorhelper.hpp.

◆ quoteType_

CapFloorHelper::QuoteType quoteType_
private

Definition at line 64 of file oiscapfloorhelper.hpp.

◆ quoteVolatilityType_

QuantLib::VolatilityType quoteVolatilityType_
private

Definition at line 65 of file oiscapfloorhelper.hpp.

◆ quoteDisplacement_

QuantLib::Real quoteDisplacement_
private

Definition at line 66 of file oiscapfloorhelper.hpp.

◆ rawQuote_

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

Definition at line 67 of file oiscapfloorhelper.hpp.

◆ initialised_

bool initialised_
private

Definition at line 68 of file oiscapfloorhelper.hpp.

◆ capFloor_

Leg capFloor_
private

Definition at line 70 of file oiscapfloorhelper.hpp.

◆ ovtsHandle_

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

Definition at line 71 of file oiscapfloorhelper.hpp.

◆ capFloorCopy_

Leg capFloorCopy_
private

Definition at line 72 of file oiscapfloorhelper.hpp.