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

#include <qle/termstructures/spreadedswaptionvolatility.hpp>

+ Inheritance diagram for SpreadedSwaptionVolatility:
+ Collaboration diagram for SpreadedSwaptionVolatility:

Public Member Functions

 SpreadedSwaptionVolatility (const Handle< SwaptionVolatilityStructure > &base, const std::vector< Period > &optionTenors, const std::vector< Period > &swapTenors, const std::vector< Real > &strikeSpreads, const std::vector< std::vector< Handle< Quote > > > &volSpreads, const QuantLib::ext::shared_ptr< SwapIndex > &baseSwapIndexBase=nullptr, const QuantLib::ext::shared_ptr< SwapIndex > &baseShortSwapIndexBase=nullptr, const QuantLib::ext::shared_ptr< SwapIndex > &simulatedSwapIndexBase=nullptr, const QuantLib::ext::shared_ptr< SwapIndex > &simulatedShortSwapIndexBase=nullptr, const bool stickyAbsMoney=false)
 
TermStructure interface
DayCounter dayCounter () const override
 
Date maxDate () const override
 
Time maxTime () const override
 
const Date & referenceDate () const override
 
Calendar calendar () const override
 
Natural settlementDays () const override
 
VolatilityTermStructure interface
Rate minStrike () const override
 
Rate maxStrike () const override
 
SwaptionVolatilityStructure interface
const Period & maxSwapTenor () const override
 
VolatilityType volatilityType () const override
 

Observer interface

Handle< SwaptionVolatilityStructurebase_
 
std::vector< Real > strikeSpreads_
 
std::vector< std::vector< Handle< Quote > > > volSpreads_
 
QuantLib::ext::shared_ptr< SwapIndex > baseSwapIndexBase_
 
QuantLib::ext::shared_ptr< SwapIndex > baseShortSwapIndexBase_
 
QuantLib::ext::shared_ptr< SwapIndex > simulatedSwapIndexBase_
 
QuantLib::ext::shared_ptr< SwapIndex > simulatedShortSwapIndexBase_
 
bool stickyAbsMoney_
 
std::vector< Matrix > volSpreadValues_
 
std::vector< Interpolation2D > volSpreadInterpolation_
 
void deepUpdate () override
 
const Handle< SwaptionVolatilityStructure > & baseVol ()
 
QuantLib::ext::shared_ptr< SmileSection > smileSectionImpl (Time optionTime, Time swapLength) const override
 
Volatility volatilityImpl (Time optionTime, Time swapLength, Rate strike) const override
 
Real shiftImpl (const Date &optionDate, const Period &swapTenor) const override
 
Real shiftImpl (Time optionTime, Time swapLength) const override
 
void performCalculations () const override
 
Real getAtmLevel (const Real optionTime, const Real swapLength, const QuantLib::ext::shared_ptr< SwapIndex > swapIndexBase, const QuantLib::ext::shared_ptr< SwapIndex > shortSwapIndexBase) const
 

Detailed Description

Definition at line 37 of file spreadedswaptionvolatility.hpp.

Constructor & Destructor Documentation

◆ SpreadedSwaptionVolatility()

SpreadedSwaptionVolatility ( const Handle< SwaptionVolatilityStructure > &  base,
const std::vector< Period > &  optionTenors,
const std::vector< Period > &  swapTenors,
const std::vector< Real > &  strikeSpreads,
const std::vector< std::vector< Handle< Quote > > > &  volSpreads,
const QuantLib::ext::shared_ptr< SwapIndex > &  baseSwapIndexBase = nullptr,
const QuantLib::ext::shared_ptr< SwapIndex > &  baseShortSwapIndexBase = nullptr,
const QuantLib::ext::shared_ptr< SwapIndex > &  simulatedSwapIndexBase = nullptr,
const QuantLib::ext::shared_ptr< SwapIndex > &  simulatedShortSwapIndexBase = nullptr,
const bool  stickyAbsMoney = false 
)

Definition at line 30 of file spreadedswaptionvolatility.cpp.

37 : SwaptionVolatilityDiscrete(optionTenors, swapTenors, 0, base->calendar(), base->businessDayConvention(),
38 base->dayCounter()),
39 base_(base), strikeSpreads_(strikeSpreads), volSpreads_(volSpreads), baseSwapIndexBase_(baseSwapIndexBase),
40 baseShortSwapIndexBase_(baseShortSwapIndexBase), simulatedSwapIndexBase_(simulatedSwapIndexBase),
41 simulatedShortSwapIndexBase_(simulatedShortSwapIndexBase), stickyAbsMoney_(stickyAbsMoney) {
42 enableExtrapolation(base_->allowsExtrapolation());
43 registerWith(base_);
44 QL_REQUIRE(
45 (baseSwapIndexBase_ == nullptr && baseShortSwapIndexBase_ == nullptr) ||
46 (baseSwapIndexBase_ != nullptr && baseShortSwapIndexBase_ != nullptr),
47 "SpreadedSwaptionVolatility: baseSwapIndexBase and baseShortSwapIndexBase must be both null or non-null");
48 QL_REQUIRE((simulatedSwapIndexBase_ == nullptr && simulatedShortSwapIndexBase_ == nullptr) ||
50 "SpreadedSwaptionVolatility: simulatedSwapIndexBase and simulatedShortSwapIndexBase must be both null "
51 "or non-null");
53 registerWith(baseSwapIndexBase_);
55 registerWith(baseShortSwapIndexBase_);
57 registerWith(simulatedSwapIndexBase_);
59 registerWith(simulatedShortSwapIndexBase_);
60 QL_REQUIRE(!strikeSpreads_.empty(), "SpreadedSwaptionVolatility: empty strike spreads");
61 QL_REQUIRE(!optionTenors_.empty(), "SpreadedSwaptionVolatility: empty option tenors");
62 QL_REQUIRE(!swapTenors_.empty(), "SpreadedSwaptionVolatility: empty swap tenors");
63 QL_REQUIRE(optionTenors.size() * swapTenors.size() == volSpreads.size(),
64 "SpreadedSwaptionVolatility: optionTenors (" << optionTenors.size() << ") * swapTenors ("
65 << swapTenors.size() << ") inconsistent with vol spreads ("
66 << volSpreads.size() << ")");
67 for (auto const& s : volSpreads_) {
68 QL_REQUIRE(s.size() == strikeSpreads_.size(), "SpreadedSwaptionVolatility: got " << strikeSpreads_.size()
69 << " strike spreads, but "
70 << s.size() << " vol spreads");
71 for (auto const& q : s)
72 registerWith(q);
73 }
74 volSpreadValues_ = std::vector<Matrix>(strikeSpreads_.size(), Matrix(optionTenors.size(), swapTenors.size(), 0.0));
75 volSpreadInterpolation_ = std::vector<Interpolation2D>(strikeSpreads_.size());
76}
QuantLib::ext::shared_ptr< SwapIndex > simulatedShortSwapIndexBase_
QuantLib::ext::shared_ptr< SwapIndex > baseSwapIndexBase_
Handle< SwaptionVolatilityStructure > base_
QuantLib::ext::shared_ptr< SwapIndex > simulatedSwapIndexBase_
std::vector< Interpolation2D > volSpreadInterpolation_
std::vector< std::vector< Handle< Quote > > > volSpreads_
QuantLib::ext::shared_ptr< SwapIndex > baseShortSwapIndexBase_

Member Function Documentation

◆ dayCounter()

DayCounter dayCounter ( ) const
override

Definition at line 78 of file spreadedswaptionvolatility.cpp.

78{ return base_->dayCounter(); }

◆ maxDate()

Date maxDate ( ) const
override

Definition at line 79 of file spreadedswaptionvolatility.cpp.

79{ return base_->maxDate(); }

◆ maxTime()

Time maxTime ( ) const
override

Definition at line 80 of file spreadedswaptionvolatility.cpp.

80{ return base_->maxTime(); }

◆ referenceDate()

const Date & referenceDate ( ) const
override

Definition at line 81 of file spreadedswaptionvolatility.cpp.

81{ return base_->referenceDate(); }

◆ calendar()

Calendar calendar ( ) const
override

Definition at line 82 of file spreadedswaptionvolatility.cpp.

82{ return base_->calendar(); }

◆ settlementDays()

Natural settlementDays ( ) const
override

Definition at line 83 of file spreadedswaptionvolatility.cpp.

83{ return base_->settlementDays(); }

◆ minStrike()

Rate minStrike ( ) const
override

Definition at line 84 of file spreadedswaptionvolatility.cpp.

84{ return base_->minStrike(); }

◆ maxStrike()

Rate maxStrike ( ) const
override

Definition at line 85 of file spreadedswaptionvolatility.cpp.

85{ return base_->maxStrike(); }

◆ maxSwapTenor()

