QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdblackscholesshoutengine.cpp
Go to the documentation of this file.
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
20/*! \file fdblackscholesshoutengine.cpp
21*/
22
23#include <ql/exercise.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)),
42 tGrid_(tGrid), xGrid_(xGrid), dampingSteps_(dampingSteps),
43 schemeDesc_(schemeDesc) {
44 registerWith(process_);
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)),
55 tGrid_(tGrid), xGrid_(xGrid), dampingSteps_(dampingSteps),
56 schemeDesc_(schemeDesc) {
57 registerWith(process_);
58 }
59
61
62 const Date exerciseDate = arguments_.exercise->lastDate();
63 const Time maturity = process_->time(exerciseDate);
64 const Date settlementDate = process_->riskFreeRate()->referenceDate();
65
66 const auto escrowedDividendAdj =
67 ext::make_shared<EscrowedDividendAdjustment>(
69 process_->riskFreeRate(),
70 process_->dividendYield(),
71 [&](Date d){ return process_->time(d); },
72 maturity);
73
74 const Real divAdj = escrowedDividendAdj
75 ->dividendAdjustment(process_->time(settlementDate));
76
77 QL_REQUIRE(process_->x0() + divAdj > 0.0,
78 "spot minus dividends becomes negative");
79
80 const auto payoff =
81 ext::dynamic_pointer_cast<PlainVanillaPayoff>(arguments_.payoff);
82
83 QL_REQUIRE(payoff, "non plain vanilla payoff given");
84
85 const DividendSchedule emptyDividendSchedule;
86
87 const auto mesher = ext::make_shared<FdmMesherComposite>(
88 ext::make_shared<FdmBlackScholesMesher>(
89 xGrid_, process_, maturity, payoff->strike(),
90 Null<Real>(), Null<Real>(), 0.0001, 1.5,
91 std::pair<Real, Real>(payoff->strike(), 0.1),
92 emptyDividendSchedule,
93 ext::shared_ptr<FdmQuantoHelper>(),
94 divAdj));
95
96 const auto innerValuecalculator =
97 ext::make_shared<FdmShoutLogInnerValueCalculator>(
98 process_->blackVolatility(),
99 escrowedDividendAdj, maturity, payoff, mesher, 0);
100
101 DividendSchedule zeroDividendSchedule = DividendSchedule();
102 for (const auto& cf: dividends_)
103 zeroDividendSchedule.push_back(
104 ext::make_shared<FixedDividend>(0.0, cf->date()));
105
106 const auto conditions =
108 zeroDividendSchedule,
109 arguments_.exercise, mesher,
110 innerValuecalculator,
111 process_->riskFreeRate()->referenceDate(),
112 process_->riskFreeRate()->dayCounter());
113
114 const FdmSolverDesc solverDesc = {
115 mesher, FdmBoundaryConditionSet(),
116 conditions, innerValuecalculator,
117 maturity, tGrid_, dampingSteps_ };
118
119 const auto solver =
120 ext::make_shared<FdmBlackScholesSolver>(
122 payoff->strike(), solverDesc, schemeDesc_);
123
124 const Real spot = process_->x0() + divAdj;
125
126 results_.value = solver->valueAt(spot);
127 results_.delta = solver->deltaAt(spot);
128 results_.gamma = solver->gammaAt(spot);
129 results_.theta = solver->thetaAt(spot);
130 }
131}
Black-Scholes processes.
const Instrument::results * results_
Definition: cdsoption.cpp:63
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
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Date d
Option exercise classes and payoff function.
Finite-Differences Black Scholes shout option engine.
1-d mesher for the Black-Scholes process (in ln(S))
FdmMesher which is a composite of Fdm1dMesher.
inner value for a shout option
composite of fdm step conditions
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
ext::shared_ptr< QuantLib::Payoff > payoff
Definition: any.hpp:35
std::vector< ext::shared_ptr< Dividend > > DividendSchedule
OperatorTraits< FdmLinearOp >::bc_set FdmBoundaryConditionSet
STL namespace.