Coverage Report

Created: 2026-09-28 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/methods/finitedifferences/operators/fdmbatesop.hpp
Line
Count
Source
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
/*! \file fdmbatesop.hpp
21
    \brief Bates linear operator
22
*/
23
24
#ifndef quantlib_fdm_bates_op_hpp
25
#define quantlib_fdm_bates_op_hpp
26
27
#include <ql/math/integrals/gaussianquadratures.hpp>
28
#include <ql/methods/finitedifferences/operators/fdmhestonop.hpp>
29
#include <ql/methods/finitedifferences/utilities/fdmboundaryconditionset.hpp>
30
31
namespace QuantLib {
32
33
    class LinearInterpolation;
34
    class BatesProcess;
35
    
36
    class FdmBatesOp : public FdmLinearOpComposite {
37
      public:
38
        FdmBatesOp(const ext::shared_ptr<FdmMesher>& mesher,
39
                   const ext::shared_ptr<BatesProcess>& batesProcess,
40
                   FdmBoundaryConditionSet bcSet,
41
                   Size integroIntegrationOrder,
42
                   const ext::shared_ptr<FdmQuantoHelper>& quantoHelper =
43
                       ext::shared_ptr<FdmQuantoHelper>());
44
45
        Size size() const override;
46
        void setTime(Time t1, Time t2) override;
47
48
        Array apply(const Array& r) const override;
49
        Array apply_mixed(const Array& r) const override;
50
51
        Array apply_direction(Size direction, const Array& r) const override;
52
        Array solve_splitting(Size direction, const Array& r, Real s) const override;
53
        Array preconditioner(const Array& r, Real s) const override;
54
55
        std::vector<SparseMatrix> toMatrixDecomp() const override;
56
57
      private:
58
        class IntegroIntegrand {
59
          public:
60
            IntegroIntegrand(const ext::shared_ptr<LinearInterpolation>& i,
61
                             const FdmBoundaryConditionSet& bcSet,
62
                             Real x, Real delta, Real nu);
63
            Real operator()(Real y) const;
64
            
65
          private:
66
            const Real x_, delta_, nu_;
67
            const FdmBoundaryConditionSet& bcSet_;
68
            const ext::shared_ptr<LinearInterpolation>& interpl_;
69
        };
70
          
71
        Array integro(const Array& r) const;  
72
        
73
        Array x_, weights_;
74
        
75
        const Real lambda_, delta_, nu_, m_;
76
        GaussHermiteIntegration gaussHermiteIntegration_;
77
        
78
        const ext::shared_ptr<FdmMesher> mesher_;
79
        const FdmBoundaryConditionSet bcSet_;
80
        const ext::shared_ptr<FdmHestonOp> hestonOp_;
81
    };
82
83
    // inline
84
0
    inline Size FdmBatesOp::size() const {
85
0
        return hestonOp_->size();
86
0
    }
87
    
88
0
    inline void FdmBatesOp::setTime(Time t1, Time t2) {
89
0
        hestonOp_->setTime(t1, t2);
90
0
    }
91
    
92
0
    inline Array FdmBatesOp::apply(const Array& r) const {
93
0
        return hestonOp_->apply(r) + integro(r);
94
0
    }
95
    
96
0
    inline Array FdmBatesOp::apply_mixed(const Array& r) const {
97
0
        return hestonOp_->apply_mixed(r) + integro(r);
98
0
    }
99
100
    inline Array FdmBatesOp::apply_direction(Size direction,
101
0
                                             const Array& r) const {
102
0
        return hestonOp_->apply_direction(direction, r);
103
0
    }
104
105
    inline Array FdmBatesOp::solve_splitting(Size direction,
106
                                             const Array& r,
107
0
                                             Real s) const{
108
0
        return hestonOp_->solve_splitting(direction, r, s);
109
0
    }
110
 
111
    inline Array FdmBatesOp::preconditioner(const Array& r,
112
0
                                            Real s) const {
113
0
        return hestonOp_->preconditioner(r, s);
114
0
    }
115
    
116
}
117
118
#endif