• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lballabio / QuantLib / 19787828006

29 Nov 2025 06:42PM UTC coverage: 74.352% (+0.4%) from 73.914%
19787828006

Pull #2344

github

web-flow
Merge e103123e2 into 08ef06893
Pull Request #2344: add multicurve bootstrap

117 of 131 new or added lines in 6 files covered. (89.31%)

413 existing lines in 27 files now uncovered.

57224 of 76964 relevant lines covered (74.35%)

8799680.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/ql/methods/finitedifferences/operators/fdmbatesop.cpp
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.cpp
21
    \brief Bates linear operator
22
*/
23

24
#include <ql/math/interpolations/linearinterpolation.hpp>
25
#include <ql/math/matrix.hpp>
26
#include <ql/methods/finitedifferences/meshers/fdmmesher.hpp>
27
#include <ql/methods/finitedifferences/operators/fdmbatesop.hpp>
28
#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
29
#include <ql/methods/finitedifferences/utilities/fdmdirichletboundary.hpp>
30
#include <ql/processes/batesprocess.hpp>
31
#include <ql/quotes/simplequote.hpp>
32
#include <ql/termstructures/yield/zerospreadedtermstructure.hpp>
33
#include <utility>
34

35
namespace QuantLib {
36

37
    FdmBatesOp::FdmBatesOp(const ext::shared_ptr<FdmMesher>& mesher,
4✔
38
                           const ext::shared_ptr<BatesProcess>& batesProcess,
39
                           FdmBoundaryConditionSet bcSet,
40
                           const Size integroIntegrationOrder,
41
                           const ext::shared_ptr<FdmQuantoHelper>& quantoHelper)
4✔
42
    : lambda_(batesProcess->lambda()), delta_(batesProcess->delta()), nu_(batesProcess->nu()),
4✔
43
      m_(std::exp(nu_ + 0.5 * delta_ * delta_) - 1.0),
4✔
44
      gaussHermiteIntegration_(integroIntegrationOrder), mesher_(mesher), bcSet_(std::move(bcSet)),
8✔
45
      hestonOp_(new FdmHestonOp(
8✔
46
          mesher,
47
          ext::make_shared<HestonProcess>(
12✔
48
              batesProcess->riskFreeRate(),
4✔
49
              Handle<YieldTermStructure>(ext::make_shared<ZeroSpreadedTermStructure>(
8✔
50
                  batesProcess->dividendYield(),
4✔
51
                  Handle<Quote>(ext::shared_ptr<Quote>(new SimpleQuote(lambda_ * m_))),
8✔
52
                  Continuous)),
4✔
53
              batesProcess->s0(),
4✔
54
              batesProcess->v0(),
4✔
55
              batesProcess->kappa(),
4✔
56
              batesProcess->theta(),
4✔
57
              batesProcess->sigma(),
4✔
58
              batesProcess->rho()),
4✔
59
          quantoHelper)) {}
12✔
60

61
    FdmBatesOp::IntegroIntegrand::IntegroIntegrand(
1,224,000✔
62
                    const ext::shared_ptr<LinearInterpolation>& interpl,
63
                    const FdmBoundaryConditionSet& bcSet,
64
                    Real x, Real delta, Real nu)
1,224,000✔
65
    : x_(x), delta_(delta), nu_(nu), 
1,224,000✔
66
      bcSet_(bcSet), interpl_(interpl) { }
1,224,000✔
67
                    
68
    Real FdmBatesOp::IntegroIntegrand::operator()(Real y) const {
14,688,000✔
69
        const Real x = x_ + M_SQRT2*delta_*y + nu_;
14,688,000✔
70
        Real valueOfDerivative = (*interpl_)(x, true);
14,688,000✔
71

72
        for (auto iter = bcSet_.begin(); iter < bcSet_.end(); ++iter) {
14,688,000✔
73

74
            const ext::shared_ptr<FdmDirichletBoundary> dirichlet
UNCOV
75
                = ext::dynamic_pointer_cast<FdmDirichletBoundary>(*iter);
×
76

77
            QL_REQUIRE(dirichlet, "FdmBatesOp can only deal with Dirichlet "
×
78
                                  "boundary conditions.");
79

80
            valueOfDerivative
UNCOV
81
                = dirichlet->applyAfterApplying(x, valueOfDerivative);
×
82
        }
83

84
        return std::exp(-y*y)*valueOfDerivative;
14,688,000✔
85
    }
86
    
87
    Array FdmBatesOp::integro(const Array& r) const {
408✔
88
        QL_REQUIRE(mesher_->layout()->dim().size() == 2, "invalid layout dimension");
408✔
89

90
        Array x(mesher_->layout()->dim()[0]);
408✔
91
        Matrix f(mesher_->layout()->dim()[1], mesher_->layout()->dim()[0]);
408✔
92
        
93
        for (const auto& iter : *mesher_->layout()) {
1,224,816✔
94
            const Size i = iter.coordinates()[0];
1,224,000✔
95
            const Size j = iter.coordinates()[1];
1,224,000✔
96
            
97
            x[i]    = mesher_->location(iter, 0);
1,224,000✔
98
            f[j][i] = r[iter.index()];
1,224,000✔
99
            
100
        }
101
        std::vector<ext::shared_ptr<LinearInterpolation> > interpl(f.rows());
408✔
102
        for (Size i=0; i < f.rows(); ++i) {
12,648✔
103
            interpl[i] = ext::make_shared<LinearInterpolation>(
12,240✔
104
                x.begin(), x.end(), f.row_begin(i));
24,480✔
105
        }
106
        
107
        Array integral(r.size());
408✔
108
        for (const auto& iter : *mesher_->layout()) {
1,224,816✔
109
            const Size i = iter.coordinates()[0];
1,224,000✔
110
            const Size j = iter.coordinates()[1];
1,224,000✔
111

112
            integral[iter.index()] = M_1_SQRTPI* 
1,224,000✔
113
                gaussHermiteIntegration_(
1,224,000✔
114
                      IntegroIntegrand(interpl[j], bcSet_, x[i], delta_, nu_));
2,448,000✔
115
        }
116

117
        return lambda_*(integral-r);
1,224✔
118
    }
408✔
119

UNCOV
120
    std::vector<SparseMatrix> FdmBatesOp::toMatrixDecomp() const {
×
UNCOV
121
        QL_FAIL("not implemented");
×
122
    }
123

124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc