/src/quantlib/ql/experimental/finitedifferences/fdmextoujumpmodelinnervalue.hpp
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) 2011 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 | | /*! \file fdmextoujumpmodelinnervalue.hpp |
21 | | \brief inner value calculator for the Ornstein Uhlenbeck |
22 | | plus exponential jumps model (Kluge Model) |
23 | | */ |
24 | | |
25 | | #ifndef quantlib_fdm_ext_ou_jump_model_inner_value_hpp |
26 | | #define quantlib_fdm_ext_ou_jump_model_inner_value_hpp |
27 | | |
28 | | #include <ql/methods/finitedifferences/meshers/fdmmesher.hpp> |
29 | | #include <ql/methods/finitedifferences/operators/fdmlinearopiterator.hpp> |
30 | | #include <ql/methods/finitedifferences/utilities/fdminnervaluecalculator.hpp> |
31 | | #include <ql/payoff.hpp> |
32 | | #include <utility> |
33 | | |
34 | | namespace QuantLib { |
35 | | |
36 | | class FdmExtOUJumpModelInnerValue : public FdmInnerValueCalculator { |
37 | | public: |
38 | | typedef std::vector<std::pair<Time, Real> > Shape; |
39 | | |
40 | | FdmExtOUJumpModelInnerValue(ext::shared_ptr<Payoff> payoff, |
41 | | ext::shared_ptr<FdmMesher> mesher, |
42 | | ext::shared_ptr<Shape> shape = ext::shared_ptr<Shape>()) |
43 | 0 | : payoff_(std::move(payoff)), mesher_(std::move(mesher)), shape_(std::move(shape)) {} |
44 | | |
45 | 0 | Real innerValue(const FdmLinearOpIterator& iter, Time t) override { |
46 | 0 | const Real x = mesher_->location(iter, 0); |
47 | 0 | const Real y = mesher_->location(iter, 1); |
48 | |
|
49 | 0 | Real f = 0; |
50 | 0 | if (shape_ != nullptr) { |
51 | 0 | f = std::lower_bound(shape_->begin(), shape_->end(), |
52 | 0 | std::pair<Time, Real>(t-std::sqrt(QL_EPSILON), 0.0))->second; |
53 | 0 | } |
54 | 0 | return (*payoff_)(std::exp(f + x + y)); |
55 | 0 | } |
56 | 0 | Real avgInnerValue(const FdmLinearOpIterator& iter, Time t) override { |
57 | 0 | return innerValue(iter, t); |
58 | 0 | } |
59 | | |
60 | | private: |
61 | | const ext::shared_ptr<Payoff> payoff_; |
62 | | const ext::shared_ptr<FdmMesher> mesher_; |
63 | | const ext::shared_ptr<Shape> shape_; |
64 | | }; |
65 | | } |
66 | | |
67 | | #endif |