44
46
47 std::vector<Real> x, y;
48
49
50
51
52
53 for (Size i = 0; i <
deltas_.size(); ++i) {
54 try {
58 } catch (const std::exception& e) {
59 QL_FAIL("SimpleDeltaInterpolatedSmile: strikeFromDelta("
60 << -deltas[i] <<
") could not be computed for spot=" <<
spot_
64 }
65 }
66
67 try {
71 } catch (const std::exception& e) {
72 QL_FAIL("SimpleDeltaIinterpolatedSmile: atmStrike could not be computed for spot="
75 <<
"), atmVol=" << atmVol <<
", expiry=" <<
expiryTime_ <<
": " << e.what());
76 }
77
78 for (Size i =
deltas_.size(); i > 0; --i) {
79 try {
84 } catch (const std::exception& e) {
85 QL_FAIL("SimpleDeltaInterpolatedSmile: strikeFromDelta("
86 << deltas[i - 1] <<
") could not be computed for spot=" <<
spot_
90 }
91 }
92
93
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
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
112
114 interpolation_ = QuantLib::ext::make_shared<LinearInterpolation>(
x_.begin(),
x_.end(),
y_.begin());
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
124}
DeltaVolQuote::DeltaType dt_
Real simpleDeltaFromStrike(const Real strike) const
std::vector< Real > deltas_
std::vector< Real > callVols_
DeltaVolQuote::AtmType at_
BlackVolatilitySurfaceBFRR::SmileInterpolation smileInterpolation_
QuantLib::ext::shared_ptr< Interpolation > interpolation_
std::vector< Real > putVols_
Real transformVol(const Real v)
Filter close_enough(const RandomVariable &x, const RandomVariable &y)