/src/quantlib/ql/methods/finitedifferences/utilities/fdminnervaluecalculator.hpp
Line | Count | Source |
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, 2009 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 | | <https://www.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 | | /*! \file fdminnervaluecalculator.hpp |
23 | | \brief layer of abstraction to calculate the inner value |
24 | | */ |
25 | | |
26 | | #ifndef quantlib_fdm_inner_value_calculator_hpp |
27 | | #define quantlib_fdm_inner_value_calculator_hpp |
28 | | |
29 | | #include <ql/types.hpp> |
30 | | #include <ql/shared_ptr.hpp> |
31 | | #include <functional> |
32 | | #include <vector> |
33 | | |
34 | | |
35 | | namespace QuantLib { |
36 | | |
37 | | class Payoff; |
38 | | class BasketPayoff; |
39 | | class FdmMesher; |
40 | | class FdmLinearOpIterator; |
41 | | |
42 | | |
43 | | class FdmInnerValueCalculator { |
44 | | public: |
45 | 3.20k | virtual ~FdmInnerValueCalculator() = default; |
46 | | |
47 | | virtual Real innerValue(const FdmLinearOpIterator& iter, Time t) = 0; |
48 | | virtual Real avgInnerValue(const FdmLinearOpIterator& iter, Time t) = 0; |
49 | | }; |
50 | | |
51 | | |
52 | | class FdmCellAveragingInnerValue : public FdmInnerValueCalculator { |
53 | | public: |
54 | | FdmCellAveragingInnerValue(ext::shared_ptr<Payoff> payoff, |
55 | | ext::shared_ptr<FdmMesher> mesher, |
56 | | Size direction, |
57 | 0 | std::function<Real(Real)> gridMapping = [](Real x){ return x; }); |
58 | | |
59 | | Real innerValue(const FdmLinearOpIterator& iter, Time) override; |
60 | | Real avgInnerValue(const FdmLinearOpIterator& iter, Time t) override; |
61 | | |
62 | | private: |
63 | | Real avgInnerValueCalc(const FdmLinearOpIterator& iter, Time t); |
64 | | |
65 | | const ext::shared_ptr<Payoff> payoff_; |
66 | | const ext::shared_ptr<FdmMesher> mesher_; |
67 | | const Size direction_; |
68 | | const std::function<Real(Real)> gridMapping_; |
69 | | |
70 | | std::vector<Real> avgInnerValues_; |
71 | | }; |
72 | | |
73 | | class FdmLogInnerValue : public FdmCellAveragingInnerValue { |
74 | | public: |
75 | | FdmLogInnerValue(const ext::shared_ptr<Payoff>& payoff, |
76 | | const ext::shared_ptr<FdmMesher>& mesher, |
77 | | Size direction); |
78 | | }; |
79 | | |
80 | | class FdmLogBasketInnerValue : public FdmInnerValueCalculator { |
81 | | public: |
82 | | FdmLogBasketInnerValue(ext::shared_ptr<BasketPayoff> payoff, |
83 | | ext::shared_ptr<FdmMesher> mesher); |
84 | | |
85 | | Real innerValue(const FdmLinearOpIterator& iter, Time) override; |
86 | | Real avgInnerValue(const FdmLinearOpIterator& iter, Time) override; |
87 | | |
88 | | private: |
89 | | const ext::shared_ptr<BasketPayoff> payoff_; |
90 | | const ext::shared_ptr<FdmMesher> mesher_; |
91 | | }; |
92 | | |
93 | | class FdmZeroInnerValue : public FdmInnerValueCalculator { |
94 | | public: |
95 | 0 | Real innerValue(const FdmLinearOpIterator&, Time) override { return 0.0; } |
96 | 0 | Real avgInnerValue(const FdmLinearOpIterator&, Time) override { return 0.0; } |
97 | | }; |
98 | | } |
99 | | |
100 | | #endif |