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

#include <qle/termstructures/swaptionsabrcube.hpp>

+ Inheritance diagram for SwaptionSabrCube:
+ Collaboration diagram for SwaptionSabrCube:

Public Member Functions

 SwaptionSabrCube (const Handle< SwaptionVolatilityStructure > &atmVolStructure, const std::vector< Period > &optionTenors, const std::vector< Period > &swapTenors, const std::vector< Period > &atmOptionTenors, const std::vector< Period > &atmSwapLengths, const std::vector< Spread > &strikeSpreads, const std::vector< std::vector< Handle< Quote > > > &volSpreads, const QuantLib::ext::shared_ptr< SwapIndex > &swapIndexBase, const QuantLib::ext::shared_ptr< SwapIndex > &shortSwapIndexBase, const QuantExt::SabrParametricVolatility::ModelVariant modelVariant, const boost::optional< QuantLib::VolatilityType > outputVolatilityType=boost::none, const std::map< std::pair< Period, Period >, std::vector< std::pair< Real, bool > > > &initialModelParameters={}, const QuantLib::Size maxCalibrationAttempts=10, const QuantLib::Real exitEarlyErrorThreshold=0.005, const QuantLib::Real maxAcceptableError=0.05)
 
void performCalculations () const override
 
QuantLib::ext::shared_ptr< SmileSection > smileSectionImpl (Time optionTime, Time swapLength) const override
 
QuantLib::ext::shared_ptr< ParametricVolatilityparametricVolatility () const
 

Private Attributes

std::map< std::pair< Real, Real >, QuantLib::ext::shared_ptr< ParametricVolatilitySmileSection > > cache_
 
QuantLib::ext::shared_ptr< ParametricVolatilityparametricVolatility_
 
std::vector< Period > atmOptionTenors_
 
std::vector< Period > atmSwapTenors_
 
QuantExt::SabrParametricVolatility::ModelVariant modelVariant_
 
boost::optional< QuantLib::VolatilityType > outputVolatilityType_
 
std::map< std::pair< QuantLib::Period, QuantLib::Period >, std::vector< std::pair< Real, bool > > > initialModelParameters_
 
QuantLib::Size maxCalibrationAttempts_
 
QuantLib::Real exitEarlyErrorThreshold_
 
QuantLib::Real maxAcceptableError_
 

Detailed Description

Definition at line 35 of file swaptionsabrcube.hpp.

Constructor & Destructor Documentation

◆ SwaptionSabrCube()

SwaptionSabrCube ( const Handle< SwaptionVolatilityStructure > &  atmVolStructure,
const std::vector< Period > &  optionTenors,
const std::vector< Period > &  swapTenors,
const std::vector< Period > &  atmOptionTenors,
const std::vector< Period > &  atmSwapLengths,
const std::vector< Spread > &  strikeSpreads,
const std::vector< std::vector< Handle< Quote > > > &  volSpreads,
const QuantLib::ext::shared_ptr< SwapIndex > &  swapIndexBase,
const QuantLib::ext::shared_ptr< SwapIndex > &  shortSwapIndexBase,
const QuantExt::SabrParametricVolatility::ModelVariant  modelVariant,
const boost::optional< QuantLib::VolatilityType >  outputVolatilityType = boost::none,
const std::map< std::pair< Period, Period >, std::vector< std::pair< Real, bool > > > &  initialModelParameters = {},
const QuantLib::Size  maxCalibrationAttempts = 10,
const QuantLib::Real  exitEarlyErrorThreshold = 0.005,
const QuantLib::Real  maxAcceptableError = 0.05 
)

Definition at line 25 of file swaptionsabrcube.cpp.

36 : SwaptionVolatilityCube(atmVolStructure, optionTenors, swapTenors, strikeSpreads, volSpreads, swapIndexBase,
37 shortSwapIndexBase, false),
38 atmOptionTenors_(atmOptionTenors), atmSwapTenors_(atmSwapTenors), modelVariant_(modelVariant),
39 outputVolatilityType_(outputVolatilityType), initialModelParameters_(initialModelParameters),
40 maxCalibrationAttempts_(maxCalibrationAttempts), exitEarlyErrorThreshold_(exitEarlyErrorThreshold),
41 maxAcceptableError_(maxAcceptableError) {
42
43 registerWith(atmVolStructure);
44
45 for (auto const& v : volSpreads)
46 for (auto const& s : v)
47 registerWith(s);
48}
std::map< std::pair< QuantLib::Period, QuantLib::Period >, std::vector< std::pair< Real, bool > > > initialModelParameters_
boost::optional< QuantLib::VolatilityType > outputVolatilityType_
QuantLib::Real exitEarlyErrorThreshold_
QuantExt::SabrParametricVolatility::ModelVariant modelVariant_
std::vector< Period > atmSwapTenors_
QuantLib::Size maxCalibrationAttempts_
std::vector< Period > atmOptionTenors_

Member Function Documentation

◆ performCalculations()

void performCalculations ( ) const
override

Definition at line 61 of file swaptionsabrcube.cpp.

61 {
62
63 SwaptionVolatilityCube::performCalculations();
64
65 cache_.clear();
66
67 // build matrices of vol spreads on either given atm options / swap tenors or the smile option / swap tenors
68
69 std::vector<Period> allOptionTenors = atmOptionTenors_.empty() ? optionTenors_ : atmOptionTenors_;
70 std::vector<Period> allSwapTenors = atmSwapTenors_.empty() ? swapTenors_ : atmSwapTenors_;
71
72 std::vector<Real> allOptionTimes, allSwapLengths;
73 for (auto const& p : allOptionTenors)
74 allOptionTimes.push_back(timeFromReference(optionDateFromTenor(p)));
75 for (auto const& p : allSwapTenors)
76 allSwapLengths.push_back(swapLength(p));
77
78 std::vector<Matrix> interpolatedVolSpreads(strikeSpreads_.size(),
79 Matrix(allSwapLengths.size(), allOptionTimes.size(), Null<Real>()));
80
81 for (Size k = 0; k < strikeSpreads_.size(); ++k) {
82 for (Size i = 0; i < allOptionTenors.size(); ++i) {
83 for (Size j = 0; j < allSwapTenors.size(); ++j) {
84 Size i0 = std::distance(optionTenors_.begin(),
85 std::find(optionTenors_.begin(), optionTenors_.end(), allOptionTenors[i]));
86 Size j0 = std::distance(swapTenors_.begin(),
87 std::find(swapTenors_.begin(), swapTenors_.end(), allSwapTenors[j]));
88 if (i0 < optionTenors_.size() && j0 < swapTenors_.size()) {
89 interpolatedVolSpreads[k](j, i) = volSpreads_[i0 * swapTenors_.size() + j0][k]->value();
90 }
91 }
92 }
93 }
94
95 for (auto& v : interpolatedVolSpreads) {
96 laplaceInterpolationWithErrorHandling(v, allOptionTimes, allSwapLengths);
97 }
98
99 // build market smiles on the grid
100
101 std::vector<ParametricVolatility::MarketSmile> marketSmiles;
102 std::map<std::pair<QuantLib::Real, QuantLib::Real>, std::vector<std::pair<Real, bool>>> modelParameters;
103 for (Size i = 0; i < allOptionTenors.size(); ++i) {
104 for (Size j = 0; j < allSwapTenors.size(); ++j) {
105 Real forward = atmStrike(allOptionTenors[i], allSwapTenors[j]);
106 Real sigma = atmVol()->volatility(allOptionTenors[i], allSwapTenors[j], forward);
107 std::vector<Real> strikes;
108 std::vector<Real> vols;
109 for (Size k = 0; k < strikeSpreads_.size(); ++k) {
110 strikes.push_back(forward + strikeSpreads_[k]);
111 vols.push_back(sigma + interpolatedVolSpreads[k](j, i));
112 }
113 marketSmiles.push_back(ParametricVolatility::MarketSmile{allOptionTimes[i],
114 allSwapLengths[j],
115 forward,
116 shift(allOptionTenors[i], allSwapTenors[j]),
117 {},
118 strikes,
119 vols});
120 if (auto m = initialModelParameters_.find(std::make_pair(allOptionTenors[i], allSwapTenors[j]));
121 m != initialModelParameters_.end()) {
122 modelParameters[std::make_pair(allOptionTimes[i], allSwapLengths[j])] = m->second;
123 }
124 }
125 }
126
127 parametricVolatility_ = boost::make_shared<SabrParametricVolatility>(
129 volatilityType() == QuantLib::Normal ? ParametricVolatility::MarketQuoteType::NormalVolatility
131 Handle<YieldTermStructure>(), modelParameters, maxCalibrationAttempts_, exitEarlyErrorThreshold_,
133}
std::map< std::pair< Real, Real >, QuantLib::ext::shared_ptr< ParametricVolatilitySmileSection > > cache_
QuantLib::ext::shared_ptr< ParametricVolatility > parametricVolatility_
vector< Real > strikes

◆ smileSectionImpl()

boost::shared_ptr< SmileSection > smileSectionImpl ( Time  optionTime,
Time  swapLength 
) const
override

Definition at line 135 of file swaptionsabrcube.cpp.

135 {
136 calculate();
137 if (auto c = cache_.find(std::make_pair(optionTime, swapLength)); c != cache_.end()) {
138 return c->second;
139 }
140 Real forward =
141 atmStrike(optionDateFromTime(optionTime), std::max<int>(1, static_cast<int>(swapLength * 12.0 + 0.5)) * Months);
142 QuantLib::VolatilityType outVolType = outputVolatilityType_ ? *outputVolatilityType_ : volatilityType();
143 auto tmp = boost::make_shared<ParametricVolatilitySmileSection>(
144 optionTime, swapLength, forward, parametricVolatility_,
145 outVolType == QuantLib::Normal ? ParametricVolatility::MarketQuoteType::NormalVolatility
147 cache_[std::make_pair(optionTime, swapLength)] = tmp;
148 return tmp;
149}

◆ parametricVolatility()

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

Definition at line 52 of file swaptionsabrcube.hpp.

52{ return parametricVolatility_; }

Member Data Documentation

◆ cache_

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

Definition at line 55 of file swaptionsabrcube.hpp.

◆ parametricVolatility_

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

Definition at line 56 of file swaptionsabrcube.hpp.

◆ atmOptionTenors_

std::vector<Period> atmOptionTenors_
private

Definition at line 57 of file swaptionsabrcube.hpp.

◆ atmSwapTenors_

std::vector<Period> atmSwapTenors_
private

Definition at line 57 of file swaptionsabrcube.hpp.

◆ modelVariant_

Definition at line 58 of file swaptionsabrcube.hpp.

◆ outputVolatilityType_

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

Definition at line 59 of file swaptionsabrcube.hpp.

◆ initialModelParameters_

std::map<std::pair<QuantLib::Period, QuantLib::Period>, std::vector<std::pair<Real, bool> > > initialModelParameters_
private

Definition at line 60 of file swaptionsabrcube.hpp.

◆ maxCalibrationAttempts_

QuantLib::Size maxCalibrationAttempts_
private

Definition at line 61 of file swaptionsabrcube.hpp.

◆ exitEarlyErrorThreshold_

QuantLib::Real exitEarlyErrorThreshold_
private

Definition at line 62 of file swaptionsabrcube.hpp.

◆ maxAcceptableError_

QuantLib::Real maxAcceptableError_
private

Definition at line 63 of file swaptionsabrcube.hpp.