28#if defined(QL_PATCH_MSVC)
29#pragma warning(disable: 4180)
40 const ext::shared_ptr<HestonModel>& model,
52 "not an European option");
55 ext::shared_ptr<PlainVanillaPayoff>
payoff =
56 ext::dynamic_pointer_cast<PlainVanillaPayoff>(
arguments_.payoff);
59 const ext::shared_ptr<HestonProcess>& process =
model_->process();
61 const Real riskFreeDiscount = process->riskFreeRate()->discount(
63 const Real dividendDiscount = process->dividendYield()->discount(
66 const Real spotPrice = process->s0()->value();
67 QL_REQUIRE(spotPrice > 0.0,
"negative or null underlying given");
74 const Real forward = spotPrice*dividendDiscount/riskFreeDiscount;
99 QL_FAIL(
"unknown expansion formula");
102 riskFreeDiscount, 0);
122 const Real forward)
const {
123 Real x = log(strike/forward);
125 return std::max(1e-8,vol);
139 pow(delta,2)*
ekt*pow(
rho,2)*
178 y - (-4 + delta*
rho*
t + 2*
ekt*(2 + delta*
rho*
t))*fastpow(
y,2))))/
203 Real sigma00 = v0Sqrt;
209 coeffs[0] = sigma00*sigma00+a00*term;
210 coeffs[1] = sigma00*sigma01*2+a01*term;
211 coeffs[2] = sigma00*sigma02*2+sigma01*sigma01+a02*term;
212 coeffs[3] = sigma01*sigma02*2;
213 coeffs[4] = sigma02*sigma02;
217 const Real forward)
const {
218 Real x = log(strike/forward);
220 var = std::max(1e-8,var);
226 return (96*pow(delta,2)*
ekt*pow(
kappa,3)*
260 pow(delta,3)*
ekt*pow(
rho,3)*
285 2*(-1 +
e2kt*(1 + 2*pow(
rho,2)) -
411 2*
y*(-3 - 3*
ekt*(1 + 4*pow(
rho,2)) + 2*pow(
rho,2)*
t*
y) +
466 2*(-1 +
e2kt*(1 + 4*pow(
rho,2)) -
476 2*(-1 +
e2kt*(1 + 2*pow(
rho,2)) -
537 6*pow(
y,2) + 24*pow(
kappa,3)*pow(
t,2)*
556 6*pow(
y,2) + 24*pow(
kappa,3)*pow(
t,2)*
570 2*
y*(-3 - 3*
ekt*(1 + 4*pow(
rho,2)) + 2*pow(
rho,2)*
t*
y) +
572 ekt*(15 + pow(
rho,2)*(72 - 4*
t*
y)))) +
585 2*
y*(-3 - 3*
ekt*(1 + 4*pow(
rho,2)) + 2*pow(
rho,2)*
t*
y) +
587 ekt*(15 + pow(
rho,2)*(72 - 4*
t*
y)))) +
604 2*(-1 +
ekt*(-1 + 2*pow(
rho,2)))*pow(
y,3)) -
607 (2 - 12*pow(
rho,2) - 4*delta*
rho*
t + 25*delta*pow(
rho,3)*
t) +
611 24*delta*pow(
rho,3)*
t) -
612 4*
ekt*(4 - 20*pow(
rho,2) - 10*delta*
rho*
t + 39*delta*pow(
rho,3)*
t)
615 140*delta*pow(
rho,3)*
t) +
621 ((-24 + 128*pow(
rho,2) + 9*delta*
rho*
t - 144*delta*pow(
rho,3)*
t -
625 (-72 + 320*pow(
rho,2) + 27*delta*
rho*
t - 360*delta*pow(
rho,3)*
t -
629 2*(32 - 128*pow(
rho,2) + 12*
e2kt*(-1 + 2*pow(
rho,2)) -
630 15*delta*
rho*
t + 144*delta*pow(
rho,3)*
t +
633 4*(4 - 16*pow(
rho,2) - 3*delta*
rho*
t + 18*delta*pow(
rho,3)*
t +
634 ekt*(-4 + 16*pow(
rho,2) - 2*delta*
rho*
t + 11*delta*pow(
rho,3)*
t))*
645 12*(-1 + 2*pow(
rho,2))*
y) +
647 2*(9 - 30*pow(
rho,2) + 7*delta*pow(
rho,3)*
t)*pow(
theta,2)*
y +
649 pow(
rho,2)*(4 + 13*delta*
rho*
t)*pow(
y,3)) +
653 pow(
y,3)) + 4*delta*pow(
rho,3)*
t*
669 92*pow(
kappa,3)*pow(
t,3))) +
671 48*pow(
kappa,3)*pow(
t,3) -
684 23*pow(
kappa,3)*pow(
t,3))) +
686 16*pow(
kappa,3)*pow(
t,3)) +
698 23*pow(
kappa,3)*pow(
t,3))) +
700 16*pow(
kappa,3)*pow(
t,3)) -
704 60*pow(
kappa,3)*pow(
t,3) -
710 46*pow(
kappa,3)*pow(
t,3))) +
713 2*pow(
kappa,3)*pow(
t,3))) +
716 23*pow(
kappa,3)*pow(
t,3))))*pow(
y,3)))/
734 const Real forward)
const {
735 Real x = log(strike/forward);
737 return std::max(1e-8,vol);
FordeHestonExpansion(Real kappa, Real theta, Real sigma, Real v0, Real rho, Real term)
Real impliedVolatility(Real strike, Real forward) const override
Base class for some pricing engine on a particular model.
Handle< HestonModel > model_
HestonExpansionEngine(const ext::shared_ptr< HestonModel > &model, HestonExpansionFormula formula)
const HestonExpansionFormula formula_
void calculate() const override
Heston model for the stochastic volatility of an asset.
Real z0(Real t, Real kappa, Real theta, Real delta, Real y, Real rho) const
LPP2HestonExpansion(Real kappa, Real theta, Real sigma, Real v0, Real rho, Real term)
Real impliedVolatility(Real strike, Real forward) const override
Real z2(Real t, Real kappa, Real theta, Real delta, Real y, Real rho) const
Real z1(Real t, Real kappa, Real theta, Real delta, Real y, Real rho) const
Real z3(Real t, Real kappa, Real theta, Real delta, Real y, Real rho) const
LPP3HestonExpansion(Real kappa, Real theta, Real sigma, Real v0, Real rho, Real term)
Real z0(Real t, Real kappa, Real theta, Real delta, Real y, Real rho) const
Real impliedVolatility(Real strike, Real forward) const override
Real z2(Real t, Real kappa, Real theta, Real delta, Real y, Real rho) const
Real z1(Real t, Real kappa, Real theta, Real delta, Real y, Real rho) const
Vanilla option (no discrete dividends, no barriers) on a single asset.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
analytic Heston expansion engine
ext::shared_ptr< QuantLib::Payoff > payoff
Real blackFormula(Option::Type optionType, Real strike, Real forward, Real stdDev, Real discount, Real displacement)
Payoffs for various options.