22#include <ql/exercise.hpp>
23#include <ql/instruments/vanillaoption.hpp>
24#include <ql/math/distributions/normaldistribution.hpp>
25#include <ql/methods/finitedifferences/meshers/fdmblackscholesmesher.hpp>
26#include <ql/methods/finitedifferences/meshers/fdmmeshercomposite.hpp>
27#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
28#include <ql/methods/finitedifferences/solvers/fdmblackscholessolver.hpp>
29#include <ql/methods/finitedifferences/stepconditions/fdmstepconditioncomposite.hpp>
30#include <ql/methods/finitedifferences/utilities/fdmdirichletboundary.hpp>
31#include <ql/methods/finitedifferences/utilities/fdmdividendhandler.hpp>
32#include <ql/methods/finitedifferences/utilities/fdminnervaluecalculator.hpp>
33#include <ql/pricingengines/barrier/fdblackscholesbarrierengine.hpp>
34#include <ql/pricingengines/barrier/fdblackscholesrebateengine.hpp>
35#include <ql/pricingengines/vanilla/fdblackscholesvanillaengine.hpp>
41 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
47 Real illegalLocalVolOverwrite)
48 : process_(
std::move(process)), explicitDividends_(false),
49 tGrid_(tGrid), xGrid_(xGrid), dampingSteps_(dampingSteps),
50 schemeDesc_(schemeDesc), localVol_(localVol),
51 illegalLocalVolOverwrite_(illegalLocalVolOverwrite) {
57 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
64 Real illegalLocalVolOverwrite)
65 : process_(
std::move(process)), dividends_(
std::move(dividends)), explicitDividends_(true),
66 tGrid_(tGrid), xGrid_(xGrid), dampingSteps_(dampingSteps),
67 schemeDesc_(schemeDesc), localVol_(localVol),
68 illegalLocalVolOverwrite_(illegalLocalVolOverwrite) {
76 QL_DEPRECATED_DISABLE_WARNING
78 QL_DEPRECATED_ENABLE_WARNING
81 const ext::shared_ptr<StrikedTypePayoff> payoff =
82 ext::dynamic_pointer_cast<StrikedTypePayoff>(
arguments_.payoff);
84 QL_REQUIRE(payoff,
"non-striked type payoff given");
85 QL_REQUIRE(payoff->strike() > 0.0,
"strike must be positive");
88 "only european style option are supported");
91 QL_REQUIRE(spot > 0.0,
"negative or null underlying given");
92 QL_REQUIRE(!
triggered(spot),
"barrier touched");
107 const ext::shared_ptr<Fdm1dMesher> equityMesher(
110 xMin, xMax, 0.0001, 1.5,
114 const ext::shared_ptr<FdmMesher> mesher (
115 ext::make_shared<FdmMesherComposite>(equityMesher));
118 ext::shared_ptr<FdmInnerValueCalculator> calculator(
119 ext::make_shared<FdmLogInnerValue>(payoff, mesher, 0));
122 std::list<ext::shared_ptr<StepCondition<Array> > > stepConditions;
123 std::list<std::vector<Time> > stoppingTimes;
126 ext::shared_ptr<FdmDividendHandler> dividendCondition(
127 ext::make_shared<FdmDividendHandler>(dividendSchedule, mesher,
128 process_->riskFreeRate()->referenceDate(),
129 process_->riskFreeRate()->dayCounter(), 0));
131 if (!dividendSchedule.empty()) {
132 stepConditions.push_back(dividendCondition);
133 std::vector<Time> dividendTimes = dividendCondition->dividendTimes();
135 for (
auto& t: dividendTimes)
136 t = std::min(maturity, t);
137 stoppingTimes.push_back(dividendTimes);
140 ext::shared_ptr<FdmStepConditionComposite> conditions(
141 ext::make_shared<FdmStepConditionComposite>(stoppingTimes, stepConditions));
147 boundaries.push_back(
155 boundaries.push_back(
161 FdmSolverDesc solverDesc = { mesher, boundaries, conditions, calculator,
164 ext::shared_ptr<FdmBlackScholesSolver> solver(
165 ext::make_shared<FdmBlackScholesSolver>(
171 results_.delta = solver->deltaAt(spot);
172 results_.gamma = solver->gammaAt(spot);
173 results_.theta = solver->thetaAt(spot);
179 ext::shared_ptr<StrikedTypePayoff> payoff =
180 ext::dynamic_pointer_cast<StrikedTypePayoff>(
187 ext::make_shared<FdBlackScholesVanillaEngine>(
198 const Size min_grid_size = 50;
199 const Size rebateDampingSteps
Barrier::Type barrierType
Barrier option on a single asset.
DividendSchedule cashFlow
bool triggered(Real underlying) const
Real illegalLocalVolOverwrite_
FdmSchemeDesc schemeDesc_
void calculate() const override
DividendSchedule dividends_
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
FdBlackScholesBarrierEngine(ext::shared_ptr< GeneralizedBlackScholesProcess > process, Size tGrid=100, Size xGrid=100, Size dampingSteps=0, const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Douglas(), bool localVol=false, Real illegalLocalVolOverwrite=-Null< Real >())
DividendBarrierOption::results results_
DividendBarrierOption::arguments arguments_
Shared handle to an observable.
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.
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
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