Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
List of all members
OptionletStripper Class Reference

#include <qle/termstructures/optionletstripper.hpp>

+ Inheritance diagram for OptionletStripper:
+ Collaboration diagram for OptionletStripper:

StrippedOptionletBase interface

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_
 
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
 
 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...
 

Detailed Description

Copy of the QL class that uses an QuantExt::CapFloorTermVolSurface to support BiLinearInterpolation

Definition at line 41 of file optionletstripper.hpp.

Constructor & Destructor Documentation

◆ 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 
)
protected

Definition at line 30 of file optionletstripper.cpp.

38 onCapSettlementDays_(onCapSettlementDays) {
39
40 bool isOis = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(index_) != nullptr;
41
42 QL_REQUIRE(!isOis || rateComputationPeriod != 0 * Days,
43 "OptionletStripper: For an OIS index the rateComputationPeriod must be given");
44 QL_REQUIRE(isOis || rateComputationPeriod == 0 * Days || rateComputationPeriod == index_->tenor(),
45 "OptionletStripper: For an Ibor index the Ibor tenor ("
46 << index_->tenor() << ") must match the rateComputationPeriod (" << rateComputationPeriod
47 << ") if the latter is given.");
48
49 if (volatilityType_ == Normal) {
50 QL_REQUIRE(displacement_ == 0.0, "non-null displacement is not allowed with Normal model");
51 }
52
53 registerWith(termVolSurface);
54 registerWith(index_);
55 registerWith(discount_);
56 registerWith(Settings::instance().evaluationDate());
57
58 QL_REQUIRE(termVolSurface->optionTenors().size() > 0, "OptionletStripper: No OptionTenors provided.");
59 Period maxCapFloorTenor = termVolSurface->optionTenors().back();
60
61 // optionlet tenors and capFloor lengths
63 capFloorLengths_.push_back(optionletTenors_.back() + (isOis ? 0 * Days : rateComputationPeriod_));
64 QL_REQUIRE(maxCapFloorTenor >= capFloorLengths_.back(),
65 "too short (" << maxCapFloorTenor << ") capfloor term vol termVolSurface");
66 Period nextCapFloorLength = capFloorLengths_.back() + rateComputationPeriod_;
67 while (nextCapFloorLength <= maxCapFloorTenor) {
68 if (capFloorLengths_.back() > optionletTenors_.back())
69 optionletTenors_.push_back(capFloorLengths_.back());
70 capFloorLengths_.push_back(nextCapFloorLength);
71 nextCapFloorLength += rateComputationPeriod_;
72 }
73 if(isOis)
74 optionletTenors_.push_back(capFloorLengths_.back());
76
77 optionletVolatilities_ = vector<vector<Volatility>>(nOptionletTenors_, vector<Volatility>(nStrikes_));
78 optionletStrikes_ = vector<vector<Rate>>(nOptionletTenors_, termVolSurface->strikes());
79 optionletDates_ = vector<Date>(nOptionletTenors_);
80 optionletTimes_ = vector<Time>(nOptionletTenors_);
84}
const Period & rateComputationPeriod() const
std::vector< Rate > atmOptionletRate_
std::vector< std::vector< Volatility > > optionletVolatilities_
std::vector< Period > capFloorLengths_
ext::shared_ptr< CapFloorTermVolSurface > termVolSurface() const
Handle< YieldTermStructure > discount_
std::vector< Date > optionletPaymentDates_
std::vector< Time > optionletAccrualPeriods_
std::vector< Period > optionletTenors_
std::vector< Time > optionletTimes_
std::vector< Date > optionletDates_
const VolatilityType volatilityType_
std::vector< std::vector< Rate > > optionletStrikes_
Real displacement() const override
ext::shared_ptr< IborIndex > index() const
ext::shared_ptr< CapFloorTermVolSurface > termVolSurface_
ext::shared_ptr< IborIndex > index_
+ Here is the call graph for this function:

Member Function Documentation

◆ optionletStrikes()

const vector< Rate > & optionletStrikes ( Size  i) const
override

Definition at line 86 of file optionletstripper.cpp.

86 {
87 calculate();
88 QL_REQUIRE(i < optionletStrikes_.size(),
89 "index (" << i << ") must be less than optionletStrikes size (" << optionletStrikes_.size() << ")");
90 return optionletStrikes_[i];
91}

◆ optionletVolatilities()

const vector< Volatility > & optionletVolatilities ( Size  i) const
override

