20#include <ql/methods/finitedifferences/meshers/fdmblackscholesmesher.hpp>
21#include <ql/methods/finitedifferences/meshers/fdmblackscholesmultistrikemesher.hpp>
22#include <ql/methods/finitedifferences/meshers/fdmhestonvariancemesher.hpp>
23#include <ql/methods/finitedifferences/meshers/fdmmeshercomposite.hpp>
24#include <ql/methods/finitedifferences/meshers/fdmsimpleprocess1dmesher.hpp>
25#include <ql/methods/finitedifferences/meshers/uniform1dmesher.hpp>
26#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
27#include <ql/methods/finitedifferences/stepconditions/fdmstepconditioncomposite.hpp>
28#include <ql/methods/finitedifferences/utilities/fdminnervaluecalculator.hpp>
29#include <ql/pricingengines/vanilla/analytichestonengine.hpp>
30#include <ql/pricingengines/vanilla/fdhestonhullwhitevanillaengine.hpp>
31#include <ql/pricingengines/vanilla/fdhestonvanillaengine.hpp>
36 QL_DEPRECATED_DISABLE_WARNING
39 const ext::shared_ptr<HestonModel>& hestonModel,
40 ext::shared_ptr<HullWhiteProcess> hwProcess,
41 Real corrEquityShortRate,
52 hwProcess_(
std::move(hwProcess)), explicitDividends_(false),
53 corrEquityShortRate_(corrEquityShortRate), tGrid_(tGrid),
54 xGrid_(xGrid), vGrid_(vGrid), rGrid_(rGrid), dampingSteps_(dampingSteps),
55 schemeDesc_(schemeDesc), controlVariate_(controlVariate) {}
58 const ext::shared_ptr<HestonModel>& hestonModel,
59 ext::shared_ptr<HullWhiteProcess> hwProcess,
61 Real corrEquityShortRate,
72 hwProcess_(
std::move(hwProcess)), dividends_(
std::move(dividends)), explicitDividends_(true),
73 corrEquityShortRate_(corrEquityShortRate), tGrid_(tGrid),
74 xGrid_(xGrid), vGrid_(vGrid), rGrid_(rGrid), dampingSteps_(dampingSteps),
75 schemeDesc_(schemeDesc), controlVariate_(controlVariate) {}
77 QL_DEPRECATED_ENABLE_WARNING
82 QL_DEPRECATED_DISABLE_WARNING
84 QL_DEPRECATED_ENABLE_WARNING
88 if (cachedArgs2result.first.exercise->type() ==
arguments_.exercise->type() &&
89 cachedArgs2result.first.exercise->dates() ==
arguments_.exercise->dates()) {
90 ext::shared_ptr<PlainVanillaPayoff> p1 =
91 ext::dynamic_pointer_cast<PlainVanillaPayoff>(
93 ext::shared_ptr<PlainVanillaPayoff> p2 =
94 ext::dynamic_pointer_cast<PlainVanillaPayoff>(cachedArgs2result.first.payoff);
96 if ((p1 !=
nullptr) && p1->strike() == p2->strike() &&
97 p1->optionType() == p2->optionType()) {
98 QL_REQUIRE(passedDividends.empty(),
99 "multiple strikes engine does not work with discrete dividends");
100 results_ = cachedArgs2result.second;
107 const ext::shared_ptr<HestonProcess> hestonProcess=
model_->process();
108 const Time maturity=hestonProcess->time(
arguments_.exercise->lastDate());
111 const Size tGridMin = 5;
112 const ext::shared_ptr<FdmHestonVarianceMesher> varianceMesher(
114 maturity,std::max(tGridMin,
tGrid_/50)));
117 const ext::shared_ptr<StrikedTypePayoff> payoff =
118 ext::dynamic_pointer_cast<StrikedTypePayoff>(
arguments_.payoff);
119 QL_REQUIRE(payoff,
"wrong payoff type given");
121 ext::shared_ptr<Fdm1dMesher> equityMesher;
123 equityMesher = ext::shared_ptr<Fdm1dMesher>(
127 hestonProcess->s0(), hestonProcess->dividendYield(),
128 hestonProcess->riskFreeRate(),
129 varianceMesher->volaEstimate()),
130 maturity, payoff->strike(),
132 std::pair<Real, Real>(payoff->strike(), 0.1),
136 QL_REQUIRE(passedDividends.empty(),
137 "multiple strikes engine does not work with discrete dividends");
138 equityMesher = ext::shared_ptr<Fdm1dMesher>(
142 hestonProcess->s0(), hestonProcess->dividendYield(),
143 hestonProcess->riskFreeRate(),
144 varianceMesher->volaEstimate()),
146 std::pair<Real, Real>(payoff->strike(), 0.075)));
150 const ext::shared_ptr<OrnsteinUhlenbeckProcess> ouProcess(
152 const ext::shared_ptr<Fdm1dMesher> shortRateMesher(
155 const ext::shared_ptr<FdmMesher> mesher(
160 const ext::shared_ptr<FdmInnerValueCalculator> calculator(
164 const ext::shared_ptr<FdmStepConditionComposite> conditions =
168 hestonProcess->riskFreeRate()->referenceDate(),
169 hestonProcess->riskFreeRate()->dayCounter());
175 const FdmSolverDesc solverDesc = { mesher, boundaries, conditions,
176 calculator, maturity,
179 const ext::shared_ptr<FdmHestonHullWhiteSolver> solver(
185 const Real spot = hestonProcess->s0()->value();
186 const Real v0 = hestonProcess->v0();
187 results_.value = solver->valueAt(spot, v0, 0);
188 results_.delta = solver->deltaAt(spot, v0, 0, spot*0.01);
189 results_.gamma = solver->gammaAt(spot, v0, 0, spot*0.01);
190 results_.theta = solver->thetaAt(spot, v0, 0);
196 ext::make_shared<PlainVanillaPayoff>(
200 QL_DEPRECATED_DISABLE_WARNING
203 QL_DEPRECATED_ENABLE_WARNING
204 results.value = solver->valueAt(spot*d, v0, 0)/d;
205 results.delta = solver->deltaAt(spot*d, v0, 0, spot*d*0.01);
206 results.gamma = solver->gammaAt(spot*d, v0, 0, spot*d*0.01)*d;
207 results.theta = solver->thetaAt(spot*d, v0, 0)/d;
211 ext::shared_ptr<PricingEngine> analyticEngine(
213 ext::shared_ptr<Exercise> exercise(
218 Real analyticNPV = option.
NPV();
220 ext::shared_ptr<FdHestonVanillaEngine> fdEngine(
224 fdEngine->enableMultipleStrikesCaching(
strikes_);
228 results_.value += analyticNPV - fdNPV;
231 ext::shared_ptr<StrikedTypePayoff>(
235 analyticNPV = controlVariateOption.
NPV();
238 fdNPV = controlVariateOption.
NPV();
246 QL_DEPRECATED_DISABLE_WARNING
250 QL_DEPRECATED_ENABLE_WARNING
254 const std::vector<Real>& strikes) {
analytic Heston-model engine based on Fourier transform
Single-asset vanilla option (no barriers) with discrete dividends.
const Real corrEquityShortRate_
void calculate() const override
const bool controlVariate_
std::vector< Real > strikes_
FdHestonHullWhiteVanillaEngine(const ext::shared_ptr< HestonModel > &model, ext::shared_ptr< HullWhiteProcess > hwProcess, Real corrEquityShortRate, Size tGrid=50, Size xGrid=100, Size vGrid=40, Size rGrid=20, Size dampingSteps=0, bool controlVariate=true, const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Hundsdorfer())
const ext::shared_ptr< HullWhiteProcess > hwProcess_
DividendSchedule dividends_
QL_DEPRECATED_DISABLE_WARNING std::vector< std::pair< DividendVanillaOption::arguments, DividendVanillaOption::results > > cachedArgs2results_
void enableMultipleStrikesCaching(const std::vector< Real > &strikes)
const FdmSchemeDesc schemeDesc_
Finite-differences Heston vanilla option engine.
static ext::shared_ptr< GeneralizedBlackScholesProcess > processHelper(const Handle< Quote > &s0, const Handle< YieldTermStructure > &rTS, const Handle< YieldTermStructure > &qTS, Volatility vol)
static ext::shared_ptr< FdmStepConditionComposite > vanillaComposite(const DividendSchedule &schedule, const ext::shared_ptr< Exercise > &exercise, const ext::shared_ptr< FdmMesher > &mesher, const ext::shared_ptr< FdmInnerValueCalculator > &calculator, const Date &refDate, const DayCounter &dayCounter)
Base class for some pricing engine on a particular model.
Handle< HestonModel > model_
Shared handle to an observable.
Heston model for the stochastic volatility of an asset.
Real NPV() const
returns the net present value of the instrument.
void setPricingEngine(const ext::shared_ptr< PricingEngine > &)
set the pricing engine to be used.
template class providing a null value for a given type.
Ornstein-Uhlenbeck process class.
Vanilla option (no discrete dividends, no barriers) on a single asset.
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
std::vector< ext::shared_ptr< Dividend > > DividendSchedule
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet