27 const ext::shared_ptr<HestonModel>& model,
Real L,
Size N)
35 rho_ (model_->
rho()) ,
36 v0_ (model_->
v0()) { }
56 "not an European option");
59 const ext::shared_ptr<PlainVanillaPayoff>
payoff =
60 ext::dynamic_pointer_cast<PlainVanillaPayoff>(
arguments_.payoff);
63 const ext::shared_ptr<HestonProcess> process =
model_->process();
66 const Time maturity = process->time(maturityDate);
68 const Real cum1 =
c1(maturity);
69 const Real w = std::sqrt(std::fabs(
c2(maturity))
75 const Real spot = process->s0()->value();
76 QL_REQUIRE(spot > 0.0,
"negative or null underlying given");
79 = process->riskFreeRate()->discount(maturityDate);
81 = process->dividendYield()->discount(maturityDate);
82 const Real fwd = spot*qf/df;
83 const Real x = std::log(fwd/k);
85 const Real a = x + cum1 -
L_*w;
90 if (x >=
b/2 || x <= a/2) {
93 results_.value = std::max(-spot*qf+k*df,0.0);
95 results_.value = std::max(spot*qf-k*df,0.0);
104 const Real expA = std::exp(a);
105 Real s =
chF(0, maturity).real()*(expA-1-a)*
d;
109 const Real U_n = 2.0*
d*( 1.0/(1.0 +
r*
r)
110 *(expA +
r*std::sin(
r*a) - std::cos(
r*a)) - 1.0/
r*std::sin(
r*a));
112 s += U_n*(
chF(
r, maturity)
113 *std::exp(std::complex<Real>(0,
r*(x-a)))).real();
120 = process->dividendYield()->discount(maturityDate);
124 QL_FAIL(
"unknown payoff type");
128 return std::log(
model_->process()->dividendYield()->discount(
t)
129 /
model_->process()->riskFreeRate()->discount(
t));
136 const std::complex<Real> D = std::sqrt(
138 + std::complex<Real>(u*u, u)*sigma2);
142 const std::complex<Real> G = (g-D)/(g+D);
145 v0_/(sigma2)*(1.0-std::exp(-D*
t))/(1.0-G*std::exp(-D*
t))
147 -2.0*std::log((1.0-G*std::exp(-D*
t))/(1.0-G)))
209 std::exp(3*
kappa_*
t)*(2*(-11*sigma3 -
231 const Real sigma4 = sigma2*sigma2;
234 const Real kappa4 = kappa2*kappa2;
235 const Real kappa5 = kappa2*kappa3;
236 const Real kappa6 = kappa3*kappa3;
237 const Real kappa7 = kappa4*kappa3;
241 const Time t3 = t2*
t;
245 3*std::exp(4*
kappa_*
t)*((-93*sigma4 +
246 64*kappa5*(
t + 4*rho2*
t) +
248 32*kappa2*sigma2*(11 + 50*rho2 +
253 sigma2)*(4*kappa2*(1 + 4*rho2) -
255 24*std::exp(
kappa_*
t)*sigma2*(-2*kappa2*(-1 +
264 sigma2*t2)*
theta_ - 2*(3 + 12*rho2 -
272 sigma3*t3)*
theta_ + (-48*rho3 + 18*(1
274 + sigma3*t3)*
v0_) + 12*kappa4*((-4 -
276 14*rho2)*sigma2*t2 +
rho_*sigma3*t3)*
theta_ + (8*rho2 -
278 8*rho2)*sigma2*t2 -
rho_*sigma3*t3)*
v0_) -
279 6*kappa2*sigma2*((15 + 80*rho2 -
295 return c3(
t)/std::pow(
c2(
t), 1.5);
void calculate() const override
std::complex< Real > chF(Real u, Real t) const
Real kurtosis(Time t) const
COSHestonEngine(const ext::shared_ptr< HestonModel > &model, Real L=16, Size N=200)
Base class for some pricing engine on a particular model.
Handle< HestonModel > model_
Heston model for the stochastic volatility of an asset.
Vanilla option (no discrete dividends, no barriers) on a single asset.
Heston engine based on Fourier-Cosine series expansions.
#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)
ext::function< Real(Real)> b
Real Time
continuous quantity with 1-year units
Real DiscountFactor
discount factor between dates
std::size_t Size
size of a container
ext::shared_ptr< QuantLib::Payoff > payoff
functionals and combinators not included in the STL
ext::shared_ptr< YieldTermStructure > r