30#ifndef quantlib_sabr_interpolation_hpp
31#define quantlib_sabr_interpolation_hpp
45 const std::vector<Real>& params,
46 const std::vector<Real>& addParams)
50 <<
shift_ <<
" not allowed");
67 const Real &forward,
const Real expiryTime,
68 const std::vector<Real> &addParams) {
73 params[0] = 0.2 * (params[1] < 0.9999 ?
74 Real(std::pow(forward + (addParams.empty() ? 0.0 : addParams[0]),
78 params[2] = std::sqrt(0.4);
82 void guess(
Array &values,
const std::vector<bool> ¶mIsFixed,
83 const Real &forward,
const Real expiryTime,
84 const std::vector<Real> &
r,
const std::vector<Real> &addParams) {
87 values[1] = (1.0 - 2E-6) *
r[j++] + 1E-6;
88 if (!paramIsFixed[0]) {
89 values[0] = (1.0 - 2E-6) *
r[j++] + 1E-6;
91 if (values[1] < 0.999)
93 std::pow(forward + (addParams.empty() ? 0.0 : addParams[0]), 1.0 - values[1]);
96 values[2] = 1.5 *
r[j++] + 1E-6;
98 values[3] = (2.0 *
r[j++] - 1.0) * (1.0 - 1E-6);
104 const std::vector<Real> &,
const Real) {
109 x[1] = std::sqrt(-std::log(
y[1]));
112 x[3] = std::asin(
y[3] /
eps2());
116 const std::vector<Real> &,
const Real) {
118 y[0] = std::fabs(x[0]) < 5.0 ?
Real(x[0] * x[0] +
eps1())
119 :
Real((10.0 * std::fabs(x[0]) - 25.0) +
eps1());
121 y[1] = std::fabs(x[1]) < std::sqrt(-std::log(
eps1()))
122 ? std::exp(-(x[1] * x[1]))
124 y[2] = std::fabs(x[2]) < 5.0 ?
Real(x[2] * x[2] +
eps1())
125 :
Real((10.0 * std::fabs(x[2]) - 25.0) +
eps1());
126 y[3] = std::fabs(x[3]) < 2.5 *
M_PI
128 :
Real(
eps2() * (x[3] > 0.0 ? 1.0 : (-1.0)));
132 const std::vector<Real> &addParams) {
138 const std::vector<Real> ¶ms,
139 const std::vector<Real> &addParams) {
140 return ext::make_shared<type>(
t, forward, params, addParams);
152 template <
class I1,
class I2>
158 Real rho,
bool alphaIsFixed,
bool betaIsFixed,
159 bool nuIsFixed,
bool rhoIsFixed,
bool vegaWeighted =
true,
161 ext::shared_ptr<EndCriteria>(),
162 const ext::shared_ptr<OptimizationMethod> &optMethod =
163 ext::shared_ptr<OptimizationMethod>(),
164 const Real errorAccept = 0.0020,
165 const bool useMaxError =
false,
166 const Size maxGuesses = 50,
const Real shift = 0.0,
169 impl_ = ext::shared_ptr<Interpolation::Impl>(
173 {alphaIsFixed, betaIsFixed, nuIsFixed, rhoIsFixed},
174 vegaWeighted,
endCriteria, optMethod, errorAccept, useMaxError,
175 maxGuesses, {shift}, volatilityType));
210 bool vegaWeighted =
false,
211 ext::shared_ptr<EndCriteria> endCriteria = ext::shared_ptr<EndCriteria>(),
212 ext::shared_ptr<OptimizationMethod> optMethod = ext::shared_ptr<OptimizationMethod>(),
213 const Real errorAccept = 0.0020,
214 const bool useMaxError =
false,
215 const Size maxGuesses = 50,
216 const Real shift = 0.0)
222 template <
class I1,
class I2>
224 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.
SABR interpolation factory and traits
const ext::shared_ptr< OptimizationMethod > optMethod_
const ext::shared_ptr< EndCriteria > endCriteria_
SABR(Time t, Real forward, Real alpha, Real beta, Real nu, Real rho, bool alphaIsFixed, bool betaIsFixed, bool nuIsFixed, bool rhoIsFixed, 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, const Real shift=0.0)
Interpolation interpolate(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin) const
SABR smile interpolation between discrete volatility points.
EndCriteria::Type endCriteria()
const detail::XABRCoeffHolder< detail::SABRSpecs > & coeffs() const
SABRInterpolation(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, Time t, const Real &forward, Real alpha, Real beta, Real nu, Real rho, bool alphaIsFixed, bool betaIsFixed, bool nuIsFixed, bool rhoIsFixed, 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, const Real shift=0.0, const VolatilityType volatilityType=VolatilityType::ShiftedLognormal)
const std::vector< Real > & interpolationWeights() const
const std::vector< Real > & params_
SABRWrapper(const Time t, const Real &forward, const std::vector< Real > ¶ms, const std::vector< Real > &addParams)
Real volatility(const Real x, const VolatilityType volatilityType)
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
void validateSabrParameters(Real alpha, Real beta, Real nu, Real rho)
Real blackFormulaStdDevDerivative(Rate strike, Rate forward, Real stdDev, Real discount, Real displacement)
Real shiftedSabrVolatility(Rate strike, Rate forward, Time expiryTime, Real alpha, Real beta, Real nu, Real rho, Real shift, VolatilityType volatilityType)
ext::shared_ptr< YieldTermStructure > r
Array inverse(const Array &y, const std::vector< bool > &, const std::vector< Real > &, const Real)
Array direct(const Array &x, 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)
void defaultValues(std::vector< Real > ¶ms, std::vector< bool > &, const Real &forward, const Real expiryTime, const std::vector< Real > &addParams)
generic interpolation class for sabr style underlying models like the Hagan 2002 expansion,...