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

#include <qle/termstructures/sabrstrippedoptionletadapter.hpp>

+ Inheritance diagram for SabrStrippedOptionletAdapter< TimeInterpolator >:
+ Collaboration diagram for SabrStrippedOptionletAdapter< TimeInterpolator >:

Public Member Functions

 SabrStrippedOptionletAdapter (const QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > &sob, const QuantExt::SabrParametricVolatility::ModelVariant modelVariant, const TimeInterpolator &ti=TimeInterpolator(), const boost::optional< QuantLib::VolatilityType > outputVolatilityType=boost::none, const std::vector< std::vector< std::pair< Real, bool > > > &initialModelParameters={}, const QuantLib::Size maxCalibrationAttempts=10, const QuantLib::Real exitEarlyErrorThreshold=0.005, const QuantLib::Real maxAcceptableError=0.05)
 
 SabrStrippedOptionletAdapter (const QuantLib::Date &referenceDate, const QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > &sob, const QuantExt::SabrParametricVolatility::ModelVariant modelVariant, const TimeInterpolator &ti=TimeInterpolator(), const boost::optional< QuantLib::VolatilityType > outputVolatilityType=boost::none, const std::vector< std::vector< std::pair< Real, bool > > > &initialModelParameters={}, const QuantLib::Size maxCalibrationAttempts=10, const QuantLib::Real exitEarlyErrorThreshold=0.005, const QuantLib::Real maxAcceptableError=0.05)
 
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
 
QuantLib::ext::shared_ptr< QuantExt::ParametricVolatilityparametricVolatility () 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...
 
QuantExt::SabrParametricVolatility::ModelVariant modelVariant_
 SABR specific inputs. More...
 
boost::optional< QuantLib::VolatilityType > outputVolatilityType_
 
std::vector< std::vector< std::pair< Real, bool > > > initialModelParameters_
 
QuantLib::Size maxCalibrationAttempts_
 
QuantLib::Real exitEarlyErrorThreshold_
 
QuantLib::Real maxAcceptableError_
 
std::map< Real, QuantLib::ext::shared_ptr< ParametricVolatilitySmileSection > > cache_
 State. More...
 
QuantLib::ext::shared_ptr< ParametricVolatilityparametricVolatility_
 
std::unique_ptr< FlatExtrapolationatmInterpolation_
 
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
 

Detailed Description

template<class TimeInterpolator>
class QuantExt::SabrStrippedOptionletAdapter< TimeInterpolator >

Definition at line 43 of file sabrstrippedoptionletadapter.hpp.

Constructor & Destructor Documentation

◆ SabrStrippedOptionletAdapter() [1/2]

SabrStrippedOptionletAdapter ( const QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > &  sob,
const QuantExt::SabrParametricVolatility::ModelVariant  modelVariant,
const TimeInterpolator &  ti = TimeInterpolator(),
const boost::optional< QuantLib::VolatilityType >  outputVolatilityType = boost::none,
const std::vector< std::vector< std::pair< Real, bool > > > &  initialModelParameters = {},
const QuantLib::Size  maxCalibrationAttempts = 10,
const QuantLib::Real  exitEarlyErrorThreshold = 0.005,
const QuantLib::Real  maxAcceptableError = 0.05 
)

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 135 of file sabrstrippedoptionletadapter.hpp.

142 : OptionletVolatilityStructure(sob->settlementDays(), sob->calendar(), sob->businessDayConvention(),
143 sob->dayCounter()),
144 optionletBase_(sob), ti_(ti), modelVariant_(modelVariant), outputVolatilityType_(outputVolatilityType),
145 initialModelParameters_(initialModelParameters), maxCalibrationAttempts_(maxCalibrationAttempts),
146 exitEarlyErrorThreshold_(exitEarlyErrorThreshold), maxAcceptableError_(maxAcceptableError) {
147 registerWith(optionletBase_);
148}
TimeInterpolator ti_
The interpolation object in the time direction.
std::vector< std::vector< std::pair< Real, bool > > > initialModelParameters_
QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > optionletBase_
Base optionlet object that provides the stripped optionlet volatilities.
boost::optional< QuantLib::VolatilityType > outputVolatilityType_
QuantExt::SabrParametricVolatility::ModelVariant modelVariant_
SABR specific inputs.

◆ SabrStrippedOptionletAdapter() [2/2]

