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

#include <qle/termstructures/optionletstripper1.hpp>

+ Inheritance diagram for OptionletStripper1:
+ Collaboration diagram for OptionletStripper1:

Public Member Functions

 OptionletStripper1 (const QuantLib::ext::shared_ptr< QuantExt::CapFloorTermVolSurface > &, const QuantLib::ext::shared_ptr< IborIndex > &index, Rate switchStrikes=Null< Rate >(), Real accuracy=1.0e-6, Natural maxIter=100, const Handle< YieldTermStructure > &discount=Handle< YieldTermStructure >(), const VolatilityType type=ShiftedLognormal, const Real displacement=0.0, const optional< VolatilityType > targetVolatilityType=boost::none, const optional< Real > targetDisplacement=boost::none)
 
const Matrix & capFloorPrices () const
 
const Matrix & capletVols () const
 
const Matrix & capFloorVolatilities () const
 
const Matrix & optionletPrices () const
 
Rate switchStrike () const
 
const Handle< YieldTermStructure > & discountCurve () const
 
- Public Member Functions inherited from OptionletStripper
const std::vector< Rate > & optionletStrikes (Size i) const override
 
const std::vector< Volatility > & optionletVolatilities (Size i) const override
 
const std::vector< Date > & optionletFixingDates () const override
 
const std::vector< Time > & optionletFixingTimes () const override
 
Size optionletMaturities () const override
 
const std::vector< Rate > & atmOptionletRates () const override
 
DayCounter dayCounter () const override
 
Calendar calendar () const override
 
Natural settlementDays () const override
 
BusinessDayConvention businessDayConvention () const override
 
const std::vector< Period > & optionletFixingTenors () const
 
const std::vector< Date > & optionletPaymentDates () const
 
const std::vector< Time > & optionletAccrualPeriods () const
 
ext::shared_ptr< CapFloorTermVolSurfacetermVolSurface () const
 
ext::shared_ptr< IborIndex > index () const
 
Real displacement () const override
 
VolatilityType volatilityType () const override
 
const Period & rateComputationPeriod () const
 

LazyObject interface

Matrix capFloorPrices_
 
Matrix optionletPrices_
 
Matrix capFloorVols_
 
Matrix optionletStDevs_
 
Matrix capletVols_
 
CapFloorMatrix capFloors_
 
std::vector< std::vector< QuantLib::ext::shared_ptr< SimpleQuote > > > volQuotes_
 
std::vector< std::vector< QuantLib::ext::shared_ptr< PricingEngine > > > capFloorEngines_
 
bool floatingSwitchStrike_
 
bool capFlooMatrixNotInitialized_
 
Rate switchStrike_
 
Real accuracy_
 
Natural maxIter_
 
const VolatilityType inputVolatilityType_
 
const Real inputDisplacement_
 
void performCalculations () const override
 
bool stripOptionlets (std::vector< Real > &, CapFloor::Type, Size, const Handle< YieldTermStructure > &, Real) const
 

Additional Inherited Members

- Protected Member Functions inherited from OptionletStripper
 OptionletStripper (const ext::shared_ptr< QuantExt::CapFloorTermVolSurface > &, const ext::shared_ptr< IborIndex > &index, const Handle< YieldTermStructure > &discount=Handle< YieldTermStructure >(), const VolatilityType type=ShiftedLognormal, const Real displacement=0.0, const Period &rateComputationPeriod=0 *Days, const Size onCapSettlementDays=0)
 
virtual void populateDates () const
 Method to populate the dates, times and accruals that can be overridden in derived classes. More...
 
- Protected Attributes inherited from OptionletStripper
ext::shared_ptr< CapFloorTermVolSurfacetermVolSurface_
 
ext::shared_ptr< IborIndex > index_
 
Handle< YieldTermStructure > discount_
 
Size nStrikes_
 
Size nOptionletTenors_
 
std::vector< std::vector< Rate > > optionletStrikes_
 
std::vector< std::vector< Volatility > > optionletVolatilities_
 
std::vector< Time > optionletTimes_
 
std::vector< Date > optionletDates_
 
std::vector< Period > optionletTenors_
 
std::vector< Rate > atmOptionletRate_
 
std::vector< Date > optionletPaymentDates_
 
std::vector< Time > optionletAccrualPeriods_
 
std::vector< Period > capFloorLengths_
 
const VolatilityType volatilityType_
 
const Real displacement_
 
const Period rateComputationPeriod_
 
const Size onCapSettlementDays_
 

Detailed Description

Helper class to strip optionlet (i.e. caplet/floorlet) volatilities (a.k.a. forward-forward volatilities) from the (cap/floor) term volatilities of a CapFloorTermVolSurface.

Definition at line 44 of file optionletstripper1.hpp.

Constructor & Destructor Documentation

◆ OptionletStripper1()

OptionletStripper1 ( const QuantLib::ext::shared_ptr< QuantExt::CapFloorTermVolSurface > &  ,
const QuantLib::ext::shared_ptr< IborIndex > &  index,
Rate  switchStrikes = Null<Rate>(),
Real  accuracy = 1.0e-6,
Natural  maxIter = 100,
const Handle< YieldTermStructure > &  discount = Handle<YieldTermStructure>(),
const VolatilityType  type = ShiftedLognormal,
const Real  displacement = 0.0,
const optional< VolatilityType >  targetVolatilityType = boost::none,
const optional< Real >  targetDisplacement = boost::none 
)

Definition at line 33 of file optionletstripper1.cpp.

39 : OptionletStripper(termVolSurface, index, discount, targetVolatilityType ? *targetVolatilityType : type,
40 targetDisplacement ? *targetDisplacement : displacement),
41 volQuotes_(nOptionletTenors_, std::vector<shared_ptr<SimpleQuote> >(nStrikes_)),
42 floatingSwitchStrike_(switchStrike == Null<Rate>() ? true : false), capFlooMatrixNotInitialized_(true),
45
50
51 Real firstGuess = 0.14; // guess is only used for shifted lognormal vols
52 optionletStDevs_ = Matrix(nOptionletTenors_, nStrikes_, firstGuess);
53
55 capFloorEngines_ = std::vector<std::vector<QuantLib::ext::shared_ptr<PricingEngine> > >(nOptionletTenors_);
56}
std::vector< std::vector< QuantLib::ext::shared_ptr< SimpleQuote > > > volQuotes_
std::vector< std::vector< QuantLib::ext::shared_ptr< PricingEngine > > > capFloorEngines_
const VolatilityType inputVolatilityType_
ext::shared_ptr< CapFloorTermVolSurface > termVolSurface() const
OptionletStripper(const ext::shared_ptr< QuantExt::CapFloorTermVolSurface > &, const ext::shared_ptr< IborIndex > &index, const Handle< YieldTermStructure > &discount=Handle< YieldTermStructure >(), const VolatilityType type=ShiftedLognormal, const Real displacement=0.0, const Period &rateComputationPeriod=0 *Days, const Size onCapSettlementDays=0)
Real displacement() const override
ext::shared_ptr< IborIndex > index() const
std::vector< std::vector< QuantLib::ext::shared_ptr< QuantLib::CapFloor > > > CapFloorMatrix

Member Function Documentation

◆ capFloorPrices()

const Matrix & capFloorPrices ( ) const

Definition at line 189 of file optionletstripper1.cpp.

189 {
190 calculate();
191 return capFloorPrices_;
192}

◆ capletVols()

const Matrix & capletVols ( ) const

Definition at line 184 of file optionletstripper1.cpp.

184 {
185 calculate();
186 return capletVols_;
187}

◆ capFloorVolatilities()

const Matrix & capFloorVolatilities ( ) const

Definition at line 194 of file optionletstripper1.cpp.

194 {
195 calculate();
196 return capFloorVols_;
197}

◆ optionletPrices()

const Matrix & optionletPrices ( ) const

Definition at line 199 of file optionletstripper1.cpp.

199 {
200 calculate();
201 return optionletPrices_;
202}

◆ switchStrike()

Rate switchStrike ( ) const

Definition at line 204 of file optionletstripper1.cpp.

204 {
206 calculate();
207 return switchStrike_;
208}

◆ discountCurve()

const Handle< YieldTermStructure > & discountCurve ( ) const

Definition at line 60 of file optionletstripper1.hpp.

60{ return discount_; }
Handle< YieldTermStructure > discount_
+ Here is the caller graph for this function:

◆ performCalculations()

void performCalculations ( ) const
override

Definition at line 58 of file optionletstripper1.cpp.

58 {
59
60 // update dates
62
64 Rate averageAtmOptionletRate = 0.0;
65 for (Size i = 0; i < nOptionletTenors_; ++i) {
66 averageAtmOptionletRate += atmOptionletRate_[i];
67 }
68 switchStrike_ = averageAtmOptionletRate / nOptionletTenors_;
69 }
70
71 const Handle<YieldTermStructure>& discountCurve =
72 discount_.empty() ? index_->forwardingTermStructure() : discount_;
73
74 const std::vector<Rate>& strikes = termVolSurface_->strikes();
75 DayCounter dc = termVolSurface_->dayCounter();
76 // initialize CapFloorMatrix
78 for (Size i = 0; i < nOptionletTenors_; ++i) {
79 capFloors_[i].resize(nStrikes_);
80 capFloorEngines_[i].resize(nStrikes_);
81 }
82 // construction might go here
83 for (Size j = 0; j < nStrikes_; ++j) {
84 for (Size i = 0; i < nOptionletTenors_; ++i) {
85 volQuotes_[i][j] = shared_ptr<SimpleQuote>(new SimpleQuote());
86 if (inputVolatilityType_ == ShiftedLognormal) {
87 capFloorEngines_[i][j] = QuantLib::ext::make_shared<BlackCapFloorEngine>(
88 discountCurve, Handle<Quote>(volQuotes_[i][j]), dc, inputDisplacement_);
89 } else if (inputVolatilityType_ == Normal) {
90 capFloorEngines_[i][j] =
91 QuantLib::ext::make_shared<BachelierCapFloorEngine>(discountCurve, Handle<Quote>(volQuotes_[i][j]), dc);
92 } else {
93 QL_FAIL("unknown volatility type: " << volatilityType_);
94 }
95 }
96 }
98 }
99
100 for (Size j = 0; j < nStrikes_; ++j) {
101 // using out-of-the-money options - but these are not always out of the money, for different tenors we may need
102 // to switch
103 CapFloor::Type capFloorType = strikes[j] < switchStrike_ ? CapFloor::Floor : CapFloor::Cap;
104
105 // we do this with the above to keep the variables capFloors_ etc consistent, but really its the
106 // optionletStdDevs_ below that we want.
107 Real previousCapFloorPrice = 0.0;
108 for (Size i = 0; i < nOptionletTenors_; ++i) {
109
110 capFloorVols_[i][j] = termVolSurface_->volatility(capFloorLengths_[i], strikes[j], true);
111 volQuotes_[i][j]->setValue(capFloorVols_[i][j]);
112 capFloors_[i][j] = MakeCapFloor(capFloorType, capFloorLengths_[i], index_, strikes[j], -0 * Days)
113 .withPricingEngine(capFloorEngines_[i][j]);
114 capFloorPrices_[i][j] = capFloors_[i][j]->NPV();
115 optionletPrices_[i][j] = capFloorPrices_[i][j] - previousCapFloorPrice;
116 previousCapFloorPrice = capFloorPrices_[i][j];
117 }
118
119 // now try to strip
120 std::vector<Real> optionletStrip(nOptionletTenors_);
121 Real firstGuess = optionletStDevs_[0][j]; // assumes we have a constant first guess here (as we do)
122 bool ok = stripOptionlets(optionletStrip, capFloorType, j, discountCurve, firstGuess);
123 if (!ok) {
124 // try the reverse
125 capFloorType = capFloorType == CapFloor::Cap ? CapFloor::Floor : CapFloor::Cap;
126 ok = stripOptionlets(optionletStrip, capFloorType, j, discountCurve, firstGuess);
127 QL_REQUIRE(ok, "Failed to strip Caplet vols");
128 }
129 // now copy
130 for (Size i = 0; i < nOptionletTenors_; ++i) {
131 optionletStDevs_[i][j] = optionletStrip[i];
132 optionletVolatilities_[i][j] = optionletStDevs_[i][j] / std::sqrt(optionletTimes_[i]);
133 }
134 }
135}
bool stripOptionlets(std::vector< Real > &, CapFloor::Type, Size, const Handle< YieldTermStructure > &, Real) const
const Handle< YieldTermStructure > & discountCurve() const
std::vector< Rate > atmOptionletRate_
std::vector< std::vector< Volatility > > optionletVolatilities_
std::vector< Period > capFloorLengths_
std::vector< Time > optionletTimes_
const VolatilityType volatilityType_
virtual void populateDates() const
Method to populate the dates, times and accruals that can be overridden in derived classes.
ext::shared_ptr< CapFloorTermVolSurface > termVolSurface_
ext::shared_ptr< IborIndex > index_
vector< Real > strikes
+ Here is the call graph for this function:

◆ stripOptionlets()

bool stripOptionlets ( std::vector< Real > &  out,
CapFloor::Type  capFloorType,
Size  j,
const Handle< YieldTermStructure > &  discountCurve,
Real  firstGuess 
) const
private

