Coverage Report

Created: 2025-11-04 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/experimental/finitedifferences/fdmexpextouinnervaluecalculator.hpp
Line
Count
Source
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 fdmexpextouinnervaluecalculator.hpp
21
    \brief inner value calculator for an exponential extended
22
           Ornstein Uhlenbeck grid
23
*/
24
25
#ifndef quantlib_fdm_exp_ext_ou_inner_value_calculator_hpp
26
#define quantlib_fdm_exp_ext_ou_inner_value_calculator_hpp
27
28
#include <ql/methods/finitedifferences/meshers/fdmmesher.hpp>
29
#include <ql/methods/finitedifferences/utilities/fdminnervaluecalculator.hpp>
30
#include <ql/payoff.hpp>
31
#include <utility>
32
33
namespace QuantLib {
34
35
    class FdmExpExtOUInnerValueCalculator : public FdmInnerValueCalculator {
36
      public:
37
        typedef std::vector<std::pair<Time, Real> > Shape;
38
39
        FdmExpExtOUInnerValueCalculator(ext::shared_ptr<Payoff> payoff,
40
                                        ext::shared_ptr<FdmMesher> mesher,
41
                                        ext::shared_ptr<Shape> shape = ext::shared_ptr<Shape>(),
42
                                        Size direction = 0)
43
0
        : direction_(direction), payoff_(std::move(payoff)), mesher_(std::move(mesher)),
44
0
          shape_(std::move(shape)) {}
45
46
0
        Real innerValue(const FdmLinearOpIterator& iter, Time t) override {
47
0
            const Real u = mesher_->location(iter, direction_);
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
55
0
            return (*payoff_)(std::exp(f + u));
56
0
        }
57
0
        Real avgInnerValue(const FdmLinearOpIterator& iter, Time t) override {
58
0
            return innerValue(iter, t);
59
0
        }
60
61
      private:
62
        const Size direction_;
63
        const ext::shared_ptr<Payoff> payoff_;
64
        const ext::shared_ptr<FdmMesher> mesher_;
65
        const ext::shared_ptr<Shape> shape_;
66
    };
67
68
}
69
#endif