Coverage Report

Created: 2026-03-31 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/experimental/finitedifferences/fdmsimple2dextousolver.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 fdmsimple2dextousolver.hpp
21
    \brief solver for simple swing options based on ext OU process
22
*/
23
24
25
#ifndef quantlib_fdm_2d_ext_ou_solver_hpp
26
#define quantlib_fdm_2d_ext_ou_solver_hpp
27
28
#include <ql/experimental/finitedifferences/fdmextendedornsteinuhlenbeckop.hpp>
29
#include <ql/experimental/processes/extendedornsteinuhlenbeckprocess.hpp>
30
#include <ql/handle.hpp>
31
#include <ql/methods/finitedifferences/solvers/fdm2dimsolver.hpp>
32
#include <ql/methods/finitedifferences/solvers/fdmbackwardsolver.hpp>
33
#include <ql/methods/finitedifferences/solvers/fdmsolverdesc.hpp>
34
#include <ql/patterns/lazyobject.hpp>
35
#include <ql/termstructures/yieldtermstructure.hpp>
36
#include <utility>
37
38
namespace QuantLib {
39
40
    class FdmSimple2dExtOUSolver : public LazyObject {
41
      public:
42
        FdmSimple2dExtOUSolver(const Handle<ExtendedOrnsteinUhlenbeckProcess>& process,
43
                               ext::shared_ptr<YieldTermStructure> rTS,
44
                               FdmSolverDesc solverDesc,
45
                               const FdmSchemeDesc& schemeDesc = FdmSchemeDesc::Hundsdorfer())
46
0
        : process_(process), rTS_(std::move(rTS)), solverDesc_(std::move(solverDesc)),
47
0
          schemeDesc_(schemeDesc) {
48
0
            registerWith(process);
49
0
        }
50
51
0
        Real valueAt(Real x, Real y) const {
52
0
            calculate();
53
0
            return solver_->interpolateAt(x, y);
54
0
        }
55
56
      protected:
57
0
        void performCalculations() const override {
58
0
            ext::shared_ptr<FdmLinearOpComposite>op(
59
0
                new FdmExtendedOrnsteinUhlenbeckOp(
60
0
                                solverDesc_.mesher, process_.currentLink(),
61
0
                                rTS_, solverDesc_.bcSet));
62
63
0
            solver_ = ext::make_shared<Fdm2DimSolver>(
64
0
                          solverDesc_, schemeDesc_, op);
65
0
        }
66
67
      private:
68
        const Handle<ExtendedOrnsteinUhlenbeckProcess> process_;
69
        const ext::shared_ptr<YieldTermStructure> rTS_;
70
        const FdmSolverDesc solverDesc_;
71
        const FdmSchemeDesc schemeDesc_;
72
73
        mutable ext::shared_ptr<Fdm2DimSolver> solver_;
74
    };
75
}
76
77
#endif
78