Definition at line 137 of file optionletstripper1.cpp.

138 {
139
140 Real strike = termVolSurface_->strikes()[j];
141
142 // floor is put, cap is call
143 Option::Type optionletType = capFloorType == CapFloor::Floor ? Option::Put : Option::Call;
144
145 Real previousCapFloorPrice = 0.0;
146 for (Size i = 0; i < nOptionletTenors_; ++i) {
147
148 // we have capFloorVols_[i][j] & volQuotes_[i][j]
149 CapFloor capFloor = MakeCapFloor(capFloorType, capFloorLengths_[i], index_, strike, -0 * Days)
150 .withPricingEngine(capFloorEngines_[i][j]);
151 Real capFloorPrice = capFloor.NPV();
152 Real optionletPrice = std::max(0.0, capFloorPrice - previousCapFloorPrice);
153 previousCapFloorPrice = capFloorPrice;
154
155 DiscountFactor d = discountCurve->discount(optionletPaymentDates_[i]);
156 DiscountFactor optionletAnnuity = optionletAccrualPeriods_[i] * d;
157 try {
158 if (volatilityType_ == ShiftedLognormal) {
159 out[i] = blackFormulaImpliedStdDev(optionletType, strike, atmOptionletRate_[i], optionletPrice,
160 optionletAnnuity, displacement_, firstGuess, accuracy_, maxIter_);
161 } else if (volatilityType_ == Normal) {
162 out[i] = std::sqrt(optionletTimes_[i]) *
163 bachelierBlackFormulaImpliedVol(optionletType, strike, atmOptionletRate_[i],
164 optionletTimes_[i], optionletPrice, optionletAnnuity);
165 } else {
166 QL_FAIL("Unknown target volatility type: " << volatilityType_);
167 }
168 } catch (std::exception& /*e*/) {
169 /*
170 QL_FAIL("could not bootstrap optionlet:"
171 << "\n type: " << optionletType
172 << "\n strike: " << io::rate(strike)
173 << "\n atm: " << io::rate(atmOptionletRate_[i])
174 << "\n price: " << optionletPrice << "\n annuity: " << optionletAnnuity
175 << "\n expiry: " << optionletDates_[i] << "\n error: " << e.what());
176 */
177 // No need to wipe the output (?)
178 return false;
179 }
180 }
181 return true;
182}
std::vector< Date > optionletPaymentDates_
std::vector< Time > optionletAccrualPeriods_
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ capFloorPrices_

Matrix capFloorPrices_
mutableprivate

Definition at line 69 of file optionletstripper1.hpp.

◆ optionletPrices_

Matrix optionletPrices_
private

Definition at line 69 of file optionletstripper1.hpp.

◆ capFloorVols_

Matrix capFloorVols_
mutableprivate

Definition at line 70 of file optionletstripper1.hpp.

◆ optionletStDevs_

Matrix optionletStDevs_
mutableprivate

Definition at line 71 of file optionletstripper1.hpp.

◆ capletVols_

Matrix capletVols_
private

Definition at line 71 of file optionletstripper1.hpp.

◆ capFloors_

CapFloorMatrix capFloors_
mutableprivate

Definition at line 73 of file optionletstripper1.hpp.

◆ volQuotes_

std::vector<std::vector<QuantLib::ext::shared_ptr<SimpleQuote> > > volQuotes_
mutableprivate

Definition at line 74 of file optionletstripper1.hpp.

◆ capFloorEngines_

std::vector<std::vector<QuantLib::ext::shared_ptr<PricingEngine> > > capFloorEngines_
mutableprivate

Definition at line 75 of file optionletstripper1.hpp.

◆ floatingSwitchStrike_

bool floatingSwitchStrike_
private

Definition at line 76 of file optionletstripper1.hpp.

◆ capFlooMatrixNotInitialized_

bool capFlooMatrixNotInitialized_
mutableprivate

Definition at line 77 of file optionletstripper1.hpp.

◆ switchStrike_

Rate switchStrike_
mutableprivate

Definition at line 78 of file optionletstripper1.hpp.

◆ accuracy_

Real accuracy_
private

Definition at line 79 of file optionletstripper1.hpp.

◆ maxIter_

Natural maxIter_
private

Definition at line 80 of file optionletstripper1.hpp.

◆ inputVolatilityType_

const VolatilityType inputVolatilityType_
private

Definition at line 81 of file optionletstripper1.hpp.

◆ inputDisplacement_

const Real inputDisplacement_
private

Definition at line 82 of file optionletstripper1.hpp.