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

#include <qle/termstructures/blackvolsurfacebfrr.hpp>

+ Collaboration diagram for SimpleDeltaInterpolatedSmile:

Public Member Functions

 SimpleDeltaInterpolatedSmile (const Real spot, const Real domDisc, const Real forDisc, const Real expiryTime, const std::vector< Real > &deltas, const std::vector< Real > &putVols, const std::vector< Real > &callVols, const Real atmVol, const DeltaVolQuote::DeltaType dt, const DeltaVolQuote::AtmType at, const BlackVolatilitySurfaceBFRR::SmileInterpolation smileInterpolation, const Real accuracy=1E-6, const Size maxIterations=1000)
 
Real volatilityAtSimpleDelta (const Real tnp)
 
Real volatility (const Real strike)
 
Real strikeFromDelta (const Option::Type type, const Real delta, const DeltaVolQuote::DeltaType dt)
 
Real atmStrike (const DeltaVolQuote::DeltaType dt, const DeltaVolQuote::AtmType at)
 

Private Member Functions

Real simpleDeltaFromStrike (const Real strike) const
 

Private Attributes

Real spot_
 
Real domDisc_
 
Real forDisc_
 
Real expiryTime_
 
std::vector< Real > deltas_
 
std::vector< Real > putVols_
 
std::vector< Real > callVols_
 
Real atmVol_
 
DeltaVolQuote::DeltaType dt_
 
DeltaVolQuote::AtmType at_
 
BlackVolatilitySurfaceBFRR::SmileInterpolation smileInterpolation_
 
Real accuracy_
 
Size maxIterations_
 
Real forward_
 
std::vector< Real > x_
 
std::vector< Real > y_
 
QuantLib::ext::shared_ptr< Interpolation > interpolation_
 

Detailed Description

Definition at line 120 of file blackvolsurfacebfrr.hpp.

Constructor & Destructor Documentation

◆ SimpleDeltaInterpolatedSmile()

SimpleDeltaInterpolatedSmile ( const Real  spot,
const Real  domDisc,
const Real  forDisc,
const Real  expiryTime,
const std::vector< Real > &  deltas,
const std::vector< Real > &  putVols,
const std::vector< Real > &  callVols,
const Real  atmVol,
const DeltaVolQuote::DeltaType  dt,
const DeltaVolQuote::AtmType  at,
const BlackVolatilitySurfaceBFRR::SmileInterpolation  smileInterpolation,
const Real  accuracy = 1E-6,
const Size  maxIterations = 1000 
)

Definition at line 35 of file blackvolsurfacebfrr.cpp.