SabrStrippedOptionletAdapter ( const QuantLib::Date &  referenceDate,
const QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > &  sob,
const QuantExt::SabrParametricVolatility::ModelVariant  modelVariant,
const TimeInterpolator &  ti = TimeInterpolator(),
const boost::optional< QuantLib::VolatilityType >  outputVolatilityType = boost::none,
const std::vector< std::vector< std::pair< Real, bool > > > &  initialModelParameters = {},
const QuantLib::Size  maxCalibrationAttempts = 10,
const QuantLib::Real  exitEarlyErrorThreshold = 0.005,
const QuantLib::Real  maxAcceptableError = 0.05 
)

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

Definition at line 151 of file sabrstrippedoptionletadapter.hpp.

158 : OptionletVolatilityStructure(referenceDate, sob->calendar(), sob->businessDayConvention(), sob->dayCounter()),
159 optionletBase_(sob), ti_(ti), modelVariant_(modelVariant), outputVolatilityType_(outputVolatilityType),
160 initialModelParameters_(initialModelParameters), maxCalibrationAttempts_(maxCalibrationAttempts),
161 exitEarlyErrorThreshold_(exitEarlyErrorThreshold), maxAcceptableError_(maxAcceptableError) {
162 registerWith(optionletBase_);
163}

Member Function Documentation

◆ maxDate()

QuantLib::Date maxDate
override

Definition at line 166 of file sabrstrippedoptionletadapter.hpp.

166 {
167 return Date::maxDate();
168}

◆ minStrike()

QuantLib::Rate minStrike
override

Definition at line 171 of file sabrstrippedoptionletadapter.hpp.

171 {
172 return -QL_MAX_REAL;
173}

◆ maxStrike()

QuantLib::Rate maxStrike
override

Definition at line 176 of file sabrstrippedoptionletadapter.hpp.

176 {
177 return QL_MAX_REAL;
178}

◆ volatilityType()

QuantLib::VolatilityType volatilityType
override

Definition at line 181 of file sabrstrippedoptionletadapter.hpp.

181 {
182 return optionletBase_->volatilityType();
183}

◆ displacement()

QuantLib::Real displacement
override

Definition at line 186 of file sabrstrippedoptionletadapter.hpp.

186 {
187 return optionletBase_->displacement();
188}

◆ update()

void update
override

Definition at line 190 of file sabrstrippedoptionletadapter.hpp.

190 {
191 optionletBase_->update();
192 TermStructure::update();
193 LazyObject::update();
194}

◆ performCalculations()

void performCalculations
override

Definition at line 197 of file sabrstrippedoptionletadapter.hpp.

