24#ifndef quantlib_svi_interpolation_hpp
25#define quantlib_svi_interpolation_hpp
37 QL_REQUIRE(
b >= 0.0,
"b (" <<
b <<
") must be non negative");
41 "a + b sigma sqrt(1-rho^2) (a=" << a <<
", b=" <<
b <<
", sigma="
43 <<
") must be non negative");
45 "b(1+|rho|) must be less than or equal to 4, (b=" <<
b <<
", rho=" <<
rho <<
")");
52 b * (
rho * (k - m) + std::sqrt((k - m) * (k - m) +
sigma *
sigma));
60 std::vector<bool> ¶mIsFixed,
const Real &forward,
61 const Real expiryTime,
62 const std::vector<Real> &addParams) {
70 params[1] = 2.0 / (1.0 + std::fabs(params[3]));
73 0.20 * 0.20 * expiryTime -
74 params[1] * (params[3] * (-params[4]) +
75 std::sqrt((-params[4]) * (-params[4]) +
76 params[2] * params[2])),
77 -params[1] * params[2] *
78 std::sqrt(1.0 - params[3] * params[3]) +
eps1());
81 void guess(
Array &values,
const std::vector<bool> ¶mIsFixed,
82 const Real &forward,
const Real expiryTime,
83 const std::vector<Real> &
r,
const std::vector<Real> &addParams) {
86 values[2] =
r[j++] +
eps1();
88 values[3] = (2.0 *
r[j++] - 1.0) *
eps2();
90 values[4] = (2.0 *
r[j++] - 1.0);
92 values[1] =
r[j++] * 4.0 / (1.0 + std::fabs(values[3])) *
eps2();
94 values[0] =
r[j++] * expiryTime -
95 eps2() * (values[1] * values[2] *
96 std::sqrt(1.0 - values[3] * values[3]));
99 const std::vector<Real> &,
const Real) {
101 x[2] = std::sqrt(
y[2] -
eps1());
102 x[3] = std::asin(
y[3] /
eps2());
104 x[1] = std::tan(
y[1] / 4.0 * (1.0 + std::fabs(
y[3])) /
eps2() *
M_PI -
106 x[0] = std::sqrt(
y[0] -
eps1() +
107 y[1] *
y[2] * std::sqrt(1.0 -
y[3] *
y[3]));
113 const std::vector<Real> ¶ms,
const Real forward) {
115 y[2] = x[2] * x[2] +
eps1();
116 y[3] = std::sin(x[3]) *
eps2();
121 y[1] = (std::atan(x[1]) +
M_PI / 2.0) /
M_PI *
eps2() * 4.0 /
122 (1.0 + std::fabs(
y[3]));
126 y[0] =
eps1() + x[0] * x[0] -
127 y[1] *
y[2] * std::sqrt(1.0 -
y[3] *
y[3]);
131 const std::vector<Real> &addParams) {
136 const std::vector<Real> ¶ms,
137 const std::vector<Real> &addParams) {
138 return ext::make_shared<type>(
t, forward, params);
146 template <
class I1,
class I2>
152 Real m,
bool aIsFixed,
bool bIsFixed,
bool sigmaIsFixed,
153 bool rhoIsFixed,
bool mIsFixed,
bool vegaWeighted =
true,
155 ext::shared_ptr<EndCriteria>(),
156 const ext::shared_ptr<OptimizationMethod> &optMethod =
157 ext::shared_ptr<OptimizationMethod>(),
158 const Real errorAccept = 0.0020,
159 const bool useMaxError =
false,
160 const Size maxGuesses = 50) {
162 impl_ = ext::shared_ptr<Interpolation::Impl>(
166 {aIsFixed, bIsFixed, sigmaIsFixed, rhoIsFixed, mIsFixed},
167 vegaWeighted,
endCriteria, optMethod, errorAccept, useMaxError,
205 bool vegaWeighted =
false,
206 ext::shared_ptr<EndCriteria> endCriteria = ext::shared_ptr<EndCriteria>(),
207 ext::shared_ptr<OptimizationMethod> optMethod = ext::shared_ptr<OptimizationMethod>(),
208 const Real errorAccept = 0.0020,
209 const bool useMaxError =
false,
210 const Size maxGuesses = 50)
216 template <
class I1,
class I2>
218 const I2 &yBegin)
const {
1-D array used in linear algebra.
base class for 1-D interpolations.
ext::shared_ptr< Impl > impl_
template class providing a null value for a given type.
Svi interpolation factory and traits
const ext::shared_ptr< OptimizationMethod > optMethod_
const ext::shared_ptr< EndCriteria > endCriteria_
Svi(Time t, Real forward, Real a, Real b, Real sigma, Real rho, Real m, bool aIsFixed, bool bIsFixed, bool sigmaIsFixed, bool rhoIsFixed, bool mIsFixed, bool vegaWeighted=false, ext::shared_ptr< EndCriteria > endCriteria=ext::shared_ptr< EndCriteria >(), ext::shared_ptr< OptimizationMethod > optMethod=ext::shared_ptr< OptimizationMethod >(), const Real errorAccept=0.0020, const bool useMaxError=false, const Size maxGuesses=50)
Interpolation interpolate(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin) const
Svi smile interpolation between discrete volatility points.
EndCriteria::Type endCriteria()
const detail::XABRCoeffHolder< detail::SviSpecs > & coeffs() const
const std::vector< Real > & interpolationWeights() const
SviInterpolation(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, Time t, const Real &forward, Real a, Real b, Real sigma, Real rho, Real m, bool aIsFixed, bool bIsFixed, bool sigmaIsFixed, bool rhoIsFixed, bool mIsFixed, bool vegaWeighted=true, const ext::shared_ptr< EndCriteria > &endCriteria=ext::shared_ptr< EndCriteria >(), const ext::shared_ptr< OptimizationMethod > &optMethod=ext::shared_ptr< OptimizationMethod >(), const Real errorAccept=0.0020, const bool useMaxError=false, const Size maxGuesses=50)
Stochastic Volatility Inspired Smile Section.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
ext::function< Real(Real)> b
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
SviSmileSection SviWrapper
void checkSviParameters(const Real a, const Real b, const Real sigma, const Real rho, const Real m, const Time tte)
Real sviTotalVariance(const Real a, const Real b, const Real sigma, const Real rho, const Real m, const Real k)
Real blackFormulaStdDevDerivative(Rate strike, Rate forward, Real stdDev, Real discount, Real displacement)
ext::shared_ptr< YieldTermStructure > r
Array inverse(const Array &y, const std::vector< bool > &, const std::vector< Real > &, const Real)
Real weight(const Real strike, const Real forward, const Real stdDev, const std::vector< Real > &addParams)
void guess(Array &values, const std::vector< bool > ¶mIsFixed, const Real &forward, const Real expiryTime, const std::vector< Real > &r, const std::vector< Real > &addParams)
ext::shared_ptr< type > instance(const Time t, const Real &forward, const std::vector< Real > ¶ms, const std::vector< Real > &addParams)
Array direct(const Array &x, const std::vector< bool > ¶mIsFixed, const std::vector< Real > ¶ms, const Real forward)
void defaultValues(std::vector< Real > ¶ms, std::vector< bool > ¶mIsFixed, const Real &forward, const Real expiryTime, const std::vector< Real > &addParams)
generic interpolation class for sabr style underlying models like the Hagan 2002 expansion,...