41 : spot_(spot), domDisc_(domDisc), forDisc_(forDisc), expiryTime_(expiryTime), deltas_(deltas), putVols_(putVols),
42 callVols_(callVols), atmVol_(atmVol), dt_(dt), at_(at), smileInterpolation_(smileInterpolation),
43 accuracy_(accuracy), maxIterations_(maxIterations) {
44
46
47 std::vector<Real> x, y;
48
49 /* Convert the puts, atm, calls to strikes using the given conventions and then to simple delta
50 using the given conventions. Store the simple deltas as x-values for the interpolation and
51 the log of the vols as y-values */
52
53 for (Size i = 0; i < deltas_.size(); ++i) {
54 try {
55 BlackDeltaCalculator c(Option::Put, dt_, spot_, domDisc_, forDisc_, putVols_[i] * std::sqrt(expiryTime_));
56 x.push_back(simpleDeltaFromStrike(c.strikeFromDelta(-deltas[i])));
57 y.push_back(transformVol(putVols_[i]));
58 } catch (const std::exception& e) {
59 QL_FAIL("SimpleDeltaInterpolatedSmile: strikeFromDelta("
60 << -deltas[i] << ") could not be computed for spot=" << spot_
61 << ", forward=" << spot_ / domDisc_ * forDisc_ << " (domRate=" << -std::log(domDisc_) / expiryTime_
62 << ", forRate=" << -std::log(forDisc) / expiryTime_ << "), putVol=" << putVols_[i]
63 << ", expiry=" << expiryTime_ << ": " << e.what());
64 }
65 }
66
67 try {
68 BlackDeltaCalculator c(Option::Call, dt_, spot_, domDisc_, forDisc_, atmVol * std::sqrt(expiryTime_));
69 x.push_back(simpleDeltaFromStrike(c.atmStrike(at_)));
70 y.push_back(transformVol(atmVol_));
71 } catch (const std::exception& e) {
72 QL_FAIL("SimpleDeltaIinterpolatedSmile: atmStrike could not be computed for spot="
73 << spot_ << ", forward=" << spot_ / domDisc_ * forDisc_
74 << " (domRate=" << -std::log(domDisc_) / expiryTime_ << ", forRate=" << -std::log(forDisc) / expiryTime_
75 << "), atmVol=" << atmVol << ", expiry=" << expiryTime_ << ": " << e.what());
76 }
77
78 for (Size i = deltas_.size(); i > 0; --i) {
79 try {
80 BlackDeltaCalculator c(Option::Call, dt_, spot_, domDisc_, forDisc_,
81 callVols_[i - 1] * std::sqrt(expiryTime_));
82 x.push_back(simpleDeltaFromStrike(c.strikeFromDelta(deltas[i - 1])));
83 y.push_back(transformVol(callVols_[i - 1]));
84 } catch (const std::exception& e) {
85 QL_FAIL("SimpleDeltaInterpolatedSmile: strikeFromDelta("
86 << deltas[i - 1] << ") could not be computed for spot=" << spot_
87 << ", forward=" << spot_ / domDisc_ * forDisc_ << " (domRate=" << -std::log(domDisc_) / expiryTime_
88 << ", forRate=" << -std::log(forDisc) / expiryTime_ << "), callVol=" << callVols_[i - 1]
89 << ", expiry=" << expiryTime_ << ": " << e.what());
90 }
91 }
92
93 /* sort the strikes */
94
95 std::vector<Size> perm(x.size());
96 std::iota(perm.begin(), perm.end(), 0);
97 std::sort(perm.begin(), perm.end(), [&x](Size a, Size b) { return x[a] < x[b]; });
98 for (Size i = 0; i < perm.size(); ++i) {
99 x_.push_back(x[perm[i]]);
100 y_.push_back(y[perm[i]]);
101 }
102
103 /* check the strikes are not (numerically) identical */
104
105 for (Size i = 0; i < x_.size() - 1; ++i) {
106 QL_REQUIRE(!close_enough(x_[i], x_[i + 1]), "SmileDeltaInterpolatedSmile: interpolation points x["
107 << i << "] = x[" << (i + 1) << "] = " << x_[i]
108 << " are numerically identical.");
109 }
110
111 /* Create the interpolation object */
112
114 interpolation_ = QuantLib::ext::make_shared<LinearInterpolation>(x_.begin(), x_.end(), y_.begin());
116 interpolation_ = QuantLib::ext::make_shared<CubicInterpolation>(
117 x_.begin(), x_.end(), y_.begin(), CubicInterpolation::Spline, false, CubicInterpolation::SecondDerivative,
118 0.0, CubicInterpolation::SecondDerivative, 0.0);
119 } else {
120 QL_FAIL("invalid interpolation, this is unexpected");
121 }
122
123 interpolation_->enableExtrapolation();
124}
BlackVolatilitySurfaceBFRR::SmileInterpolation smileInterpolation_
QuantLib::ext::shared_ptr< Interpolation > interpolation_
Real transformVol(const Real v)
Filter close_enough(const RandomVariable &x, const RandomVariable &y)
+ Here is the call graph for this function:

Member Function Documentation

◆ volatilityAtSimpleDelta()