Definition at line 93 of file optionletstripper.cpp.

93 {
94 calculate();
95 QL_REQUIRE(i < optionletVolatilities_.size(), "index (" << i << ") must be less than optionletVolatilities size ("
96 << optionletVolatilities_.size() << ")");
97 return optionletVolatilities_[i];
98}

◆ optionletFixingDates()

const vector< Date > & optionletFixingDates ( ) const
override

Definition at line 102 of file optionletstripper.cpp.

102 {
103 calculate();
104 return optionletDates_;
105}

◆ optionletFixingTimes()

const vector< Time > & optionletFixingTimes ( ) const
override

Definition at line 107 of file optionletstripper.cpp.

107 {
108 calculate();
109 return optionletTimes_;
110}

◆ optionletMaturities()

Size optionletMaturities ( ) const
override

Definition at line 112 of file optionletstripper.cpp.

112{ return optionletTenors_.size(); }

◆ atmOptionletRates()

const vector< Rate > & atmOptionletRates ( ) const
override

Definition at line 124 of file optionletstripper.cpp.

124 {
125 calculate();
126 return atmOptionletRate_;
127}

◆ dayCounter()

DayCounter dayCounter ( ) const
override

Definition at line 129 of file optionletstripper.cpp.

129{ return termVolSurface_->dayCounter(); }

◆ calendar()

Calendar calendar ( ) const
override

Definition at line 131 of file optionletstripper.cpp.

131{ return termVolSurface_->calendar(); }

◆ settlementDays()

Natural settlementDays ( ) const
override

Definition at line 133 of file optionletstripper.cpp.

133{ return termVolSurface_->settlementDays(); }

◆ businessDayConvention()

BusinessDayConvention businessDayConvention ( ) const
override

Definition at line 135 of file optionletstripper.cpp.

135 {
136 return termVolSurface_->businessDayConvention();
137}

◆ optionletFixingTenors()

const vector< Period > & optionletFixingTenors ( ) const

Definition at line 100 of file optionletstripper.cpp.

100{ return optionletTenors_; }

◆ optionletPaymentDates()

const vector< Date > & optionletPaymentDates ( ) const

Definition at line 114 of file optionletstripper.cpp.

114 {
115 calculate();
117}

◆ optionletAccrualPeriods()

const vector< Time > & optionletAccrualPeriods ( ) const

Definition at line 119 of file optionletstripper.cpp.

119 {
120 calculate();
122}

◆ termVolSurface()

ext::shared_ptr< CapFloorTermVolSurface > termVolSurface ( ) const

Definition at line 139 of file optionletstripper.cpp.

139{ return termVolSurface_; }
+ Here is the caller graph for this function:

◆ index()

ext::shared_ptr< IborIndex > index ( ) const

Definition at line 141 of file optionletstripper.cpp.

141{ return index_; }
+ Here is the caller graph for this function:

◆ displacement()

Real displacement ( ) const
override

Definition at line 143 of file optionletstripper.cpp.

143{ return displacement_; }

◆ volatilityType()

VolatilityType volatilityType ( ) const
override

Definition at line 145 of file optionletstripper.cpp.

145{ return volatilityType_; }

◆ rateComputationPeriod()

const Period & rateComputationPeriod ( ) const

Definition at line 147 of file optionletstripper.cpp.

147{ return rateComputationPeriod_; }
+ Here is the caller graph for this function:

◆ populateDates()

void populateDates ( ) const
protectedvirtual

Method to populate the dates, times and accruals that can be overridden in derived classes.

Definition at line 149 of file optionletstripper.cpp.

