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

#include <qle/termstructures/strippedoptionletadapter2.hpp>

+ Inheritance diagram for StrippedOptionletAdapter2:
+ Collaboration diagram for StrippedOptionletAdapter2:

Public Member Functions

 StrippedOptionletAdapter2 (const QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > &, const bool flatExtrapolation=false)
 
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
 
QuantLib::ext::shared_ptr< QuantLib::OptionletStripper > optionletStripper () const
 
QuantLib::VolatilityType volatilityType () const override
 
QuantLib::Real displacement () const override
 

OptionletVolatilityStructure interface

const QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > optionletStripper_
 
QuantLib::Size nInterpolations_
 
std::vector< QuantLib::ext::shared_ptr< QuantLib::Interpolation > > strikeInterpolations_
 
const bool flatExtrapolation_
 
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

Adapter class for turning a StrippedOptionletBase object into an OptionletVolatilityStructure.

Definition at line 39 of file strippedoptionletadapter2.hpp.

Constructor & Destructor Documentation

◆ StrippedOptionletAdapter2()

StrippedOptionletAdapter2 ( const QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > &  ,
const bool  flatExtrapolation = false 
)

Definition at line 36 of file strippedoptionletadapter2.cpp.

38 : OptionletVolatilityStructure(s->settlementDays(), s->calendar(), s->businessDayConvention(), s->dayCounter()),
40 flatExtrapolation_(flatExtrapolation) {
41 registerWith(optionletStripper_);
42}
const QuantLib::ext::shared_ptr< QuantLib::StrippedOptionletBase > optionletStripper_
std::vector< QuantLib::ext::shared_ptr< QuantLib::Interpolation > > strikeInterpolations_

Member Function Documentation

◆ maxDate()

Date maxDate ( ) const
override

Definition at line 135 of file strippedoptionletadapter2.cpp.

135{ return optionletStripper_->optionletFixingDates().back(); }

◆ minStrike()

Rate minStrike ( ) const
override

Definition at line 127 of file strippedoptionletadapter2.cpp.

127 {
128 return optionletStripper_->optionletStrikes(0).front(); // FIX
129}

◆ maxStrike()

Rate maxStrike ( ) const
override

Definition at line 131 of file strippedoptionletadapter2.cpp.

131 {
132 return optionletStripper_->optionletStrikes(0).back(); // FIX
133}

◆ update()

void update ( )
override

Definition at line 76 of file strippedoptionletadapter2.hpp.

76 {
77 optionletStripper_->update(); // just in case
78 TermStructure::update();
79 LazyObject::update();
80}

◆ performCalculations()

void performCalculations ( ) const
override

Definition at line 82 of file strippedoptionletadapter2.cpp.

82 {
83
84 // const std::vector<Rate>& atmForward = optionletStripper_->atmOptionletRate();
85 // const std::vector<Time>& optionletTimes = optionletStripper_->optionletTimes();
86
87 for (Size i = 0; i < nInterpolations_; ++i) {
88 const std::vector<Rate>& optionletStrikes = optionletStripper_->optionletStrikes(i);
89 const std::vector<Volatility>& optionletVolatilities = optionletStripper_->optionletVolatilities(i);
90 // strikeInterpolations_[i] = QuantLib::ext::shared_ptr<SABRInterpolation>(new
91 // SABRInterpolation(optionletStrikes.begin(), optionletStrikes.end(),
92 // optionletVolatilities.begin(),
93 // optionletTimes[i], atmForward[i],
94 // 0.02,0.5,0.2,0.,
95 // false, true, false, false
96 // //alphaGuess_, betaGuess_,
97 // //nuGuess_, rhoGuess_,
98 // //isParameterFixed_[0],
99 // //isParameterFixed_[1],
100 // //isParameterFixed_[2],
101 // //isParameterFixed_[3]
102 // ////,
103 // //vegaWeightedSmileFit_,
104 // //endCriteria_,
105 // //optMethod_
106 // ));
107 QuantLib::ext::shared_ptr<Interpolation> tmp = QuantLib::ext::shared_ptr<LinearInterpolation>(
108 new LinearInterpolation(optionletStrikes.begin(), optionletStrikes.end(), optionletVolatilities.begin()));
110 strikeInterpolations_[i] = QuantLib::ext::make_shared<FlatExtrapolation>(tmp);
111 else
112 strikeInterpolations_[i] = tmp;
113
114 // QL_ENSURE(strikeInterpolations_[i]->endCriteria()!=EndCriteria::MaxIterations,
115 // "section calibration failed: "
116 // "option time " << optionletTimes[i] <<
117 // ": " <<
118 // ", alpha " << strikeInterpolations_[i]->alpha()<<
119 // ", beta " << strikeInterpolations_[i]->beta() <<
120 // ", nu " << strikeInterpolations_[i]->nu() <<
121 // ", rho " << strikeInterpolations_[i]->rho() <<
122 // ", error " << strikeInterpolations_[i]->interpolationError()
123 // );
124 }
125}

◆ optionletStripper()

QuantLib::ext::shared_ptr< QuantLib::OptionletStripper > optionletStripper ( ) const

Definition at line 82 of file strippedoptionletadapter2.hpp.

82 {
83 return QuantLib::ext::dynamic_pointer_cast<QuantLib::OptionletStripper>(optionletStripper_);
84}

◆ volatilityType()

VolatilityType volatilityType ( ) const
override

Definition at line 137 of file strippedoptionletadapter2.cpp.

137{ return optionletStripper_->volatilityType(); }
+ Here is the caller graph for this function:

◆ displacement()

Real displacement ( ) const
override

Definition at line 139 of file strippedoptionletadapter2.cpp.

139{ return optionletStripper_->displacement(); }
+ Here is the caller graph for this function:

◆ smileSectionImpl()

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

Definition at line 44 of file strippedoptionletadapter2.cpp.

44 {
45 std::vector<Rate> optionletStrikes =
46 optionletStripper_->optionletStrikes(0); // strikes are the same for all times ?!
47 std::vector<Real> stddevs;
48 Real tEff = flatExtrapolation_ ? std::min(t, optionletStripper_->optionletFixingTimes().back()) : t;
49 for (Size i = 0; i < optionletStrikes.size(); i++) {
50 stddevs.push_back(volatilityImpl(tEff, optionletStrikes[i]) * std::sqrt(tEff));
51 }
52 // Use a linear interpolated smile section.
53 // TODO: possibly make this configurable?
55 return QuantLib::ext::make_shared<InterpolatedSmileSection<LinearFlat> >(t, optionletStrikes, stddevs, Null<Real>(),
56 LinearFlat(), Actual365Fixed(),
58 else
59 return QuantLib::ext::make_shared<InterpolatedSmileSection<Linear> >(
60 t, optionletStrikes, stddevs, Null<Real>(), Linear(), Actual365Fixed(), volatilityType(), displacement());
61}
QuantLib::Volatility volatilityImpl(QuantLib::Time length, QuantLib::Rate strike) const override
QuantLib::VolatilityType volatilityType() const override
QuantLib::Real displacement() const override
+ Here is the call graph for this function:

◆ volatilityImpl()

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

Definition at line 63 of file strippedoptionletadapter2.cpp.

63 {
64
65 calculate();
66
67 vector<Volatility> vol(nInterpolations_);
68 for (Size i = 0; i < nInterpolations_; ++i)
69 vol[i] = strikeInterpolations_[i]->operator()(strike, true);
70
71 vector<Time> optionletTimes = optionletStripper_->optionletFixingTimes();
72 LinearInterpolation timeInterpolator(optionletTimes.begin(), optionletTimes.end(), vol.begin());
73
74 // If flat extrapolation is turned on, extrapolate flat after last expiry _and_ before first expiry
76 length = max(min(length, optionletTimes.back()), optionletTimes.front());
77 }
78
79 return timeInterpolator(length, true);
80}
CompiledFormula min(CompiledFormula x, const CompiledFormula &y)
CompiledFormula max(CompiledFormula x, const CompiledFormula &y)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ optionletStripper_

const QuantLib::ext::shared_ptr<QuantLib::StrippedOptionletBase> optionletStripper_
private

Definition at line 70 of file strippedoptionletadapter2.hpp.

◆ nInterpolations_

QuantLib::Size nInterpolations_
private

Definition at line 71 of file strippedoptionletadapter2.hpp.

◆ strikeInterpolations_

std::vector<QuantLib::ext::shared_ptr<QuantLib::Interpolation> > strikeInterpolations_
mutableprivate

Definition at line 72 of file strippedoptionletadapter2.hpp.

◆ flatExtrapolation_

const bool flatExtrapolation_
private

Definition at line 73 of file strippedoptionletadapter2.hpp.