Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | List of all members
StrippedOptionletAdapter< TimeInterpolator, SmileInterpolator > Class Template Reference

#include <qle/termstructures/strippedoptionletadapter.hpp>

+ Inheritance diagram for StrippedOptionletAdapter< TimeInterpolator, SmileInterpolator >:
+ Collaboration diagram for StrippedOptionletAdapter< TimeInterpolator, SmileInterpolator >:

Public Member Functions

 StrippedOptionletAdapter (const QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > &sob, const TimeInterpolator &ti=TimeInterpolator(), const SmileInterpolator &si=SmileInterpolator())
 
 StrippedOptionletAdapter (const QuantLib::Date &referenceDate, const QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > &sob, const TimeInterpolator &ti=TimeInterpolator(), const SmileInterpolator &si=SmileInterpolator())
 
TermStructure interface
QuantLib::Date maxDate () const override
 
VolatilityTermStructure interface
QuantLib::Rate minStrike () const override
 
QuantLib::Rate maxStrike () const override
 
LazyObject interface
void update () override
 
void performCalculations () const override
 
Observer interface
void deepUpdate () override
 
Inspectors
QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > optionletBase () const
 

OptionletVolatilityStructure interface

QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > optionletBase_
 Base optionlet object that provides the stripped optionlet volatilities. More...
 
TimeInterpolator ti_
 The interpolation object in the time direction. More...
 
SmileInterpolator si_
 The interpolation object in the strike direction. More...
 
std::vector< QuantLib::Interpolation > strikeSections_
 
bool oneStrike_
 Flag that indicates if optionletBase_ has only one strike for all option tenors. More...
 
QuantLib::VolatilityType volatilityType () const override
 
QuantLib::Real displacement () const override
 
QuantLib::ext::shared_ptr< QuantLib::SmileSection > smileSectionImpl (QuantLib::Time optionTime) const override
 
QuantLib::Volatility volatilityImpl (QuantLib::Time length, QuantLib::Rate strike) const override
 
void populateOneStrike ()
 Method to populate oneStrike_ on initialisation. More...
 

Detailed Description

template<class TimeInterpolator, class SmileInterpolator>
class QuantExt::StrippedOptionletAdapter< TimeInterpolator, SmileInterpolator >

Adapter class for turning a StrippedOptionletBase into an OptionletVolatilityStructure.

The class takes two template parameters indicating the interpolation in the time and strike direction respectively.

The class can take a QuantLib::StrippedOptionletBase that has only one strike column. In this case, the strike interpolation is ignored and the volatility at one of the pillar tenors, and any strike, is merely the passed in volatility. In this case, the smile sections are flat. All of this enables the StrippedOptionletAdapter to represent a stripped ATM optionlet curve. The single strike in the QuantLib::StrippedOptionletBase is ignored.

Definition at line 51 of file strippedoptionletadapter.hpp.

Constructor & Destructor Documentation

◆ StrippedOptionletAdapter() [1/2]

StrippedOptionletAdapter ( const QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > &  sob,
const TimeInterpolator &  ti = TimeInterpolator(),
const SmileInterpolator &  si = SmileInterpolator() 
)

Constructor that does not take a reference date. The settlement days is derived from sob and the term structure will be a moving term structure.

Definition at line 131 of file strippedoptionletadapter.hpp.

134 : OptionletVolatilityStructure(sob->settlementDays(), sob->calendar(), sob->businessDayConvention(),
135 sob->dayCounter()),
136 optionletBase_(sob), ti_(ti), si_(si), strikeSections_(optionletBase_->optionletMaturities()) {
137 registerWith(optionletBase_);
139}
TimeInterpolator ti_
The interpolation object in the time direction.
void populateOneStrike()
Method to populate oneStrike_ on initialisation.
QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > optionletBase_
Base optionlet object that provides the stripped optionlet volatilities.
SmileInterpolator si_
The interpolation object in the strike direction.
std::vector< QuantLib::Interpolation > strikeSections_
+ Here is the call graph for this function:

◆ StrippedOptionletAdapter() [2/2]

StrippedOptionletAdapter ( const QuantLib::Date &  referenceDate,
const QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > &  sob,
const TimeInterpolator &  ti = TimeInterpolator(),
const SmileInterpolator &  si = SmileInterpolator() 
)

Constructor taking an explicit referenceDate and the term structure will therefore be not moving.

Definition at line 142 of file strippedoptionletadapter.hpp.

