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

#include <qle/termstructures/optionletstripper2.hpp>

+ Inheritance diagram for OptionletStripper2:
+ Collaboration diagram for OptionletStripper2:

Classes

class  ObjectiveFunction
 

Public Member Functions

 OptionletStripper2 (const QuantLib::ext::shared_ptr< QuantExt::OptionletStripper > &optionletStripper, const Handle< QuantLib::CapFloorTermVolCurve > &atmCapFloorTermVolCurve, const Handle< YieldTermStructure > &discount=Handle< YieldTermStructure >(), const VolatilityType type=ShiftedLognormal, const Real displacement=0.0)
 
vector< Rate > atmCapFloorStrikes () const
 
vector< Real > atmCapFloorPrices () const
 
vector< Volatility > spreadsVol () 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

const QuantLib::ext::shared_ptr< QuantExt::OptionletStripperstripper_
 
const Handle< QuantLib::CapFloorTermVolCurve > atmCapFloorTermVolCurve_
 
DayCounter dc_
 
Size nOptionExpiries_
 
vector< Rate > atmCapFloorStrikes_
 
vector< Real > atmCapFloorPrices_
 
vector< Volatility > spreadsVolImplied_
 
vector< QuantLib::ext::shared_ptr< QuantLib::CapFloor > > caps_
 
Size maxEvaluations_
 
Real accuracy_
 
const VolatilityType inputVolatilityType_
 
const Real inputDisplacement_
 
void performCalculations () const override
 
vector< Volatility > spreadsVolImplied (const Handle< YieldTermStructure > &discount) 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 extend a QuantExt::OptionletStripper object stripping additional optionlet (i.e. caplet/floorlet) volatilities (a.k.a. forward-forward volatilities) from the (cap/floor) At-The-Money term volatilities of a CapFloorTermVolCurve.

Definition at line 41 of file optionletstripper2.hpp.

Constructor & Destructor Documentation

◆ OptionletStripper2()

OptionletStripper2 ( const QuantLib::ext::shared_ptr< QuantExt::OptionletStripper > &  optionletStripper,
const Handle< QuantLib::CapFloorTermVolCurve > &  atmCapFloorTermVolCurve,
const Handle< YieldTermStructure > &  discount = Handle<YieldTermStructure>(),
const VolatilityType  type = ShiftedLognormal,
const Real  displacement = 0.0 
)

Optionlet stripper that modifies the stripped optionlets from optionletStripper by adding optionlet volatilities stripped from an ATM volatility curve atmCapFloorTermVolCurve

Definition at line 32 of file optionletstripper2.cpp.

36 : OptionletStripper(optionletStripper->termVolSurface(), optionletStripper->index(), discount,
37 optionletStripper->volatilityType(), optionletStripper->displacement()),
38 stripper_(optionletStripper), atmCapFloorTermVolCurve_(atmCapFloorTermVolCurve),
39 dc_(stripper_->termVolSurface()->dayCounter()), nOptionExpiries_(atmCapFloorTermVolCurve->optionTenors().size()),
43
44 registerWith(stripper_);
45 registerWith(atmCapFloorTermVolCurve_);
46
47 QL_REQUIRE(dc_ == atmCapFloorTermVolCurve->dayCounter(), "different day counters provided");
48}
const Handle< QuantLib::CapFloorTermVolCurve > atmCapFloorTermVolCurve_
const QuantLib::ext::shared_ptr< QuantExt::OptionletStripper > stripper_
vector< Volatility > spreadsVolImplied_
vector< QuantLib::ext::shared_ptr< QuantLib::CapFloor > > caps_
const VolatilityType inputVolatilityType_
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

Member Function Documentation

◆ atmCapFloorStrikes()

vector< Rate > atmCapFloorStrikes ( ) const

Definition at line 142 of file optionletstripper2.cpp.

142 {
143 calculate();
144 return atmCapFloorStrikes_;
145}

◆ atmCapFloorPrices()

vector< Real > atmCapFloorPrices ( ) const

