/src/quantlib/ql/methods/finitedifferences/solvers/fdm2dblackscholessolver.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2010 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 | | <https://www.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 | | #include <ql/methods/finitedifferences/operators/fdm2dblackscholesop.hpp> |
21 | | #include <ql/methods/finitedifferences/solvers/fdm2dblackscholessolver.hpp> |
22 | | #include <ql/methods/finitedifferences/solvers/fdm2dimsolver.hpp> |
23 | | #include <ql/processes/blackscholesprocess.hpp> |
24 | | #include <utility> |
25 | | |
26 | | namespace QuantLib { |
27 | | |
28 | | Fdm2dBlackScholesSolver::Fdm2dBlackScholesSolver(Handle<GeneralizedBlackScholesProcess> p1, |
29 | | Handle<GeneralizedBlackScholesProcess> p2, |
30 | | const Real correlation, |
31 | | FdmSolverDesc solverDesc, |
32 | | const FdmSchemeDesc& schemeDesc, |
33 | | bool localVol, |
34 | | Real illegalLocalVolOverwrite) |
35 | 0 | : p1_(std::move(p1)), p2_(std::move(p2)), correlation_(correlation), |
36 | 0 | solverDesc_(std::move(solverDesc)), schemeDesc_(schemeDesc), localVol_(localVol), |
37 | 0 | illegalLocalVolOverwrite_(illegalLocalVolOverwrite) { |
38 | |
|
39 | 0 | registerWith(p1_); |
40 | 0 | registerWith(p2_); |
41 | 0 | } Unexecuted instantiation: QuantLib::Fdm2dBlackScholesSolver::Fdm2dBlackScholesSolver(QuantLib::Handle<QuantLib::GeneralizedBlackScholesProcess>, QuantLib::Handle<QuantLib::GeneralizedBlackScholesProcess>, double, QuantLib::FdmSolverDesc, QuantLib::FdmSchemeDesc const&, bool, double) Unexecuted instantiation: QuantLib::Fdm2dBlackScholesSolver::Fdm2dBlackScholesSolver(QuantLib::Handle<QuantLib::GeneralizedBlackScholesProcess>, QuantLib::Handle<QuantLib::GeneralizedBlackScholesProcess>, double, QuantLib::FdmSolverDesc, QuantLib::FdmSchemeDesc const&, bool, double) |
42 | | |
43 | | |
44 | 0 | void Fdm2dBlackScholesSolver::performCalculations() const { |
45 | | |
46 | 0 | ext::shared_ptr<Fdm2dBlackScholesOp> op( |
47 | 0 | ext::make_shared<Fdm2dBlackScholesOp>(solverDesc_.mesher, |
48 | 0 | p1_.currentLink(), |
49 | 0 | p2_.currentLink(), |
50 | 0 | correlation_, |
51 | 0 | solverDesc_.maturity, |
52 | 0 | localVol_, |
53 | 0 | illegalLocalVolOverwrite_)); |
54 | |
|
55 | 0 | solver_ = ext::make_shared<Fdm2DimSolver>(solverDesc_, schemeDesc_, op); |
56 | 0 | } |
57 | | |
58 | 0 | Real Fdm2dBlackScholesSolver::valueAt(Real u, Real v) const { |
59 | 0 | calculate(); |
60 | 0 | const Real x = std::log(u); |
61 | 0 | const Real y = std::log(v); |
62 | |
|
63 | 0 | return solver_->interpolateAt(x, y); |
64 | 0 | } |
65 | | |
66 | 0 | Real Fdm2dBlackScholesSolver::thetaAt(Real u, Real v) const { |
67 | 0 | calculate(); |
68 | 0 | const Real x = std::log(u); |
69 | 0 | const Real y = std::log(v); |
70 | 0 | return solver_->thetaAt(x, y); |
71 | 0 | } |
72 | | |
73 | | |
74 | 0 | Real Fdm2dBlackScholesSolver::deltaXat(Real u, Real v) const { |
75 | 0 | calculate(); |
76 | |
|
77 | 0 | const Real x = std::log(u); |
78 | 0 | const Real y = std::log(v); |
79 | |
|
80 | 0 | return solver_->derivativeX(x, y)/u; |
81 | 0 | } |
82 | | |
83 | 0 | Real Fdm2dBlackScholesSolver::deltaYat(Real u, Real v) const { |
84 | 0 | calculate(); |
85 | |
|
86 | 0 | const Real x = std::log(u); |
87 | 0 | const Real y = std::log(v); |
88 | |
|
89 | 0 | return solver_->derivativeY(x, y)/v; |
90 | 0 | } |
91 | | |
92 | 0 | Real Fdm2dBlackScholesSolver::gammaXat(Real u, Real v) const { |
93 | 0 | calculate(); |
94 | | |
95 | 0 | const Real x = std::log(u); |
96 | 0 | const Real y = std::log(v); |
97 | | |
98 | 0 | return (solver_->derivativeXX(x, y) |
99 | 0 | -solver_->derivativeX(x, y))/(u*u); |
100 | 0 | } |
101 | | |
102 | 0 | Real Fdm2dBlackScholesSolver::gammaYat(Real u, Real v) const { |
103 | 0 | calculate(); |
104 | | |
105 | 0 | const Real x = std::log(u); |
106 | 0 | const Real y = std::log(v); |
107 | | |
108 | 0 | return (solver_->derivativeYY(x, y) |
109 | 0 | -solver_->derivativeY(x, y))/(v*v); |
110 | 0 | } |
111 | | |
112 | 0 | Real Fdm2dBlackScholesSolver::gammaXYat(Real u, Real v) const { |
113 | 0 | calculate(); |
114 | |
|
115 | 0 | const Real x = std::log(u); |
116 | 0 | const Real y = std::log(v); |
117 | |
|
118 | 0 | return solver_->derivativeXY(x, y)/(u*v); |
119 | 0 | } |
120 | | } |