QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdblackscholesshoutengine.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2021 Klaus Spanderen
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
23#include <ql/exercise.hpp>
24#include <ql/methods/finitedifferences/utilities/escroweddividendadjustment.hpp>
25#include <ql/methods/finitedifferences/meshers/fdmblackscholesmesher.hpp>
26#include <ql/methods/finitedifferences/meshers/fdmmeshercomposite.hpp>
27#include <ql/methods/finitedifferences/solvers/fdmblackscholessolver.hpp>
28#include <ql/methods/finitedifferences/stepconditions/fdmstepconditioncomposite.hpp>
29#include <ql/methods/finitedifferences/utilities/fdmshoutloginnervaluecalculator.hpp>
30#include <ql/pricingengines/vanilla/fdblackscholesshoutengine.hpp>
31#include <ql/processes/blackscholesprocess.hpp>
32
33namespace QuantLib {
34
36 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
37 Size tGrid,
38 Size xGrid,
39 Size dampingSteps,
40 const FdmSchemeDesc& schemeDesc)
41 : process_(std::move(process)), explicitDividends_(false),
42 tGrid_(tGrid), xGrid_(xGrid), dampingSteps_(dampingSteps),
43 schemeDesc_(schemeDesc) {
45 }
46
48 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
49 DividendSchedule dividends,
50 Size tGrid,
51 Size xGrid,
52 Size dampingSteps,
53 const FdmSchemeDesc& schemeDesc)
54 : process_(std::move(process)), dividends_(std::move(dividends)), explicitDividends_(true),
55 tGrid_(tGrid), xGrid_(xGrid), dampingSteps_(dampingSteps),
56 schemeDesc_(schemeDesc) {
58 }
59
61
62 // dividends will eventually be moved out of arguments, but for now we need the switch
63 QL_DEPRECATED_DISABLE_WARNING
65 QL_DEPRECATED_ENABLE_WARNING
66
67 const Date exerciseDate = arguments_.exercise->lastDate();
68 const Time maturity = process_->time(exerciseDate);
69 const Date settlementDate = process_->riskFreeRate()->referenceDate();
70
71 const auto escrowedDividendAdj =
72 ext::make_shared<EscrowedDividendAdjustment>(
73 passedDividends,
74 process_->riskFreeRate(),
75 process_->dividendYield(),
76 [&](Date d){ return process_->time(d); },
77 maturity);
78
79 const Real divAdj = escrowedDividendAdj
80 ->dividendAdjustment(process_->time(settlementDate));
81
82 QL_REQUIRE(process_->x0() + divAdj > 0.0,
83 "spot minus dividends becomes negative");
84
85 const auto payoff =
86 ext::dynamic_pointer_cast<PlainVanillaPayoff>(arguments_.payoff);
87
88 QL_REQUIRE(payoff, "non plain vanilla payoff given");
89
90 const DividendSchedule emptyDividendSchedule;
91
92 const auto mesher = ext::make_shared<FdmMesherComposite>(
93 ext::make_shared<FdmBlackScholesMesher>(
94 xGrid_, process_, maturity, payoff->strike(),
95 Null<Real>(), Null<Real>(), 0.0001, 1.5,
96 std::pair<Real, Real>(payoff->strike(), 0.1),
97 emptyDividendSchedule,
98 ext::shared_ptr<FdmQuantoHelper>(),
99 divAdj));
100
101 const auto innerValuecalculator =
102 ext::make_shared<FdmShoutLogInnerValueCalculator>(
103 process_->blackVolatility(),
104 escrowedDividendAdj, maturity, payoff, mesher, 0);
105
106 DividendSchedule zeroDividendSchedule = DividendSchedule();
107 for (const auto& cf: passedDividends)
108 zeroDividendSchedule.push_back(
109 ext::make_shared<FixedDividend>(0.0, cf->date()));
110
111 const auto conditions =
113 zeroDividendSchedule,
114 arguments_.exercise, mesher,
115 innerValuecalculator,
116 process_->riskFreeRate()->referenceDate(),
117 process_->riskFreeRate()->dayCounter());
118
119 const FdmSolverDesc solverDesc = {
120 mesher, FdmBoundaryConditionSet(),
121 conditions, innerValuecalculator,
122 maturity, tGrid_, dampingSteps_ };
123
124 const auto solver =
125 ext::make_shared<FdmBlackScholesSolver>(
127 payoff->strike(), solverDesc, schemeDesc_);
128
129 const Real spot = process_->x0() + divAdj;
130
131 results_.value = solver->valueAt(spot);
132 results_.delta = solver->deltaAt(spot);
133 results_.gamma = solver->gammaAt(spot);
134 results_.theta = solver->thetaAt(spot);
135 }
136}
Concrete date class.
Definition: date.hpp:125
const ext::shared_ptr< GeneralizedBlackScholesProcess > process_
FdBlackScholesShoutEngine(ext::shared_ptr< GeneralizedBlackScholesProcess >, Size tGrid=100, Size xGrid=100, Size dampingSteps=0, const FdmSchemeDesc &schemeDesc=FdmSchemeDesc::Douglas())
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)
Shared handle to an observable.
Definition: handle.hpp:41
template class providing a null value for a given type.
Definition: null.hpp:76
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
std::vector< ext::shared_ptr< Dividend > > DividendSchedule
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet
STL namespace.