Real volatilityAtSimpleDelta ( const Real  tnp)

Definition at line 179 of file blackvolsurfacebfrr.cpp.

179 {
180 Real tmp = untransformVol((*interpolation_)(simpleDelta));
181 QL_REQUIRE(std::isfinite(tmp), "SimpleDeltaInterpolatedSmile::volatilityAtSimpleDelta() non-finite result ("
182 << tmp << ") for simple delta " << simpleDelta);
183 return tmp;
184}
Real untransformVol(const Real w)
+ Here is the call graph for this function:

◆ volatility()

Real volatility ( const Real  strike)

Definition at line 186 of file blackvolsurfacebfrr.cpp.

186 {
188 if (!std::isfinite(tmp)) {
189 std::ostringstream os;
190 for (Size i = 0; i < x_.size(); ++i) {
191 os << "(" << x_[i] << "," << y_[i] << ")";
192 }
193 QL_FAIL("SimpleDeltaInterpolatedSmile::volatility() non-finite result ("
194 << tmp << ") for strike " << strike << ", simple delta is " << simpleDeltaFromStrike(strike)
195 << ", interpolated value is " << (*interpolation_)(simpleDeltaFromStrike(strike))
196 << ", interpolation data point are " << os.str());
197 }
198 return tmp;
199}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ strikeFromDelta()

Real strikeFromDelta ( const Option::Type  type,
const Real  delta,
const DeltaVolQuote::DeltaType  dt 
)

Definition at line 126 of file blackvolsurfacebfrr.cpp.

127 {
128 Real result = forward_, lastResult;
129 Size iterations = 0;
130 do {
131 Real stddev = std::sqrt(expiryTime_) * volatility(result);
132 try {
133 BlackDeltaCalculator c(type, dt, spot_, domDisc_, forDisc_, stddev);
134 lastResult = result;
135 result = c.strikeFromDelta((type == Option::Call ? 1.0 : -1.0) * delta);
136 } catch (const std::exception& e) {
137 QL_FAIL("SimpleDeltaInterpolatedSmile::strikeFromDelta("
138 << (type == Option::Call ? 1.0 : -1.0) * delta << ") could not be computed for spot=" << spot_
139 << ", forward=" << spot_ / domDisc_ * forDisc_ << " (domRate=" << -std::log(domDisc_) / expiryTime_
140 << ", forRate=" << -std::log(forDisc_) / expiryTime_ << "), vol=" << stddev / std::sqrt(expiryTime_)
141 << ", expiry=" << expiryTime_ << ": " << e.what());
142 }
143 } while (std::abs((result - lastResult) / lastResult) > accuracy_ && ++iterations < maxIterations_);
144 QL_REQUIRE(iterations < maxIterations_,
145 "SmileDeltaInterpolatedSmile::strikeFromDelta("
146 << (type == Option::Call ? 1.0 : -1.0) * delta << "): max iterations (" << maxIterations_
147 << "), no solution found for accuracy " << accuracy_ << ", last iterations: " << lastResult << "/"
148 << result << ", spot=" << spot_ << ", forward=" << spot_ / domDisc_ * forDisc_
149 << " (domRate=" << -std::log(domDisc_) / expiryTime_
150 << ", forRate=" << -std::log(forDisc_) / expiryTime_ << "), expiry=" << expiryTime_);
151 return result;
152}
+ Here is the call graph for this function:

◆ atmStrike()

Real atmStrike ( const DeltaVolQuote::DeltaType  dt,
const DeltaVolQuote::AtmType  at 
)

Definition at line 154 of file blackvolsurfacebfrr.cpp.