145 : OptionletVolatilityStructure(referenceDate, sob->calendar(), sob->businessDayConvention(), sob->dayCounter()),
146 optionletBase_(sob), ti_(ti), si_(si), strikeSections_(optionletBase_->optionletMaturities()) {
147 registerWith(optionletBase_);
149}
+ Here is the call graph for this function:

Member Function Documentation

◆ maxDate()

QuantLib::Date maxDate
override

Definition at line 152 of file strippedoptionletadapter.hpp.

152 {
153 return optionletBase_->optionletFixingDates().back();
154}

◆ minStrike()

QuantLib::Rate minStrike
override

Definition at line 157 of file strippedoptionletadapter.hpp.

157 {
158
159 // If only one strike
160 if (oneStrike_) {
161 if (volatilityType() == QuantLib::ShiftedLognormal) {
162 return displacement() > 0.0 ? -displacement() : 0.0;
163 } else {
164 return QL_MIN_REAL;
165 }
166 }
167
168 // Return the minimum strike over all optionlet tenors
169 QuantLib::Rate minStrike = optionletBase_->optionletStrikes(0).front();
170 for (QuantLib::Size i = 1; i < optionletBase_->optionletMaturities(); ++i) {
171 minStrike = std::min(optionletBase_->optionletStrikes(i).front(), minStrike);
172 }
173 return minStrike;
174}
QuantLib::Real displacement() const override
QuantLib::VolatilityType volatilityType() const override
bool oneStrike_
Flag that indicates if optionletBase_ has only one strike for all option tenors.
QuantLib::Rate minStrike() const override

◆ maxStrike()

QuantLib::Rate maxStrike
override

Definition at line 177 of file strippedoptionletadapter.hpp.

177 {
178
179 // If only one strike, there is no max strike
180 if (oneStrike_) {
181 return QL_MAX_REAL;
182 }
183
184 // Return the maximum strike over all optionlet tenors
185 QuantLib::Rate maxStrike = optionletBase_->optionletStrikes(0).back();
186 for (QuantLib::Size i = 1; i < optionletBase_->optionletMaturities(); ++i) {
187 maxStrike = std::max(optionletBase_->optionletStrikes(i).back(), maxStrike);
188 }
189 return maxStrike;
190}
QuantLib::Rate maxStrike() const override

◆ volatilityType()

QuantLib::VolatilityType volatilityType
override

Definition at line 193 of file strippedoptionletadapter.hpp.

193 {
194 return optionletBase_->volatilityType();
195}

◆ displacement()

QuantLib::Real displacement
override

Definition at line 198 of file strippedoptionletadapter.hpp.

198 {
199 return optionletBase_->displacement();
200}

◆ update()

void update
override

Definition at line 203 of file strippedoptionletadapter.hpp.

203 {
204
205 // Need this or some tests with ObservationMode::Mode::Disable fail
206 // e.g. */SensitivityAnalysisTest/testPortfolioSensitivityDisableObs
207 optionletBase_->update();
208
209 TermStructure::update();
210 LazyObject::update();
211}

◆ performCalculations()

void performCalculations
override

Definition at line 214 of file strippedoptionletadapter.hpp.

214 {
215
216 // Some localised typedefs and using declarations to make the code more readable
217 using QuantLib::Rate;
218 using QuantLib::Size;
219 using QuantLib::Volatility;
220 using std::vector;
221
222 // If only one strike, no strike section to update
223 if (oneStrike_) {
224 return;
225 }
226
227 for (Size i = 0; i < optionletBase_->optionletMaturities(); ++i) {
228 const vector<Rate>& strikes = optionletBase_->optionletStrikes(i);
229 const vector<Volatility>& vols = optionletBase_->optionletVolatilities(i);
230 strikeSections_[i] = si_.interpolate(strikes.begin(), strikes.end(), vols.begin());
231 // Extrapolation can be enabled here. Range checks are performed in the volatility methods.
232 strikeSections_[i].enableExtrapolation();
233 }
234}
vector< Real > strikes

◆ deepUpdate()

void deepUpdate
override

Definition at line 237 of file strippedoptionletadapter.hpp.

237 {
238 optionletBase_->update();
239 update();
240}

◆ optionletBase()

QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > optionletBase

Definition at line 244 of file strippedoptionletadapter.hpp.

244 {
245 return optionletBase_;
246}

◆ smileSectionImpl()

QuantLib::ext::shared_ptr< QuantLib::SmileSection > smileSectionImpl ( QuantLib::Time  optionTime) const
overrideprotected

Definition at line 250 of file strippedoptionletadapter.hpp.