Definition at line 147 of file optionletstripper2.cpp.

147 {
148 calculate();
149 return atmCapFloorPrices_;
150}

◆ spreadsVol()

vector< Volatility > spreadsVol ( ) const

Definition at line 137 of file optionletstripper2.cpp.

137 {
138 calculate();
139 return spreadsVolImplied_;
140}

◆ performCalculations()

void performCalculations ( ) const
override

Definition at line 50 of file optionletstripper2.cpp.

50 {
51
52 // optionletStripper data
53 optionletDates_ = stripper_->optionletFixingDates();
54 optionletPaymentDates_ = stripper_->optionletPaymentDates();
55 optionletAccrualPeriods_ = stripper_->optionletAccrualPeriods();
56 optionletTimes_ = stripper_->optionletFixingTimes();
57 atmOptionletRate_ = stripper_->atmOptionletRates();
58 for (Size i = 0; i < optionletTimes_.size(); ++i) {
59 optionletStrikes_[i] = stripper_->optionletStrikes(i);
60 optionletVolatilities_[i] = stripper_->optionletVolatilities(i);
61 }
62
63 // atmCapFloorTermVolCurve data
64 const vector<Period>& optionExpiriesTenors = atmCapFloorTermVolCurve_->optionTenors();
65 const vector<Time>& optionExpiriesTimes = atmCapFloorTermVolCurve_->optionTimes();
66
67 // discount curve
68 const Handle<YieldTermStructure>& discountCurve =
69 discount_.empty() ? index_->forwardingTermStructure() : discount_;
70
71 for (Size j = 0; j < nOptionExpiries_; ++j) {
72 // Dummy strike, doesn't get used for ATM curve
73 Volatility atmOptionVol = atmCapFloorTermVolCurve_->volatility(optionExpiriesTimes[j], 33.3333);
74
75 // Create a cap for each pillar point on ATM curve and attach relevant pricing engine i.e. Black if
76 // quotes are shifted lognormal and Bachelier if quotes are normal
77 QuantLib::ext::shared_ptr<PricingEngine> engine;
78 if (inputVolatilityType_ == ShiftedLognormal) {
79 engine = QuantLib::ext::make_shared<BlackCapFloorEngine>(discountCurve, atmOptionVol, dc_, inputDisplacement_);
80 } else if (inputVolatilityType_ == Normal) {
81 engine = QuantLib::ext::make_shared<BachelierCapFloorEngine>(discountCurve, atmOptionVol, dc_);
82 } else {
83 QL_FAIL("unknown volatility type: " << volatilityType_);
84 }
85
86 // Using Null<Rate>() as strike => strike will be set to ATM rate. However, to calculate ATM rate, QL requires
87 // a BlackCapFloorEngine to be set (not a BachelierCapFloorEngine)! So, need a temp BlackCapFloorEngine with a
88 // dummy vol to calculate ATM rate. Needs to be fixed in QL.
89 QuantLib::ext::shared_ptr<PricingEngine> tempEngine = QuantLib::ext::make_shared<BlackCapFloorEngine>(discountCurve, 0.01);
90 caps_[j] = MakeCapFloor(CapFloor::Cap, optionExpiriesTenors[j], index_, Null<Rate>(), 0 * Days)
91 .withPricingEngine(tempEngine);
92
93 // Now set correct engine and get the ATM rate and the price
94 caps_[j]->setPricingEngine(engine);
95 atmCapFloorStrikes_[j] = caps_[j]->atmRate(**discountCurve);
96 atmCapFloorPrices_[j] = caps_[j]->NPV();
97 }
98
100
101 StrippedOptionletAdapter adapter(stripper_);
102 adapter.enableExtrapolation();
103
104 Volatility unadjustedVol, adjustedVol;
105 for (Size j = 0; j < nOptionExpiries_; ++j) {
106 for (Size i = 0; i < optionletVolatilities_.size(); ++i) {
107 if (i <= caps_[j]->floatingLeg().size()) {
108 unadjustedVol = adapter.volatility(optionletTimes_[i], atmCapFloorStrikes_[j]);
109 adjustedVol = unadjustedVol + spreadsVolImplied_[j];
110
111 // insert adjusted volatility
112 vector<Rate>::const_iterator previous =
113 lower_bound(optionletStrikes_[i].begin(), optionletStrikes_[i].end(), atmCapFloorStrikes_[j]);
114 Size insertIndex = previous - optionletStrikes_[i].begin();
115
116 optionletStrikes_[i].insert(optionletStrikes_[i].begin() + insertIndex, atmCapFloorStrikes_[j]);
117 optionletVolatilities_[i].insert(optionletVolatilities_[i].begin() + insertIndex, adjustedVol);
118 }
119 }
120 }
121}
vector< Volatility > spreadsVolImplied(const Handle< YieldTermStructure > &discount) const
std::vector< Rate > atmOptionletRate_
std::vector< std::vector< Volatility > > optionletVolatilities_
Handle< YieldTermStructure > discount_
std::vector< Date > optionletPaymentDates_
std::vector< Time > optionletAccrualPeriods_
std::vector< Time > optionletTimes_
std::vector< Date > optionletDates_
const VolatilityType volatilityType_
std::vector< std::vector< Rate > > optionletStrikes_
ext::shared_ptr< IborIndex > index_
+ Here is the call graph for this function:

