23#include <ql/methods/finitedifferences/meshers/fdmblackscholesmesher.hpp>
24#include <ql/methods/finitedifferences/meshers/fdmblackscholesmultistrikemesher.hpp>
25#include <ql/methods/finitedifferences/meshers/fdmhestonvariancemesher.hpp>
26#include <ql/methods/finitedifferences/meshers/fdmmeshercomposite.hpp>
27#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
28#include <ql/methods/finitedifferences/solvers/fdmhestonsolver.hpp>
29#include <ql/methods/finitedifferences/stepconditions/fdmstepconditioncomposite.hpp>
30#include <ql/methods/finitedifferences/utilities/fdminnervaluecalculator.hpp>
31#include <ql/pricingengines/vanilla/fdhestonvanillaengine.hpp>
32#include <ql/processes/batesprocess.hpp>
37 QL_DEPRECATED_DISABLE_WARNING
45 ext::shared_ptr<LocalVolTermStructure> leverageFct,
46 const Real mixingFactor)
50 explicitDividends_(false),
51 tGrid_(tGrid), xGrid_(xGrid), vGrid_(vGrid), dampingSteps_(dampingSteps),
52 schemeDesc_(schemeDesc), leverageFct_(
std::move(leverageFct)),
53 quantoHelper_(ext::shared_ptr<
FdmQuantoHelper>()), mixingFactor_(mixingFactor) {}
62 ext::shared_ptr<LocalVolTermStructure> leverageFct,
63 const Real mixingFactor)
67 dividends_(
std::move(dividends)), explicitDividends_(true),
68 tGrid_(tGrid), xGrid_(xGrid), vGrid_(vGrid), dampingSteps_(dampingSteps),
69 schemeDesc_(schemeDesc), leverageFct_(
std::move(leverageFct)),
70 quantoHelper_(ext::shared_ptr<
FdmQuantoHelper>()), mixingFactor_(mixingFactor) {}
73 ext::shared_ptr<FdmQuantoHelper> quantoHelper,
79 ext::shared_ptr<LocalVolTermStructure> leverageFct,
80 const Real mixingFactor)
84 explicitDividends_(false),
85 tGrid_(tGrid), xGrid_(xGrid), vGrid_(vGrid), dampingSteps_(dampingSteps),
86 schemeDesc_(schemeDesc), leverageFct_(
std::move(leverageFct)),
87 quantoHelper_(
std::move(quantoHelper)), mixingFactor_(mixingFactor) {}
91 ext::shared_ptr<FdmQuantoHelper> quantoHelper,
97 ext::shared_ptr<LocalVolTermStructure> leverageFct,
98 const Real mixingFactor)
102 dividends_(
std::move(dividends)), explicitDividends_(true),
103 tGrid_(tGrid), xGrid_(xGrid), vGrid_(vGrid), dampingSteps_(dampingSteps),
104 schemeDesc_(schemeDesc), leverageFct_(
std::move(leverageFct)),
105 quantoHelper_(
std::move(quantoHelper)), mixingFactor_(mixingFactor) {}
107 QL_DEPRECATED_ENABLE_WARNING
112 QL_DEPRECATED_DISABLE_WARNING
114 QL_DEPRECATED_ENABLE_WARNING
117 const ext::shared_ptr<HestonProcess> process =
model_->process();
118 const Time maturity = process->time(
arguments_.exercise->lastDate());
121 const Size tGridMin = 5;
122 const Size tGridAvgSteps = std::max(tGridMin,
tGrid_/50);
123 const ext::shared_ptr<FdmHestonLocalVolatilityVarianceMesher> vMesher
124 = ext::make_shared<FdmHestonLocalVolatilityVarianceMesher>(
127 const Volatility avgVolaEstimate = vMesher->volaEstimate();
130 const ext::shared_ptr<StrikedTypePayoff> payoff =
131 ext::dynamic_pointer_cast<StrikedTypePayoff>(
arguments_.payoff);
133 ext::shared_ptr<Fdm1dMesher> equityMesher;
135 equityMesher = ext::shared_ptr<Fdm1dMesher>(
139 process->s0(), process->dividendYield(),
140 process->riskFreeRate(), avgVolaEstimate),
141 maturity, payoff->strike(),
143 std::pair<Real, Real>(payoff->strike(), 0.1),
148 QL_REQUIRE(passedDividends.empty(),
149 "multiple strikes engine does not work with discrete dividends");
150 equityMesher = ext::shared_ptr<Fdm1dMesher>(
154 process->s0(), process->dividendYield(),
155 process->riskFreeRate(), avgVolaEstimate),
157 std::pair<Real, Real>(payoff->strike(), 0.075)));
160 const ext::shared_ptr<FdmMesher> mesher(
164 const ext::shared_ptr<FdmInnerValueCalculator> calculator(
168 const ext::shared_ptr<FdmStepConditionComposite> conditions =
172 process->riskFreeRate()->referenceDate(),
173 process->riskFreeRate()->dayCounter());
180 calculator, maturity,
189 QL_DEPRECATED_DISABLE_WARNING
191 QL_DEPRECATED_ENABLE_WARNING
195 if (cachedArgs2result.first.exercise->type() ==
arguments_.exercise->type() &&
196 cachedArgs2result.first.exercise->dates() ==
arguments_.exercise->dates()) {
197 ext::shared_ptr<PlainVanillaPayoff> p1 =
198 ext::dynamic_pointer_cast<PlainVanillaPayoff>(
200 ext::shared_ptr<PlainVanillaPayoff> p2 =
201 ext::dynamic_pointer_cast<PlainVanillaPayoff>(cachedArgs2result.first.payoff);
203 if ((p1 !=
nullptr) && p1->strike() == p2->strike() &&
204 p1->optionType() == p2->optionType()) {
205 QL_REQUIRE(passedDividends.empty(),
206 "multiple strikes engine does not work with discrete dividends");
207 results_ = cachedArgs2result.second;
213 const ext::shared_ptr<HestonProcess> process =
model_->process();
221 const Real v0 = process->v0();
222 const Real spot = process->s0()->value();
224 results_.value = solver->valueAt(spot, v0);
225 results_.delta = solver->deltaAt(spot, v0);
226 results_.gamma = solver->gammaAt(spot, v0);
227 results_.theta = solver->thetaAt(spot, v0);
230 const ext::shared_ptr<StrikedTypePayoff> payoff =
231 ext::dynamic_pointer_cast<StrikedTypePayoff>(
arguments_.payoff);
235 ext::make_shared<PlainVanillaPayoff>(
239 QL_DEPRECATED_DISABLE_WARNING
241 QL_DEPRECATED_ENABLE_WARNING
242 results.value = solver->valueAt(spot*d, v0)/d;
243 results.delta = solver->deltaAt(spot*d, v0);
244 results.gamma = solver->gammaAt(spot*d, v0)*d;
245 results.theta = solver->thetaAt(spot*d, v0)/d;
251 QL_DEPRECATED_DISABLE_WARNING
255 QL_DEPRECATED_ENABLE_WARNING
259 const std::vector<Real>& strikes) {
266 : hestonModel_(
std::move(hestonModel)),
270 const ext::shared_ptr<FdmQuantoHelper>& quantoHelper) {
302 schemeDesc_ = ext::make_shared<FdmSchemeDesc>(schemeDesc);
308 ext::shared_ptr<LocalVolTermStructure>& leverageFct) {
315 const std::vector<Date>& dividendDates,
316 const std::vector<Real>& dividendAmounts) {
322 MakeFdHestonVanillaEngine::operator
323 ext::shared_ptr<PricingEngine>()
const {
324 if (explicitDividends_) {
325 return ext::make_shared<FdHestonVanillaEngine>(
329 tGrid_, xGrid_, vGrid_, dampingSteps_,
333 return ext::make_shared<FdHestonVanillaEngine>(
336 tGrid_, xGrid_, vGrid_, dampingSteps_,
Single-asset vanilla option (no barriers) with discrete dividends.
FdmSolverDesc getSolverDesc(Real equityScaleFactor) const
std::vector< Real > strikes_
const ext::shared_ptr< FdmQuantoHelper > quantoHelper_
void calculate() const override
const ext::shared_ptr< LocalVolTermStructure > leverageFct_
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_
FdHestonVanillaEngine(const ext::shared_ptr< HestonModel > &model, Size tGrid=100, Size xGrid=100, Size vGrid=50, Size dampingSteps=0, const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Hundsdorfer(), ext::shared_ptr< LocalVolTermStructure > leverageFct={}, Real mixingFactor=1.0)
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.
MakeFdHestonVanillaEngine & withDampingSteps(Size dampingSteps)
MakeFdHestonVanillaEngine & withQuantoHelper(const ext::shared_ptr< FdmQuantoHelper > &quantoHelper)
MakeFdHestonVanillaEngine & withTGrid(Size tGrid)
MakeFdHestonVanillaEngine(ext::shared_ptr< HestonModel > hestonModel)
MakeFdHestonVanillaEngine & withCashDividends(const std::vector< Date > ÷ndDates, const std::vector< Real > ÷ndAmounts)
DividendSchedule dividends_
ext::shared_ptr< FdmQuantoHelper > quantoHelper_
MakeFdHestonVanillaEngine & withVGrid(Size vGrid)
ext::shared_ptr< FdmSchemeDesc > schemeDesc_
MakeFdHestonVanillaEngine & withFdmSchemeDesc(const FdmSchemeDesc &schemeDesc)
MakeFdHestonVanillaEngine & withLeverageFunction(ext::shared_ptr< LocalVolTermStructure > &leverageFct)
MakeFdHestonVanillaEngine & withXGrid(Size xGrid)
ext::shared_ptr< LocalVolTermStructure > leverageFct_
template class providing a null value for a given type.
Real Time
continuous quantity with 1-year units
Real Volatility
volatility
std::size_t Size
size of a container
std::vector< ext::shared_ptr< Dividend > > DividendSchedule
std::vector< ext::shared_ptr< Dividend > > DividendVector(const std::vector< Date > ÷ndDates, const std::vector< Real > ÷nds)
helper function building a sequence of fixed dividends
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet