22#include <ql/exercise.hpp>
23#include <ql/methods/finitedifferences/meshers/fdmblackscholesmesher.hpp>
24#include <ql/methods/finitedifferences/utilities/escroweddividendadjustment.hpp>
25#include <ql/methods/finitedifferences/meshers/fdmmeshercomposite.hpp>
26#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
27#include <ql/methods/finitedifferences/solvers/fdmblackscholessolver.hpp>
28#include <ql/methods/finitedifferences/stepconditions/fdmstepconditioncomposite.hpp>
29#include <ql/methods/finitedifferences/utilities/fdminnervaluecalculator.hpp>
30#include <ql/methods/finitedifferences/utilities/fdmescrowedloginnervaluecalculator.hpp>
31#include <ql/methods/finitedifferences/utilities/fdmquantohelper.hpp>
32#include <ql/pricingengines/vanilla/fdblackscholesvanillaengine.hpp>
33#include <ql/processes/blackscholesprocess.hpp>
38 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
44 Real illegalLocalVolOverwrite,
46 : process_(
std::move(process)), explicitDividends_(false), tGrid_(tGrid), xGrid_(xGrid),
47 dampingSteps_(dampingSteps), schemeDesc_(schemeDesc), localVol_(localVol),
48 illegalLocalVolOverwrite_(illegalLocalVolOverwrite), cashDividendModel_(cashDividendModel) {
53 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
60 Real illegalLocalVolOverwrite,
62 : process_(
std::move(process)), dividends_(
std::move(dividends)), explicitDividends_(true),
63 tGrid_(tGrid), xGrid_(xGrid), dampingSteps_(dampingSteps), schemeDesc_(schemeDesc),
64 localVol_(localVol), illegalLocalVolOverwrite_(illegalLocalVolOverwrite),
65 cashDividendModel_(cashDividendModel) {
70 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
71 ext::shared_ptr<FdmQuantoHelper> quantoHelper,
77 Real illegalLocalVolOverwrite,
79 : process_(
std::move(process)), explicitDividends_(false),
80 tGrid_(tGrid), xGrid_(xGrid), dampingSteps_(dampingSteps),
81 schemeDesc_(schemeDesc), localVol_(localVol),
82 illegalLocalVolOverwrite_(illegalLocalVolOverwrite), quantoHelper_(
std::move(quantoHelper)),
83 cashDividendModel_(cashDividendModel) {
89 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
91 ext::shared_ptr<FdmQuantoHelper> quantoHelper,
97 Real illegalLocalVolOverwrite,
99 : process_(
std::move(process)), dividends_(
std::move(dividends)), explicitDividends_(true),
100 tGrid_(tGrid), xGrid_(xGrid), dampingSteps_(dampingSteps),
101 schemeDesc_(schemeDesc), localVol_(localVol),
102 illegalLocalVolOverwrite_(illegalLocalVolOverwrite), quantoHelper_(
std::move(quantoHelper)),
103 cashDividendModel_(cashDividendModel) {
112 QL_DEPRECATED_DISABLE_WARNING
114 QL_DEPRECATED_ENABLE_WARNING
119 const Date settlementDate =
process_->riskFreeRate()->referenceDate();
121 Real spotAdjustment = 0.0;
124 ext::shared_ptr<EscrowedDividendAdjustment> escrowedDivAdj;
128 dividendSchedule = passedDividends;
133 for (
const auto& cf: passedDividends)
134 dividendSchedule.push_back(
135 ext::make_shared<FixedDividend>(0.0, cf->date()));
138 "Escrowed dividend model is not supported for Quanto-Options");
140 escrowedDivAdj = ext::make_shared<EscrowedDividendAdjustment>(
144 [&](
Date d){ return process_->time(d); },
149 escrowedDivAdj->dividendAdjustment(
process_->time(settlementDate));
151 QL_REQUIRE(
process_->x0() + spotAdjustment > 0.0,
152 "spot minus dividends becomes negative");
156 QL_FAIL(
"unknwon cash dividend model");
160 const ext::shared_ptr<StrikedTypePayoff> payoff =
161 ext::dynamic_pointer_cast<StrikedTypePayoff>(
arguments_.payoff);
163 const ext::shared_ptr<Fdm1dMesher> equityMesher =
164 ext::make_shared<FdmBlackScholesMesher>(
167 std::pair<Real, Real>(payoff->strike(), 0.1),
171 const ext::shared_ptr<FdmMesher> mesher =
172 ext::make_shared<FdmMesherComposite>(equityMesher);
175 ext::shared_ptr<FdmInnerValueCalculator> calculator;
178 calculator = ext::make_shared<FdmLogInnerValue>(
182 calculator = ext::make_shared<FdmEscrowedLogInnerValueCalculator>(
183 escrowedDivAdj, payoff, mesher, 0);
186 QL_FAIL(
"unknwon cash dividend model");
190 const ext::shared_ptr<FdmStepConditionComposite> conditions =
192 dividendSchedule,
arguments_.exercise, mesher, calculator,
193 process_->riskFreeRate()->referenceDate(),
194 process_->riskFreeRate()->dayCounter());
200 FdmSolverDesc solverDesc = { mesher, boundaries, conditions, calculator,
203 const ext::shared_ptr<FdmBlackScholesSolver> solver(
204 ext::make_shared<FdmBlackScholesSolver>(
213 results_.delta = solver->deltaAt(spot);
214 results_.gamma = solver->gammaAt(spot);
215 results_.theta = solver->thetaAt(spot);
219 ext::shared_ptr<GeneralizedBlackScholesProcess> process)
220 : process_(
std::move(process)),
222 illegalLocalVolOverwrite_(-
Null<
Real>()) {}
226 const ext::shared_ptr<FdmQuantoHelper>& quantoHelper) {
252 schemeDesc_ = ext::make_shared<FdmSchemeDesc>(schemeDesc);
264 Real illegalLocalVolOverwrite) {
271 const std::vector<Date>& dividendDates,
272 const std::vector<Real>& dividendAmounts) {
285 MakeFdBlackScholesVanillaEngine::operator
286 ext::shared_ptr<PricingEngine>()
const {
287 if (explicitDividends_) {
288 return ext::make_shared<FdBlackScholesVanillaEngine>(
292 tGrid_, xGrid_, dampingSteps_,
295 illegalLocalVolOverwrite_,
298 return ext::make_shared<FdBlackScholesVanillaEngine>(
301 tGrid_, xGrid_, dampingSteps_,
304 illegalLocalVolOverwrite_,
DividendSchedule cashFlow
Real illegalLocalVolOverwrite_
FdmSchemeDesc schemeDesc_
void calculate() const override
DividendSchedule dividends_
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
ext::shared_ptr< FdmQuantoHelper > quantoHelper_
FdBlackScholesVanillaEngine(ext::shared_ptr< GeneralizedBlackScholesProcess >, Size tGrid=100, Size xGrid=100, Size dampingSteps=0, const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Douglas(), bool localVol=false, Real illegalLocalVolOverwrite=-Null< Real >(), CashDividendModel cashDividendModel=Spot)
CashDividendModel cashDividendModel_
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)
DividendVanillaOption::results results_
DividendVanillaOption::arguments arguments_
Shared handle to an observable.
MakeFdBlackScholesVanillaEngine & withIllegalLocalVolOverwrite(Real illegalLocalVolOverwrite)
MakeFdBlackScholesVanillaEngine & withLocalVol(bool localVol)
MakeFdBlackScholesVanillaEngine & withCashDividendModel(FdBlackScholesVanillaEngine::CashDividendModel cashDividendModel)
Real illegalLocalVolOverwrite_
MakeFdBlackScholesVanillaEngine & withTGrid(Size tGrid)
MakeFdBlackScholesVanillaEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process)
FdBlackScholesVanillaEngine::CashDividendModel cashDividendModel_
MakeFdBlackScholesVanillaEngine & withDampingSteps(Size dampingSteps)
MakeFdBlackScholesVanillaEngine & withQuantoHelper(const ext::shared_ptr< FdmQuantoHelper > &quantoHelper)
MakeFdBlackScholesVanillaEngine & withXGrid(Size xGrid)
MakeFdBlackScholesVanillaEngine & withCashDividends(const std::vector< Date > ÷ndDates, const std::vector< Real > ÷ndAmounts)
DividendSchedule dividends_
ext::shared_ptr< FdmQuantoHelper > quantoHelper_
MakeFdBlackScholesVanillaEngine & withFdmSchemeDesc(const FdmSchemeDesc &schemeDesc)
ext::shared_ptr< FdmSchemeDesc > schemeDesc_
template class providing a null value for a given type.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Real Time
continuous quantity with 1-year units
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