const Period & maxSwapTenor ( ) const
override

Definition at line 86 of file spreadedswaptionvolatility.cpp.

86{ return base_->maxSwapTenor(); }

◆ volatilityType()

VolatilityType volatilityType ( ) const
override

Definition at line 87 of file spreadedswaptionvolatility.cpp.

87{ return base_->volatilityType(); }

◆ deepUpdate()

void deepUpdate ( )
override

Definition at line 88 of file spreadedswaptionvolatility.cpp.

88 {
89 base_->update();
90 update();
91}

◆ baseVol()

const Handle< SwaptionVolatilityStructure > & baseVol ( )

Definition at line 92 of file spreadedswaptionvolatility.cpp.

92{ return base_; }

◆ smileSectionImpl()

QuantLib::ext::shared_ptr< SmileSection > smileSectionImpl ( Time  optionTime,
Time  swapLength 
) const
overrideprivate

Definition at line 110 of file spreadedswaptionvolatility.cpp.

110 {
111 calculate();
112 auto baseSection = base_->smileSection(optionTime, swapLength);
113 Real baseAtmLevel = Null<Real>();
114 Real simulatedAtmLevel = Null<Real>();
115 if ((stickyAbsMoney_ || strikeSpreads_.size() > 1) && baseSection->atmLevel() == Null<Real>()) {
116 QL_REQUIRE(baseSwapIndexBase_ != nullptr,
117 "SpreadedSwaptionVolatility::smileSecitonImpl: require baseSwapIndexBase, since stickyAbsMoney is "
118 "true and the base vol smile section does not provide an ATM level.");
119 baseAtmLevel = getAtmLevel(optionTime, swapLength, baseSwapIndexBase_, baseShortSwapIndexBase_);
120 }
121 if (stickyAbsMoney_) {
122 QL_REQUIRE(simulatedSwapIndexBase_ != nullptr, "SpreadedSwaptionVolatility::smileSectionImpl: required "
123 "simualtedSwapIndexBase, since stickyAbsMoney is true");
124 simulatedAtmLevel = getAtmLevel(optionTime, swapLength, simulatedSwapIndexBase_, simulatedShortSwapIndexBase_);
125 }
126 // interpolate vol spreads
127 std::vector<Real> volSpreads(strikeSpreads_.size());
128 for (Size k = 0; k < volSpreads.size(); ++k) {
129 volSpreads[k] = volSpreadInterpolation_[k](swapLength, optionTime);
130 }
131 // create smile section
132 return QuantLib::ext::make_shared<SpreadedSmileSection2>(base_->smileSection(optionTime, swapLength), volSpreads,
133 strikeSpreads_, true, baseAtmLevel, simulatedAtmLevel,
135}
Real getAtmLevel(const Real optionTime, const Real swapLength, const QuantLib::ext::shared_ptr< SwapIndex > swapIndexBase, const QuantLib::ext::shared_ptr< SwapIndex > shortSwapIndexBase) const
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ volatilityImpl()

Volatility volatilityImpl ( Time  optionTime,
Time  swapLength,
Rate  strike 
) const
overrideprivate

Definition at line 137 of file spreadedswaptionvolatility.cpp.

137 {
138 if (strike == Null<Real>()) {
139 calculate();
140 // support input strike null, interpret this as atm
141 std::vector<Real> volSpreads(strikeSpreads_.size());
142 for (Size k = 0; k < volSpreads.size(); ++k) {
143 volSpreads[k] = volSpreadInterpolation_[k](swapLength, optionTime);
144 }
145 Real volSpread;
146 if (volSpreads.size() > 1) {
147 auto spreadInterpolation =
148 LinearFlat().interpolate(strikeSpreads_.begin(), strikeSpreads_.end(), volSpreads.begin());
149 volSpread = spreadInterpolation(0.0);
150 } else {
151 volSpread = volSpreads.front();
152 }
153 return base_->volatility(optionTime, swapLength, strike) + volSpread;
154 } else {
155 // if input strike != null, use smile section implementation
156 return smileSectionImpl(optionTime, swapLength)->volatility(strike);
157 }
158}
QuantLib::ext::shared_ptr< SmileSection > smileSectionImpl(Time optionTime, Time swapLength) const override
+ Here is the call graph for this function:

◆ shiftImpl() [1/2]

Real shiftImpl ( const Date &  optionDate,
const Period &  swapTenor 
) const
overrideprivate

Definition at line 160 of file spreadedswaptionvolatility.cpp.

160 {
161 return base_->shift(optionDate, swapTenor);
162}

◆ shiftImpl() [2/2]

Real shiftImpl ( Time  optionTime,
Time  swapLength 
) const
overrideprivate

Definition at line 164 of file spreadedswaptionvolatility.cpp.

164 {
165 return base_->shift(optionTime, swapLength);
166}

◆ performCalculations()

void performCalculations ( ) const
overrideprivate

Definition at line 168 of file spreadedswaptionvolatility.cpp.

168 {
169 SwaptionVolatilityDiscrete::performCalculations();
170 for (Size k = 0; k < strikeSpreads_.size(); ++k) {
171 for (Size i = 0; i < optionTenors_.size(); ++i) {
172 for (Size j = 0; j < swapTenors_.size(); ++j) {
173 Size index = i * swapTenors_.size() + j;
174 QL_REQUIRE(!volSpreads_[index][k].empty(), "SpreadedSwaptionVolatility: vol spread quote at index ("
175 << i << "," << j << "," << k << ") is empty");
176 volSpreadValues_[k](i, j) = volSpreads_[index][k]->value();
177 }
178 }
179 volSpreadInterpolation_[k] = FlatExtrapolator2D(QuantLib::ext::make_shared<BilinearInterpolation>(
180 swapLengths_.begin(), swapLengths_.end(), optionTimes_.begin(), optionTimes_.end(), volSpreadValues_[k]));
181 volSpreadInterpolation_[k].enableExtrapolation();
182 }
183}

◆ getAtmLevel()

Real getAtmLevel ( const Real  optionTime,
const Real  swapLength,
const QuantLib::ext::shared_ptr< SwapIndex >  swapIndexBase,
const QuantLib::ext::shared_ptr< SwapIndex >  shortSwapIndexBase 
) const
private

Definition at line 94 of file spreadedswaptionvolatility.cpp.

96 {
97 Date optionDate = optionDateFromTime(optionTime);
98 Rounding rounder(0);
99 Period swapTenor(static_cast<Integer>(rounder(swapLength * 12.0)), Months);
100 optionDate = swapTenor > shortSwapIndexBase->tenor()
101 ? swapIndexBase->fixingCalendar().adjust(optionDate, Following)
102 : shortSwapIndexBase->fixingCalendar().adjust(optionDate, Following);
103 if (swapTenor > shortSwapIndexBase->tenor()) {
104 return swapIndexBase->clone(swapTenor)->fixing(optionDate);
105 } else {
106 return shortSwapIndexBase->clone(swapTenor)->fixing(optionDate);
107 }
108}
+ Here is the caller graph for this function:

Member Data Documentation

◆ base_

Handle<SwaptionVolatilityStructure> base_
private

Definition at line 87 of file spreadedswaptionvolatility.hpp.

◆ strikeSpreads_

std::vector<Real> strikeSpreads_
private

Definition at line 88 of file spreadedswaptionvolatility.hpp.

◆ volSpreads_

std::vector<std::vector<Handle<Quote> > > volSpreads_
private

Definition at line 89 of file spreadedswaptionvolatility.hpp.

◆ baseSwapIndexBase_

QuantLib::ext::shared_ptr<SwapIndex> baseSwapIndexBase_
private

Definition at line 90 of file spreadedswaptionvolatility.hpp.

◆ baseShortSwapIndexBase_

QuantLib::ext::shared_ptr<SwapIndex> baseShortSwapIndexBase_
private

Definition at line 90 of file spreadedswaptionvolatility.hpp.

◆ simulatedSwapIndexBase_

QuantLib::ext::shared_ptr<SwapIndex> simulatedSwapIndexBase_
private

Definition at line 91 of file spreadedswaptionvolatility.hpp.

◆ simulatedShortSwapIndexBase_

QuantLib::ext::shared_ptr<SwapIndex> simulatedShortSwapIndexBase_
private

Definition at line 91 of file spreadedswaptionvolatility.hpp.

◆ stickyAbsMoney_

bool stickyAbsMoney_
private

Definition at line 92 of file spreadedswaptionvolatility.hpp.

◆ volSpreadValues_

std::vector<Matrix> volSpreadValues_
mutableprivate

Definition at line 93 of file spreadedswaptionvolatility.hpp.

◆ volSpreadInterpolation_

std::vector<Interpolation2D> volSpreadInterpolation_
mutableprivate

Definition at line 94 of file spreadedswaptionvolatility.hpp.