/src/quantlib/ql/methods/finitedifferences/solvers/fdmcirsolver.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2020 Lew Wei Hao |
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 | | #include <ql/methods/finitedifferences/operators/fdmcirop.hpp> |
21 | | #include <ql/methods/finitedifferences/solvers/fdm2dimsolver.hpp> |
22 | | #include <ql/methods/finitedifferences/solvers/fdmcirsolver.hpp> |
23 | | #include <ql/processes/hestonprocess.hpp> |
24 | | #include <utility> |
25 | | |
26 | | namespace QuantLib { |
27 | | |
28 | | FdmCIRSolver::FdmCIRSolver(Handle<CoxIngersollRossProcess> cirProcess, |
29 | | Handle<GeneralizedBlackScholesProcess> bsProcess, |
30 | | FdmSolverDesc solverDesc, |
31 | | const FdmSchemeDesc& schemeDesc, |
32 | | const Real rho, |
33 | | const Real strike) |
34 | 0 | : bsProcess_(std::move(bsProcess)), cirProcess_(std::move(cirProcess)), |
35 | 0 | solverDesc_(std::move(solverDesc)), schemeDesc_(schemeDesc), rho_(rho), strike_(strike) { |
36 | 0 | registerWith(bsProcess_); |
37 | 0 | registerWith(cirProcess_); |
38 | 0 | } Unexecuted instantiation: QuantLib::FdmCIRSolver::FdmCIRSolver(QuantLib::Handle<QuantLib::CoxIngersollRossProcess>, QuantLib::Handle<QuantLib::GeneralizedBlackScholesProcess>, QuantLib::FdmSolverDesc, QuantLib::FdmSchemeDesc const&, double, double) Unexecuted instantiation: QuantLib::FdmCIRSolver::FdmCIRSolver(QuantLib::Handle<QuantLib::CoxIngersollRossProcess>, QuantLib::Handle<QuantLib::GeneralizedBlackScholesProcess>, QuantLib::FdmSolverDesc, QuantLib::FdmSchemeDesc const&, double, double) |
39 | | |
40 | 0 | void FdmCIRSolver::performCalculations() const { |
41 | 0 | ext::shared_ptr<FdmLinearOpComposite> op( |
42 | 0 | ext::make_shared<FdmCIROp>( |
43 | 0 | solverDesc_.mesher, |
44 | 0 | cirProcess_.currentLink(), |
45 | 0 | bsProcess_.currentLink(), |
46 | 0 | rho_, |
47 | 0 | strike_)); |
48 | |
|
49 | 0 | solver_ = ext::make_shared<Fdm2DimSolver>(solverDesc_, schemeDesc_, op); |
50 | 0 | } |
51 | | |
52 | 0 | Real FdmCIRSolver::valueAt(Real s, Real r) const { |
53 | 0 | calculate(); |
54 | 0 | return solver_->interpolateAt(std::log(s), r); |
55 | 0 | } |
56 | | |
57 | 0 | Real FdmCIRSolver::deltaAt(Real s, Real r) const { |
58 | 0 | calculate(); |
59 | 0 | return solver_->derivativeX(std::log(s), r)/s; |
60 | 0 | } |
61 | | |
62 | 0 | Real FdmCIRSolver::gammaAt(Real s, Real r) const { |
63 | 0 | calculate(); |
64 | 0 | const Real x = std::log(s); |
65 | 0 | return (solver_->derivativeXX(x, r)-solver_->derivativeX(x, r))/(s*s); |
66 | 0 | } |
67 | | |
68 | 0 | Real FdmCIRSolver::thetaAt(Real s, Real r) const { |
69 | 0 | calculate(); |
70 | 0 | return solver_->thetaAt(std::log(s), r); |
71 | 0 | } |
72 | | } |