149 {
150
151 bool isOis = QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(index_) != nullptr;
152
153 Date referenceDate = termVolSurface_->referenceDate();
154 DayCounter dc = termVolSurface_->dayCounter();
155 QuantLib::ext::shared_ptr<BlackCapFloorEngine> dummyEngine =
156 QuantLib::ext::make_shared<BlackCapFloorEngine>(index_->forwardingTermStructure(), 0.20, dc);
157
158 for (Size i = 0; i < nOptionletTenors_; ++i) {
159 if (isOis) {
160 Leg dummyCap =
161 MakeOISCapFloor(CapFloor::Cap, capFloorLengths_[i], QuantLib::ext::dynamic_pointer_cast<OvernightIndex>(index_),
163 .withTelescopicValueDates(true)
164 .withSettlementDays(onCapSettlementDays_);
165 auto lastCoupon = QuantLib::ext::dynamic_pointer_cast<CappedFlooredOvernightIndexedCoupon>(dummyCap.back());
166 QL_REQUIRE(lastCoupon, "OptionletStripper::populateDates(): expected CappedFlooredOvernightIndexedCoupon");
167 optionletDates_[i] = std::max(referenceDate + 1, lastCoupon->underlying()->fixingDates().front());
168 optionletPaymentDates_[i] = lastCoupon->underlying()->date();
169 optionletAccrualPeriods_[i] = lastCoupon->underlying()->accrualPeriod();
170 optionletTimes_[i] = dc.yearFraction(referenceDate, optionletDates_[i]);
171 atmOptionletRate_[i] = lastCoupon->underlying()->rate();
172 } else {
173 CapFloor dummyCap =
174 MakeCapFloor(CapFloor::Cap, capFloorLengths_[i], index_, 0.04, 0 * Days).withPricingEngine(dummyEngine);
175 QuantLib::ext::shared_ptr<FloatingRateCoupon> lastCoupon = dummyCap.lastFloatingRateCoupon();
176 optionletDates_[i] = std::max(referenceDate + 1, lastCoupon->fixingDate());
177 optionletPaymentDates_[i] = lastCoupon->date();
178 optionletAccrualPeriods_[i] = lastCoupon->accrualPeriod();
179 optionletTimes_[i] = dc.yearFraction(referenceDate, optionletDates_[i]);
180 atmOptionletRate_[i] = lastCoupon->indexFixing();
181 }
182 QL_REQUIRE(i == 0 || optionletDates_[i] > optionletDates_[i - 1],
183 "OptionletStripper::populateDates(): got non-increasing optionletDates "
184 << optionletDates_[i - 1] << ", " << optionletDates_[i] << " for tenors "
185 << capFloorLengths_[i - 1] << ", " << capFloorLengths_[i] << " and index " << index_->name());
186 }
187}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ termVolSurface_

ext::shared_ptr<CapFloorTermVolSurface> termVolSurface_
protected

Definition at line 80 of file optionletstripper.hpp.

◆ index_

ext::shared_ptr<IborIndex> index_
protected

Definition at line 81 of file optionletstripper.hpp.

◆ discount_

Handle<YieldTermStructure> discount_
protected

Definition at line 82 of file optionletstripper.hpp.

◆ nStrikes_

Size nStrikes_
protected

Definition at line 83 of file optionletstripper.hpp.

◆ nOptionletTenors_

Size nOptionletTenors_
protected

Definition at line 84 of file optionletstripper.hpp.

◆ optionletStrikes_

std::vector<std::vector<Rate> > optionletStrikes_
mutableprotected

Definition at line 86 of file optionletstripper.hpp.

◆ optionletVolatilities_

std::vector<std::vector<Volatility> > optionletVolatilities_
mutableprotected

Definition at line 87 of file optionletstripper.hpp.

◆ optionletTimes_

std::vector<Time> optionletTimes_
mutableprotected

Definition at line 89 of file optionletstripper.hpp.

◆ optionletDates_

std::vector<Date> optionletDates_
mutableprotected

Definition at line 90 of file optionletstripper.hpp.

◆ optionletTenors_

std::vector<Period> optionletTenors_
protected

Definition at line 91 of file optionletstripper.hpp.

◆ atmOptionletRate_

std::vector<Rate> atmOptionletRate_
mutableprotected

Definition at line 92 of file optionletstripper.hpp.

◆ optionletPaymentDates_

std::vector<Date> optionletPaymentDates_
mutableprotected

Definition at line 93 of file optionletstripper.hpp.

◆ optionletAccrualPeriods_

std::vector<Time> optionletAccrualPeriods_
mutableprotected

Definition at line 94 of file optionletstripper.hpp.

◆ capFloorLengths_

std::vector<Period> capFloorLengths_
protected

Definition at line 96 of file optionletstripper.hpp.

◆ volatilityType_

const VolatilityType volatilityType_
protected

Definition at line 97 of file optionletstripper.hpp.

◆ displacement_

const Real displacement_
protected

Definition at line 98 of file optionletstripper.hpp.

◆ rateComputationPeriod_

const Period rateComputationPeriod_
protected

Definition at line 99 of file optionletstripper.hpp.

◆ onCapSettlementDays_

const Size onCapSettlementDays_
protected

Definition at line 100 of file optionletstripper.hpp.