154 {
155 Real result = forward_, lastResult;
156 Size iterations = 0;
157 do {
158 Real stddev = std::sqrt(expiryTime_) * volatility(result);
159 try {
160 BlackDeltaCalculator c(Option::Call, dt, spot_, domDisc_, forDisc_, stddev);
161 lastResult = result;
162 result = c.atmStrike(at);
163 } catch (const std::exception& e) {
164 QL_FAIL("SimpleDeltaInterpolatedSmile::atmStrike() could not be computed for spot="
165 << spot_ << ", forward=" << spot_ / domDisc_ * forDisc_ << " (domRate="
166 << -std::log(domDisc_) / expiryTime_ << ", forRate=" << -std::log(forDisc_) / expiryTime_
167 << "), vol=" << stddev / std::sqrt(expiryTime_) << ", expiry=" << expiryTime_ << ": " << e.what());
168 }
169 } while (std::abs((result - lastResult) / lastResult) > accuracy_ && ++iterations < maxIterations_);
170 QL_REQUIRE(iterations < maxIterations_,
171 "SmileDeltaInterpolatedSmile::atmStrike(): max iterations ("
172 << maxIterations_ << "), no solution found for accuracy " << accuracy_
173 << ", last iterations: " << lastResult << "/" << result << ", spot=" << spot_
174 << ", forward=" << spot_ / domDisc_ * forDisc_ << " (domRate=" << -std::log(domDisc_) / expiryTime_
175 << ", forRate=" << -std::log(forDisc_) / expiryTime_ << "), expiry=" << expiryTime_);
176 return result;
177}
+ Here is the call graph for this function:

◆ simpleDeltaFromStrike()

Real simpleDeltaFromStrike ( const Real  strike) const
private

Definition at line 201 of file blackvolsurfacebfrr.cpp.

201 {
202 if (close_enough(strike, 0.0))
203 return 0.0;
204 CumulativeNormalDistribution Phi;
205 return Phi(std::log(strike / forward_) / (atmVol_ * std::sqrt(expiryTime_)));
206}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ spot_

Real spot_
private

Definition at line 137 of file blackvolsurfacebfrr.hpp.

◆ domDisc_

Real domDisc_
private

Definition at line 137 of file blackvolsurfacebfrr.hpp.

◆ forDisc_

Real forDisc_
private

Definition at line 137 of file blackvolsurfacebfrr.hpp.

◆ expiryTime_

Real expiryTime_
private

Definition at line 137 of file blackvolsurfacebfrr.hpp.

◆ deltas_

std::vector<Real> deltas_
private

Definition at line 138 of file blackvolsurfacebfrr.hpp.

◆ putVols_

std::vector<Real> putVols_
private

Definition at line 138 of file blackvolsurfacebfrr.hpp.

◆ callVols_

std::vector<Real> callVols_
private

Definition at line 138 of file blackvolsurfacebfrr.hpp.

◆ atmVol_

Real atmVol_
private

Definition at line 139 of file blackvolsurfacebfrr.hpp.

◆ dt_

DeltaVolQuote::DeltaType dt_
private

Definition at line 140 of file blackvolsurfacebfrr.hpp.

◆ at_

DeltaVolQuote::AtmType at_
private

Definition at line 141 of file blackvolsurfacebfrr.hpp.

◆ smileInterpolation_

Definition at line 142 of file blackvolsurfacebfrr.hpp.

◆ accuracy_

Real accuracy_
private

Definition at line 143 of file blackvolsurfacebfrr.hpp.

◆ maxIterations_

Size maxIterations_
private

Definition at line 144 of file blackvolsurfacebfrr.hpp.

◆ forward_

Real forward_
private

Definition at line 146 of file blackvolsurfacebfrr.hpp.

◆ x_

std::vector<Real> x_
private

Definition at line 147 of file blackvolsurfacebfrr.hpp.

◆ y_

std::vector<Real> y_
private

Definition at line 147 of file blackvolsurfacebfrr.hpp.

◆ interpolation_

QuantLib::ext::shared_ptr<Interpolation> interpolation_
private

Definition at line 148 of file blackvolsurfacebfrr.hpp.