24#ifndef quantlib_zabr_interpolation_hpp
25#define quantlib_zabr_interpolation_hpp
39 std::vector<bool> ¶mIsFixed,
const Real &forward,
40 const Real expiryTime,
const std::vector<Real>& addParams) {
47 (params[1] < 0.9999 ? std::pow(forward, 1.0 - params[1]) :
Real(1.0));
49 params[2] = std::sqrt(0.4);
55 void guess(
Array &values,
const std::vector<bool> ¶mIsFixed,
56 const Real &forward,
const Real expiryTime,
57 const std::vector<Real> &
r,
const std::vector<Real>& addParams) {
60 values[1] = (1.0 - 2E-6) *
r[j++] + 1E-6;
61 if (!paramIsFixed[0]) {
62 values[0] = (1.0 - 2E-6) *
r[j++] + 1E-6;
64 if (values[1] < 0.999)
65 values[0] *= std::pow(forward, 1.0 - values[1]);
68 values[2] = 1.5 *
r[j++] + 1E-6;
70 values[3] = (2.0 *
r[j++] - 1.0) * (1.0 - 1E-6);
72 values[4] =
r[j++] * 2.0;
78 const std::vector<Real> &,
const Real) {
80 x[0] =
y[0] < 25.0 +
eps1() ? std::sqrt(
y[0] -
eps1())
82 x[1] = std::sqrt(-std::log(
y[1]));
83 x[2] = std::tan(
M_PI*(
y[4]/5.0-0.5));
84 x[3] = std::asin(
y[3] /
eps2());
85 x[4] = std::tan(
M_PI*(
y[4]/1.9-0.5));
89 const std::vector<Real> &,
const Real) {
91 y[0] = std::fabs(x[0]) < 5.0 ?
Real(x[0] * x[0] +
eps1())
92 : (10.0 * std::fabs(x[0]) - 25.0) +
eps1();
93 y[1] = std::fabs(x[1]) < std::sqrt(-std::log(
eps1()))
94 ? std::exp(-(x[1] * x[1]))
97 y[2] = (std::atan(x[2])/
M_PI + 0.5) * 5.0;
98 y[3] = std::fabs(x[3]) < 2.5 *
M_PI
99 ?
eps2() * std::sin(x[3])
100 :
Real(
eps2() * (x[3] > 0.0 ? 1.0 : (-1.0)));
102 y[4] = (std::atan(x[4])/
M_PI + 0.5) * 1.9;
106 const std::vector<Real> &addParams) {
111 const std::vector<Real> ¶ms,
112 const std::vector<Real> &addParams) {
113 return ext::make_shared<type>(
t, forward, params);
122 template <
class I1,
class I2>
129 Real gamma,
bool alphaIsFixed,
bool betaIsFixed,
bool nuIsFixed,
130 bool rhoIsFixed,
bool gammaIsFixed,
bool vegaWeighted =
true,
132 ext::shared_ptr<EndCriteria>(),
133 const ext::shared_ptr<OptimizationMethod> &optMethod =
134 ext::shared_ptr<OptimizationMethod>(),
135 const Real errorAccept = 0.0020,
const bool useMaxError =
false,
136 const Size maxGuesses = 50) {
137 impl_ = ext::shared_ptr<
143 {alphaIsFixed, betaIsFixed, nuIsFixed, rhoIsFixed, gammaIsFixed},
144 vegaWeighted,
endCriteria, optMethod, errorAccept, useMaxError,
168template<
class Evaluation>
class Zabr {
182 bool vegaWeighted =
false,
183 ext::shared_ptr<EndCriteria> endCriteria = ext::shared_ptr<EndCriteria>(),
184 ext::shared_ptr<OptimizationMethod> optMethod = ext::shared_ptr<OptimizationMethod>(),
185 const Real errorAccept = 0.0020,
186 const bool useMaxError =
false,
187 const Size maxGuesses = 50)
193 template <
class I1,
class I2>
195 const I2 &yBegin)
const {
1-D array used in linear algebra.
abstract base class for interpolation implementations
base class for 1-D interpolations.
ext::shared_ptr< Impl > impl_
template class providing a null value for a given type.
no arbtrage sabr interpolation factory and traits
const ext::shared_ptr< OptimizationMethod > optMethod_
const ext::shared_ptr< EndCriteria > endCriteria_
Zabr(Time t, Real forward, Real alpha, Real beta, Real nu, Real rho, Real gamma, bool alphaIsFixed, bool betaIsFixed, bool nuIsFixed, bool rhoIsFixed, bool gammaIsFixed, 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
zabr smile interpolation between discrete volatility points.
EndCriteria::Type endCriteria()
const detail::XABRCoeffHolder< detail::ZabrSpecs< Evaluation > > & coeffs() const
ZabrInterpolation(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, Time t, const Real &forward, Real alpha, Real beta, Real nu, Real rho, Real gamma, bool alphaIsFixed, bool betaIsFixed, bool nuIsFixed, bool rhoIsFixed, bool gammaIsFixed, 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 std::vector< Real > & interpolationWeights() const
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
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)
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)
ZabrSmileSection< Evaluation > type
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 > ¶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,...