Coverage Report

Created: 2025-08-11 06:28

/src/quantlib/ql/methods/finitedifferences/solvers/fdmblackscholessolver.cpp
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) 2008 Andreas Gaida
5
 Copyright (C) 2008, 2009 Ralph Schreyer
6
 Copyright (C) 2008, 2009 Klaus Spanderen
7
8
 This file is part of QuantLib, a free-software/open-source library
9
 for financial quantitative analysts and developers - http://quantlib.org/
10
11
 QuantLib is free software: you can redistribute it and/or modify it
12
 under the terms of the QuantLib license.  You should have received a
13
 copy of the license along with this program; if not, please email
14
 <quantlib-dev@lists.sf.net>. The license is also available online at
15
 <http://quantlib.org/license.shtml>.
16
17
 This program is distributed in the hope that it will be useful, but WITHOUT
18
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 FOR A PARTICULAR PURPOSE.  See the license for more details.
20
*/
21
22
#include <ql/methods/finitedifferences/operators/fdmblackscholesop.hpp>
23
#include <ql/methods/finitedifferences/solvers/fdm1dimsolver.hpp>
24
#include <ql/methods/finitedifferences/solvers/fdmblackscholessolver.hpp>
25
#include <ql/processes/blackscholesprocess.hpp>
26
#include <utility>
27
28
namespace QuantLib {
29
30
    FdmBlackScholesSolver::FdmBlackScholesSolver(Handle<GeneralizedBlackScholesProcess> process,
31
                                                 Real strike,
32
                                                 FdmSolverDesc solverDesc,
33
                                                 const FdmSchemeDesc& schemeDesc,
34
                                                 bool localVol,
35
                                                 Real illegalLocalVolOverwrite,
36
                                                 Handle<FdmQuantoHelper> quantoHelper)
37
0
    : process_(std::move(process)), strike_(strike), solverDesc_(std::move(solverDesc)),
38
0
      schemeDesc_(schemeDesc), localVol_(localVol),
39
0
      illegalLocalVolOverwrite_(illegalLocalVolOverwrite), quantoHelper_(std::move(quantoHelper)) {
40
41
0
        registerWith(process_);
42
0
        registerWith(quantoHelper_);
43
0
    }
Unexecuted instantiation: QuantLib::FdmBlackScholesSolver::FdmBlackScholesSolver(QuantLib::Handle<QuantLib::GeneralizedBlackScholesProcess>, double, QuantLib::FdmSolverDesc, QuantLib::FdmSchemeDesc const&, bool, double, QuantLib::Handle<QuantLib::FdmQuantoHelper>)
Unexecuted instantiation: QuantLib::FdmBlackScholesSolver::FdmBlackScholesSolver(QuantLib::Handle<QuantLib::GeneralizedBlackScholesProcess>, double, QuantLib::FdmSolverDesc, QuantLib::FdmSchemeDesc const&, bool, double, QuantLib::Handle<QuantLib::FdmQuantoHelper>)
44
45
0
    void FdmBlackScholesSolver::performCalculations() const {
46
0
            const ext::shared_ptr<FdmBlackScholesOp> op(
47
0
            ext::make_shared<FdmBlackScholesOp>(
48
0
                solverDesc_.mesher, process_.currentLink(), strike_,
49
0
                localVol_, illegalLocalVolOverwrite_, 0,
50
0
                (quantoHelper_.empty())
51
0
                    ? ext::shared_ptr<FdmQuantoHelper>()
52
0
                    : quantoHelper_.currentLink()));
53
54
0
        solver_ = ext::make_shared<Fdm1DimSolver>(solverDesc_, schemeDesc_, op);
55
0
    }
56
57
0
    Real FdmBlackScholesSolver::valueAt(Real s) const {
58
0
        calculate();
59
0
        return solver_->interpolateAt(std::log(s));
60
0
    }
61
62
0
    Real FdmBlackScholesSolver::deltaAt(Real s) const {
63
0
        calculate();
64
0
        return solver_->derivativeX(std::log(s))/s;
65
0
    }
66
67
0
    Real FdmBlackScholesSolver::gammaAt(Real s) const {
68
0
        calculate();
69
0
        return (solver_->derivativeXX(std::log(s))
70
0
                -solver_->derivativeX(std::log(s)))/(s*s);
71
0
    }
72
73
0
    Real FdmBlackScholesSolver::thetaAt(Real s) const {
74
0
        return solver_->thetaAt(std::log(s));
75
0
    }
76
}