197 {
198 cache_.clear();
199
200 atmInterpolation_ = std::make_unique<FlatExtrapolation>(QuantLib::ext::make_shared<LinearInterpolation>(
201 this->optionletBase()->optionletFixingTimes().begin(), this->optionletBase()->optionletFixingTimes().end(),
202 this->optionletBase()->atmOptionletRates().begin()));
203 atmInterpolation_->enableExtrapolation();
204 atmInterpolation_->update();
205
206 std::vector<ParametricVolatility::MarketSmile> marketSmiles;
207 std::map<std::pair<QuantLib::Real, QuantLib::Real>, std::vector<std::pair<Real, bool>>> modelParameters;
208 QL_REQUIRE(initialModelParameters_.empty() || initialModelParameters_.size() == 1 ||
209 initialModelParameters_.size() == this->optionletBase()->optionletFixingTimes().size(),
210 "SabrStrippedOptionletAdapter: initial model parameters must be empty or their size ("
212 << ") must be 1 or it must match the number of optionlet fixing times ("
213 << this->optionletBase()->optionletFixingTimes().size() << ")");
214 for (Size i = 0; i < this->optionletBase()->optionletFixingTimes().size(); ++i) {
215 Real forward = atmInterpolation_->operator()(this->optionletBase()->optionletFixingTimes()[i]);
216 marketSmiles.push_back(ParametricVolatility::MarketSmile{this->optionletBase()->optionletFixingTimes()[i],
217 Null<Real>(),
218 forward,
219 displacement(),
220 {},
221 this->optionletBase()->optionletStrikes(i),
222 this->optionletBase()->optionletVolatilities(i)});
223 if (!initialModelParameters_.empty()) {
224 modelParameters[std::make_pair(this->optionletBase()->optionletFixingTimes()[i], Null<Real>())] =
226 }
227 }
228
229 parametricVolatility_ = QuantLib::ext::make_shared<SabrParametricVolatility>(
233 Handle<YieldTermStructure>(), modelParameters, maxCalibrationAttempts_, exitEarlyErrorThreshold_,
235}
std::unique_ptr< FlatExtrapolation > atmInterpolation_
std::map< Real, QuantLib::ext::shared_ptr< ParametricVolatilitySmileSection > > cache_
State.
QuantLib::VolatilityType volatilityType() const override
QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > optionletBase() const
QuantLib::ext::shared_ptr< ParametricVolatility > parametricVolatility_

◆ deepUpdate()

void deepUpdate
override

Definition at line 237 of file sabrstrippedoptionletadapter.hpp.

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

◆ optionletBase()

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

Definition at line 244 of file sabrstrippedoptionletadapter.hpp.

244 {
245 return optionletBase_;
246}

◆ parametricVolatility()

QuantLib::ext::shared_ptr< QuantExt::ParametricVolatility > parametricVolatility ( ) const

Definition at line 101 of file sabrstrippedoptionletadapter.hpp.

101 {
103 }

◆ smileSectionImpl()

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

Definition at line 250 of file sabrstrippedoptionletadapter.hpp.

250 {
251 calculate();
252 if (auto c = cache_.find(optionTime); c != cache_.end()) {
253 return c->second;
254 }
255 Real forward = atmInterpolation_->operator()(optionTime);
256 QuantLib::VolatilityType outVolType = outputVolatilityType_ ? *outputVolatilityType_ : volatilityType();
257 auto tmp = QuantLib::ext::make_shared<ParametricVolatilitySmileSection>(
258 optionTime, Null<Real>(), forward, parametricVolatility_,
259 outVolType == QuantLib::Normal ? ParametricVolatility::MarketQuoteType::NormalVolatility
261 cache_[optionTime] = tmp;
262 return tmp;
263}

◆ volatilityImpl()

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

Definition at line 267 of file sabrstrippedoptionletadapter.hpp.

267 {
268 return smileSectionImpl(optionTime)->volatility(strike);
269}
QuantLib::ext::shared_ptr< QuantLib::SmileSection > smileSectionImpl(QuantLib::Time optionTime) const override

Member Data Documentation

◆ optionletBase_

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

Base optionlet object that provides the stripped optionlet volatilities.

Definition at line 115 of file sabrstrippedoptionletadapter.hpp.

◆ ti_

TimeInterpolator ti_
private

The interpolation object in the time direction.

Definition at line 118 of file sabrstrippedoptionletadapter.hpp.

◆ modelVariant_

SABR specific inputs.

Definition at line 121 of file sabrstrippedoptionletadapter.hpp.

◆ outputVolatilityType_

boost::optional<QuantLib::VolatilityType> outputVolatilityType_
private

Definition at line 122 of file sabrstrippedoptionletadapter.hpp.

◆ initialModelParameters_

std::vector<std::vector<std::pair<Real, bool> > > initialModelParameters_
private

Definition at line 123 of file sabrstrippedoptionletadapter.hpp.

◆ maxCalibrationAttempts_

QuantLib::Size maxCalibrationAttempts_
private

Definition at line 124 of file sabrstrippedoptionletadapter.hpp.

◆ exitEarlyErrorThreshold_

QuantLib::Real exitEarlyErrorThreshold_
private

Definition at line 125 of file sabrstrippedoptionletadapter.hpp.

◆ maxAcceptableError_

QuantLib::Real maxAcceptableError_
private

Definition at line 126 of file sabrstrippedoptionletadapter.hpp.

◆ cache_

std::map<Real, QuantLib::ext::shared_ptr<ParametricVolatilitySmileSection> > cache_
mutableprivate

State.

Definition at line 129 of file sabrstrippedoptionletadapter.hpp.

◆ parametricVolatility_

QuantLib::ext::shared_ptr<ParametricVolatility> parametricVolatility_
mutableprivate

Definition at line 130 of file sabrstrippedoptionletadapter.hpp.

◆ atmInterpolation_

std::unique_ptr<FlatExtrapolation> atmInterpolation_
mutableprivate

Definition at line 131 of file sabrstrippedoptionletadapter.hpp.