250 {
251
252 // Some localised typedefs and using declarations to make the code more readable
253 using QuantLib::Null;
254 using QuantLib::Rate;
255 using QuantLib::Real;
256 using QuantLib::Size;
257 using QuantLib::Volatility;
258 using QuantLib::io::ordinal;
259 using std::equal;
260 using std::sqrt;
261 using std::vector;
262
263 // Leave ATM rate as Null<Real>() for now but could interpolate optionletBase_->atmOptionletRates()?
264 Real atmRate = Null<Real>();
265
266 // If one strike, return a flat smile section
267 if (oneStrike_) {
268 Volatility vol = volatility(optionTime, optionletBase_->optionletStrikes(0)[0], true);
269 return QuantLib::ext::make_shared<QuantLib::FlatSmileSection>(optionTime, vol, optionletBase_->dayCounter(), atmRate,
271 }
272
273 /* we choose the strikes from the first fixing time for interpolation
274 - if only fixed strikes are used, they are the same for all times anyway
275 - if atm is used in addition, the first time's strikes are a superset of all others, i.e. the densest */
276 const vector<Rate>& strikes = optionletBase_->optionletStrikes(0);
277
278 // Store standard deviation at each strike
279 vector<Real> stdDevs;
280 for (Size i = 0; i < strikes.size(); i++) {
281 stdDevs.push_back(sqrt(blackVariance(optionTime, strikes[i], true)));
282 }
283
284 // Return the smile section.
285 return QuantLib::ext::make_shared<QuantLib::InterpolatedSmileSection<SmileInterpolator> >(
286 optionTime, strikes, stdDevs, atmRate, si_, optionletBase_->dayCounter(), volatilityType(), displacement());
287}
RandomVariable sqrt(RandomVariable x)
+ Here is the call graph for this function:

◆ volatilityImpl()

QuantLib::Volatility volatilityImpl ( QuantLib::Time  length,
QuantLib::Rate  strike 
) const
overrideprotected

Definition at line 291 of file strippedoptionletadapter.hpp.

292 {
293
294 // Some localised typedefs and using declarations to make the code more readable
295 using QuantLib::Interpolation;
296 using QuantLib::Size;
297 using QuantLib::Time;
298 using QuantLib::Volatility;
299 using std::vector;
300
301 calculate();
302
303 vector<Volatility> vols(optionletBase_->optionletMaturities());
304 for (Size i = 0; i < optionletBase_->optionletMaturities(); ++i) {
305 vols[i] = oneStrike_ ? optionletBase_->optionletVolatilities(i)[0] : strikeSections_[i](strike);
306 }
307
308 vector<Time> fixingTimes = optionletBase_->optionletFixingTimes();
309 Interpolation ti = ti_.interpolate(fixingTimes.begin(), fixingTimes.end(), vols.begin());
310
311 // Extrapolation can be enabled at this level. The range checks will have already been performed in
312 // the public OptionletVolatilityStructure::volatility method that calls this `Impl`
313 ti.enableExtrapolation();
314
315 return ti(optionTime);
316}

◆ populateOneStrike()

void populateOneStrike
private

Method to populate oneStrike_ on initialisation.

Definition at line 319 of file strippedoptionletadapter.hpp.

319 {
320 oneStrike_ = true;
321 for (QuantLib::Size i = 0; i < optionletBase_->optionletMaturities(); ++i) {
322 if (optionletBase_->optionletStrikes(i).size() > 1) {
323 oneStrike_ = false;
324 return;
325 }
326 }
327}
+ Here is the caller graph for this function:

Member Data Documentation

◆ optionletBase_

QuantLib::ext::shared_ptr<QuantLib::StrippedOptionletBase> optionletBase_
private

Base optionlet object that provides the stripped optionlet volatilities.

Definition at line 110 of file strippedoptionletadapter.hpp.

◆ ti_

TimeInterpolator ti_
private

The interpolation object in the time direction.

Definition at line 113 of file strippedoptionletadapter.hpp.

◆ si_

SmileInterpolator si_
private

The interpolation object in the strike direction.

Definition at line 116 of file strippedoptionletadapter.hpp.

◆ strikeSections_

std::vector<QuantLib::Interpolation> strikeSections_
mutableprivate

The optionlet volatility vs strike section at each optionlet fixing date It is mutable so that we can call enableExtrapolation in performCalculations.

Definition at line 121 of file strippedoptionletadapter.hpp.

◆ oneStrike_

bool oneStrike_
private

Flag that indicates if optionletBase_ has only one strike for all option tenors.

Definition at line 124 of file strippedoptionletadapter.hpp.