◆ spreadsVolImplied()

vector< Volatility > spreadsVolImplied ( const Handle< YieldTermStructure > &  discount) const
private

Definition at line 123 of file optionletstripper2.cpp.

123 {
124
125 Brent solver;
126 vector<Volatility> result(nOptionExpiries_);
127 Volatility guess = 0.0001, minSpread = -0.1, maxSpread = 0.1;
128 for (Size j = 0; j < nOptionExpiries_; ++j) {
129 ObjectiveFunction f(stripper_, caps_[j], atmCapFloorPrices_[j], discount);
130 solver.setMaxEvaluations(maxEvaluations_);
131 Volatility root = solver.solve(f, accuracy_, guess, minSpread, maxSpread);
132 result[j] = root;
133 }
134 return result;
135}
+ Here is the caller graph for this function:

Member Data Documentation

◆ stripper_

const QuantLib::ext::shared_ptr<QuantExt::OptionletStripper> stripper_
private

Definition at line 76 of file optionletstripper2.hpp.

◆ atmCapFloorTermVolCurve_

const Handle<QuantLib::CapFloorTermVolCurve> atmCapFloorTermVolCurve_
private

Definition at line 77 of file optionletstripper2.hpp.

◆ dc_

DayCounter dc_
private

Definition at line 78 of file optionletstripper2.hpp.

◆ nOptionExpiries_

Size nOptionExpiries_
private

Definition at line 79 of file optionletstripper2.hpp.

◆ atmCapFloorStrikes_

vector<Rate> atmCapFloorStrikes_
mutableprivate

Definition at line 80 of file optionletstripper2.hpp.

◆ atmCapFloorPrices_

vector<Real> atmCapFloorPrices_
mutableprivate

Definition at line 81 of file optionletstripper2.hpp.

◆ spreadsVolImplied_

vector<Volatility> spreadsVolImplied_
mutableprivate

Definition at line 82 of file optionletstripper2.hpp.

◆ caps_

vector<QuantLib::ext::shared_ptr<QuantLib::CapFloor> > caps_
mutableprivate

Definition at line 83 of file optionletstripper2.hpp.

◆ maxEvaluations_

Size maxEvaluations_
private

Definition at line 84 of file optionletstripper2.hpp.

◆ accuracy_

Real accuracy_
private

Definition at line 85 of file optionletstripper2.hpp.

◆ inputVolatilityType_

const VolatilityType inputVolatilityType_
private

Definition at line 86 of file optionletstripper2.hpp.

◆ inputDisplacement_

const Real inputDisplacement_
private

Definition at line 87 of file optionletstripper2.hpp.