33 Real relativeAccuracy,
35 : process_(
std::move(process)), relativeAccuracy_(relativeAccuracy),
36 maxIterations_(maxIterations) {
43 Real jumpSquareVol =
process_->logJumpVolatility()->value()
44 *
process_->logJumpVolatility()->value();
45 Real muPlusHalfSquareVol =
process_->logMeanJump()->value()
48 Real k = std::exp(muPlusHalfSquareVol) - 1.0;
49 Real lambda = (k+1.0) *
process_->jumpIntensity()->value();
51 ext::shared_ptr<StrikedTypePayoff>
payoff =
52 ext::dynamic_pointer_cast<StrikedTypePayoff>(arguments_.payoff);
56 process_->blackVolatility()->blackVariance(
57 arguments_.exercise->lastDate(),
62 Date volRefDate =
process_->blackVolatility()->referenceDate();
64 arguments_.exercise->lastDate());
65 Rate riskFreeRate = -std::log(
process_->riskFreeRate()->discount(
66 arguments_.exercise->lastDate()))/
t;
67 Date rateRefDate =
process_->riskFreeRate()->referenceDate();
78 ext::shared_ptr<GeneralizedBlackScholesProcess> bsProcess(
86 baseArguments->
payoff = arguments_.payoff;
87 baseArguments->exercise = arguments_.exercise;
89 baseArguments->validate();
91 const auto* baseResults =
102 Real r,
v, weight, lastContribution = 1.0;
104 Real theta_correction;
108 || i <
Size(lambda*
t); i++) {
111 v = std::sqrt((
variance + i*jumpSquareVol)/
t);
112 r = riskFreeRate -
process_->jumpIntensity()->value()*k
113 + i*muPlusHalfSquareVol/
t;
114 riskFreeTS.
linkTo(ext::shared_ptr<YieldTermStructure>(
new
116 volTS.
linkTo(ext::shared_ptr<BlackVolTermStructure>(
new
119 baseArguments->validate();
123 results_.value += weight * baseResults->value;
124 results_.delta += weight * baseResults->delta;
125 results_.gamma += weight * baseResults->gamma;
129 theta_correction = baseResults->vega*((i*jumpSquareVol)/
131 baseResults->rho*i*muPlusHalfSquareVol/(
t*
t);
132 results_.theta += weight *(baseResults->theta + theta_correction +
133 lambda*baseResults->value);
135 results_.theta -= (p(
Size(i-1))*lambda* baseResults->value);
138 results_.rho += weight * baseResults->rho;
139 results_.dividendRho += weight * baseResults->dividendRho;
141 lastContribution = std::fabs(baseResults->value /
144 lastContribution = std::max<Real>(lastContribution,
145 std::fabs(baseResults->delta /
148 lastContribution = std::max<Real>(lastContribution,
149 std::fabs(baseResults->gamma /
152 lastContribution = std::max<Real>(lastContribution,
153 std::fabs(baseResults->theta /
156 lastContribution = std::max<Real>(lastContribution,
157 std::fabs(baseResults->vega /
160 lastContribution = std::max<Real>(lastContribution,
161 std::fabs(baseResults->rho /
164 lastContribution = std::max<Real>(lastContribution,
165 std::fabs(baseResults->dividendRho /
169 lastContribution *= weight;
172 i <<
" iterations have been not enough to reach "
175 <<
" addendum was " << lastContribution
176 <<
" while the running sum was " <<
results_.value);
Analytic European engine.
Black constant volatility, no time dependence, no strike dependence.
const Instrument::results * results_
Pricing engine for European vanilla options using analytical formulae.
void calculate() const override
Constant Black volatility, no time-strike dependence.
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Flat interest-rate curve.
Generalized Black-Scholes stochastic process.
Shared handle to an observable.
JumpDiffusionEngine(ext::shared_ptr< Merton76Process >, Real relativeAccuracy_=1e-4, Size maxIterations=100)
void calculate() const override
ext::shared_ptr< Merton76Process > process_
ext::shared_ptr< Payoff > payoff
Poisson distribution function.
Relinkable handle to an observable.
void linkTo(const ext::shared_ptr< T > &h, bool registerAsObserver=true)
#define QL_ENSURE(condition, message)
throw an error if the given post-condition is not verified
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Option exercise classes and payoff function.
LinearInterpolation variance
flat forward rate term structure
detail::ordinal_holder ordinal(Size)
outputs naturals as 1st, 2nd, 3rd...
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
ext::shared_ptr< QuantLib::Payoff > payoff
Jump diffusion (Merton 1976) engine.
ext::shared_ptr< YieldTermStructure > r
ext::shared_ptr< BlackVolTermStructure > v