22#include <ql/methods/finitedifferences/meshers/fdmblackscholesmesher.hpp>
23#include <ql/methods/finitedifferences/meshers/fdmhestonvariancemesher.hpp>
24#include <ql/methods/finitedifferences/meshers/fdmmeshercomposite.hpp>
25#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
26#include <ql/methods/finitedifferences/stepconditions/fdmstepconditioncomposite.hpp>
27#include <ql/methods/finitedifferences/utilities/fdmdirichletboundary.hpp>
28#include <ql/methods/finitedifferences/utilities/fdmdividendhandler.hpp>
29#include <ql/methods/finitedifferences/utilities/fdminnervaluecalculator.hpp>
30#include <ql/instruments/vanillaoption.hpp>
31#include <ql/pricingengines/barrier/fdhestonbarrierengine.hpp>
32#include <ql/pricingengines/barrier/fdhestonrebateengine.hpp>
33#include <ql/pricingengines/vanilla/fdhestonvanillaengine.hpp>
38 QL_DEPRECATED_DISABLE_WARNING
46 ext::shared_ptr<LocalVolTermStructure> leverageFct,
47 const Real mixingFactor)
51 explicitDividends_(false), tGrid_(tGrid), xGrid_(xGrid), vGrid_(vGrid), dampingSteps_(dampingSteps),
52 schemeDesc_(schemeDesc), leverageFct_(
std::move(leverageFct)), mixingFactor_(mixingFactor) {}
61 ext::shared_ptr<LocalVolTermStructure> leverageFct,
62 const Real mixingFactor)
66 dividends_(
std::move(dividends)), explicitDividends_(true),
67 tGrid_(tGrid), xGrid_(xGrid), vGrid_(vGrid), dampingSteps_(dampingSteps),
68 schemeDesc_(schemeDesc), leverageFct_(
std::move(leverageFct)), mixingFactor_(mixingFactor) {}
70 QL_DEPRECATED_ENABLE_WARNING
75 QL_DEPRECATED_DISABLE_WARNING
77 QL_DEPRECATED_ENABLE_WARNING
80 const ext::shared_ptr<HestonProcess>& process =
model_->process();
81 const Time maturity = process->time(
arguments_.exercise->lastDate());
84 const Size tGridMin = 5;
85 const Size tGridAvgSteps = std::max(tGridMin,
tGrid_/50);
87 const ext::shared_ptr<FdmHestonLocalVolatilityVarianceMesher> vMesher
88 = ext::make_shared<FdmHestonLocalVolatilityVarianceMesher>(
92 const ext::shared_ptr<StrikedTypePayoff> payoff =
93 ext::dynamic_pointer_cast<StrikedTypePayoff>(
arguments_.payoff);
106 const ext::shared_ptr<Fdm1dMesher> equityMesher(
110 process->s0(), process->dividendYield(),
111 process->riskFreeRate(), vMesher->volaEstimate()),
112 maturity, payoff->strike(),
113 xMin, xMax, 0.0001, 1.5,
117 const ext::shared_ptr<FdmMesher> mesher (
118 ext::make_shared<FdmMesherComposite>(equityMesher, vMesher));
121 ext::shared_ptr<FdmInnerValueCalculator> calculator(
122 ext::make_shared<FdmLogInnerValue>(payoff, mesher, 0));
125 std::list<ext::shared_ptr<StepCondition<Array> > > stepConditions;
126 std::list<std::vector<Time> > stoppingTimes;
129 ext::shared_ptr<FdmDividendHandler> dividendCondition(
130 ext::make_shared<FdmDividendHandler>(dividendSchedule, mesher,
131 process->riskFreeRate()->referenceDate(),
132 process->riskFreeRate()->dayCounter(), 0));
134 if (!dividendSchedule.empty()) {
135 stepConditions.push_back(dividendCondition);
136 std::vector<Time> dividendTimes = dividendCondition->dividendTimes();
138 for (
auto& t: dividendTimes)
139 t = std::min(maturity, t);
140 stoppingTimes.push_back(dividendTimes);
144 "only european style option are supported");
146 ext::shared_ptr<FdmStepConditionComposite> conditions(
147 ext::make_shared<FdmStepConditionComposite>(stoppingTimes, stepConditions));
153 boundaries.push_back(
154 ext::make_shared<FdmDirichletBoundary>(mesher,
arguments_.rebate, 0,
160 boundaries.push_back(
161 ext::make_shared<FdmDirichletBoundary>(mesher,
arguments_.rebate, 0,
167 calculator, maturity,
170 ext::shared_ptr<FdmHestonSolver> solver(ext::make_shared<FdmHestonSolver>(
174 const Real spot = process->s0()->value();
175 results_.value = solver->valueAt(spot, process->v0());
176 results_.delta = solver->deltaAt(spot, process->v0());
177 results_.gamma = solver->gammaAt(spot, process->v0());
178 results_.theta = solver->thetaAt(spot, process->v0());
184 ext::shared_ptr<StrikedTypePayoff> payoff =
185 ext::dynamic_pointer_cast<StrikedTypePayoff>(
190 ext::make_shared<FdHestonVanillaEngine>(*
model_, dividendSchedule,
199 const Size xGridMin = 20;
200 const Size vGridMin = 10;
201 const Size rebateDampingSteps
204 ext::make_shared<FdHestonRebateEngine>(*
model_, dividendSchedule,
206 std::max(xGridMin,
xGrid_/4),
207 std::max(vGridMin,
vGrid_/4),
Barrier option on a single asset.
Single-asset barrier option with discrete dividends.
void calculate() const override
FdmSchemeDesc schemeDesc_
FdHestonBarrierEngine(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)
DividendSchedule dividends_
ext::shared_ptr< LocalVolTermStructure > leverageFct_
static ext::shared_ptr< GeneralizedBlackScholesProcess > processHelper(const Handle< Quote > &s0, const Handle< YieldTermStructure > &rTS, const Handle< YieldTermStructure > &qTS, Volatility vol)
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.
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