Coverage Report

Created: 2026-01-25 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/methods/finitedifferences/solvers/fdmhestonsolver.cpp
Line
Count
Source
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, 2011, 2014, 2015 Klaus Spanderen
7
 Copyright (C) 2015 Johannes Göttker-Schnetmann
8
9
 This file is part of QuantLib, a free-software/open-source library
10
 for financial quantitative analysts and developers - http://quantlib.org/
11
12
 QuantLib is free software: you can redistribute it and/or modify it
13
 under the terms of the QuantLib license.  You should have received a
14
 copy of the license along with this program; if not, please email
15
 <quantlib-dev@lists.sf.net>. The license is also available online at
16
 <https://www.quantlib.org/license.shtml>.
17
18
 This program is distributed in the hope that it will be useful, but WITHOUT
19
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20
 FOR A PARTICULAR PURPOSE.  See the license for more details.
21
*/
22
23
#include <ql/methods/finitedifferences/operators/fdmhestonop.hpp>
24
#include <ql/methods/finitedifferences/solvers/fdm2dimsolver.hpp>
25
#include <ql/methods/finitedifferences/solvers/fdmhestonsolver.hpp>
26
#include <ql/processes/hestonprocess.hpp>
27
#include <utility>
28
29
namespace QuantLib {
30
31
    FdmHestonSolver::FdmHestonSolver(Handle<HestonProcess> process,
32
                                     FdmSolverDesc solverDesc,
33
                                     const FdmSchemeDesc& schemeDesc,
34
                                     Handle<FdmQuantoHelper> quantoHelper,
35
                                     ext::shared_ptr<LocalVolTermStructure> leverageFct,
36
                                     const Real mixingFactor)
37
0
    : process_(std::move(process)), solverDesc_(std::move(solverDesc)), schemeDesc_(schemeDesc),
38
0
      quantoHelper_(std::move(quantoHelper)), leverageFct_(std::move(leverageFct)),
39
0
      mixingFactor_(mixingFactor) {
40
41
0
        registerWith(process_);
42
0
        registerWith(quantoHelper_);
43
0
    }
Unexecuted instantiation: QuantLib::FdmHestonSolver::FdmHestonSolver(QuantLib::Handle<QuantLib::HestonProcess>, QuantLib::FdmSolverDesc, QuantLib::FdmSchemeDesc const&, QuantLib::Handle<QuantLib::FdmQuantoHelper>, boost::shared_ptr<QuantLib::LocalVolTermStructure>, double)
Unexecuted instantiation: QuantLib::FdmHestonSolver::FdmHestonSolver(QuantLib::Handle<QuantLib::HestonProcess>, QuantLib::FdmSolverDesc, QuantLib::FdmSchemeDesc const&, QuantLib::Handle<QuantLib::FdmQuantoHelper>, boost::shared_ptr<QuantLib::LocalVolTermStructure>, double)
44
45
0
    void FdmHestonSolver::performCalculations() const {
46
0
        ext::shared_ptr<FdmLinearOpComposite> op(
47
0
      ext::make_shared<FdmHestonOp>(
48
0
                solverDesc_.mesher, process_.currentLink(),
49
0
                (!quantoHelper_.empty()) ? quantoHelper_.currentLink()
50
0
                             : ext::shared_ptr<FdmQuantoHelper>(),
51
0
                leverageFct_, mixingFactor_));
52
53
0
        solver_ = ext::make_shared<Fdm2DimSolver>(solverDesc_, schemeDesc_, op);
54
0
    }
55
56
0
    Real FdmHestonSolver::valueAt(Real s, Real v) const {
57
0
        calculate();
58
0
        return solver_->interpolateAt(std::log(s), v);
59
0
    }
60
61
0
    Real FdmHestonSolver::deltaAt(Real s, Real v) const {
62
0
        calculate();
63
0
        return solver_->derivativeX(std::log(s), v)/s;
64
0
    }
65
66
0
    Real FdmHestonSolver::gammaAt(Real s, Real v) const {
67
0
        calculate();
68
0
        const Real x = std::log(s);
69
0
        return (solver_->derivativeXX(x, v)-solver_->derivativeX(x, v))/(s*s);
70
0
    }
71
72
0
    Real FdmHestonSolver::meanVarianceDeltaAt(Real s, Real v) const {
73
0
        calculate();
74
75
0
        const Real alpha = process_->rho()*process_->sigma()/s;
76
0
        return deltaAt(s, v) + alpha*solver_->derivativeY(std::log(s), v);
77
0
    }
78
79
0
    Real FdmHestonSolver::meanVarianceGammaAt(Real s, Real v) const {
80
0
        calculate();
81
82
0
        const Real x = std::log(s);
83
0
        const Real alpha = process_->rho()*process_->sigma()/s;
84
0
        return gammaAt(s, v)
85
0
                +  solver_->derivativeYY(x, v)*alpha*alpha
86
0
                +2*solver_->derivativeXY(x, v)*alpha/s;
87
0
    }
88
89
0
    Real FdmHestonSolver::thetaAt(Real s, Real v) const {
90
0
        calculate();
91
0
        return solver_->thetaAt(std::log(s), v);
92
0
    }
93
}