QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdblackscholesrebateengine.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2008 Andreas Gaida
5 Copyright (C) 2008, 2009 Ralph Schreyer
6 Copyright (C) 2008 Klaus Spanderen
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22#include <ql/exercise.hpp>
23#include <ql/methods/finitedifferences/meshers/fdmblackscholesmesher.hpp>
24#include <ql/methods/finitedifferences/meshers/fdmmeshercomposite.hpp>
25#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
26#include <ql/methods/finitedifferences/solvers/fdmblackscholessolver.hpp>
27#include <ql/methods/finitedifferences/stepconditions/fdmstepconditioncomposite.hpp>
28#include <ql/methods/finitedifferences/utilities/fdmdirichletboundary.hpp>
29#include <ql/methods/finitedifferences/utilities/fdminnervaluecalculator.hpp>
30#include <ql/pricingengines/barrier/fdblackscholesrebateengine.hpp>
31#include <utility>
32
33namespace QuantLib {
34
36 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
37 Size tGrid,
38 Size xGrid,
39 Size dampingSteps,
40 const FdmSchemeDesc& schemeDesc,
41 bool localVol,
42 Real illegalLocalVolOverwrite)
43 : process_(std::move(process)), explicitDividends_(false),
44 tGrid_(tGrid), xGrid_(xGrid), dampingSteps_(dampingSteps),
45 schemeDesc_(schemeDesc), localVol_(localVol),
46 illegalLocalVolOverwrite_(illegalLocalVolOverwrite) {
47
49 }
50
52 ext::shared_ptr<GeneralizedBlackScholesProcess> process,
53 DividendSchedule dividends,
54 Size tGrid,
55 Size xGrid,
56 Size dampingSteps,
57 const FdmSchemeDesc& schemeDesc,
58 bool localVol,
59 Real illegalLocalVolOverwrite)
60 : process_(std::move(process)), dividends_(std::move(dividends)), explicitDividends_(true),
61 tGrid_(tGrid), xGrid_(xGrid), dampingSteps_(dampingSteps),
62 schemeDesc_(schemeDesc), localVol_(localVol),
63 illegalLocalVolOverwrite_(illegalLocalVolOverwrite) {
64
66 }
67
69
70 // dividends will eventually be moved out of arguments, but for now we need the switch
71 QL_DEPRECATED_DISABLE_WARNING
73 QL_DEPRECATED_ENABLE_WARNING
74
75 // 1. Mesher
76 const ext::shared_ptr<StrikedTypePayoff> payoff =
77 ext::dynamic_pointer_cast<StrikedTypePayoff>(arguments_.payoff);
78 const Time maturity = process_->time(arguments_.exercise->lastDate());
79
80 Real xMin=Null<Real>();
81 Real xMax=Null<Real>();
84 xMin = std::log(arguments_.barrier);
85 }
88 xMax = std::log(arguments_.barrier);
89 }
90
91 const ext::shared_ptr<Fdm1dMesher> equityMesher(
93 xGrid_, process_, maturity, payoff->strike(),
94 xMin, xMax, 0.0001, 1.5,
95 std::make_pair(Null<Real>(), Null<Real>()),
96 dividendSchedule));
97
98 const ext::shared_ptr<FdmMesher> mesher (
99 new FdmMesherComposite(equityMesher));
100
101 // 2. Calculator
102 const ext::shared_ptr<StrikedTypePayoff> rebatePayoff(
104 const ext::shared_ptr<FdmInnerValueCalculator> calculator(
105 new FdmLogInnerValue(rebatePayoff, mesher, 0));
106
107 // 3. Step conditions
108 QL_REQUIRE(arguments_.exercise->type() == Exercise::European,
109 "only european style option are supported");
110
111 const ext::shared_ptr<FdmStepConditionComposite> conditions =
113 dividendSchedule, arguments_.exercise,
114 mesher, calculator,
115 process_->riskFreeRate()->referenceDate(),
116 process_->riskFreeRate()->dayCounter());
117
118 // 4. Boundary conditions
119 FdmBoundaryConditionSet boundaries;
122 boundaries.push_back(FdmBoundaryConditionSet::value_type(
125
126 }
129 boundaries.push_back(FdmBoundaryConditionSet::value_type(
132 }
133
134 // 5. Solver
135 FdmSolverDesc solverDesc = { mesher, boundaries, conditions, calculator,
136 maturity, tGrid_, dampingSteps_ };
137
138 const ext::shared_ptr<FdmBlackScholesSolver> solver(
141 payoff->strike(), solverDesc, schemeDesc_,
143
144 const Real spot = process_->x0();
145 results_.value = solver->valueAt(spot);
146 results_.delta = solver->deltaAt(spot);
147 results_.gamma = solver->gammaAt(spot);
148 results_.theta = solver->thetaAt(spot);
149 }
150}
Binary cash-or-nothing payoff.
Definition: payoffs.hpp:152
FdBlackScholesRebateEngine(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 >())
ext::shared_ptr< GeneralizedBlackScholesProcess > process_
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.