/src/quantlib/ql/methods/finitedifferences/solvers/fdmbatessolver.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) 2010, 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 | | <http://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 fdmbatessolver.cpp |
21 | | */ |
22 | | |
23 | | #include <ql/methods/finitedifferences/operators/fdmbatesop.hpp> |
24 | | #include <ql/methods/finitedifferences/solvers/fdm2dimsolver.hpp> |
25 | | #include <ql/methods/finitedifferences/solvers/fdmbatessolver.hpp> |
26 | | #include <ql/processes/batesprocess.hpp> |
27 | | #include <utility> |
28 | | |
29 | | |
30 | | namespace QuantLib { |
31 | | |
32 | | FdmBatesSolver::FdmBatesSolver(Handle<BatesProcess> process, |
33 | | FdmSolverDesc solverDesc, |
34 | | const FdmSchemeDesc& schemeDesc, |
35 | | Size integroIntegrationOrder, |
36 | | Handle<FdmQuantoHelper> quantoHelper) |
37 | 0 | : process_(std::move(process)), solverDesc_(std::move(solverDesc)), schemeDesc_(schemeDesc), |
38 | 0 | integroIntegrationOrder_(integroIntegrationOrder), quantoHelper_(std::move(quantoHelper)) { |
39 | 0 | registerWith(process_); |
40 | 0 | registerWith(quantoHelper_); |
41 | 0 | } Unexecuted instantiation: QuantLib::FdmBatesSolver::FdmBatesSolver(QuantLib::Handle<QuantLib::BatesProcess>, QuantLib::FdmSolverDesc, QuantLib::FdmSchemeDesc const&, unsigned long, QuantLib::Handle<QuantLib::FdmQuantoHelper>) Unexecuted instantiation: QuantLib::FdmBatesSolver::FdmBatesSolver(QuantLib::Handle<QuantLib::BatesProcess>, QuantLib::FdmSolverDesc, QuantLib::FdmSchemeDesc const&, unsigned long, QuantLib::Handle<QuantLib::FdmQuantoHelper>) |
42 | | |
43 | 0 | void FdmBatesSolver::performCalculations() const { |
44 | 0 | ext::shared_ptr<FdmLinearOpComposite> op( |
45 | 0 | new FdmBatesOp(solverDesc_.mesher, process_.currentLink(), |
46 | 0 | solverDesc_.bcSet, integroIntegrationOrder_, |
47 | 0 | (!quantoHelper_.empty()) |
48 | 0 | ? quantoHelper_.currentLink() |
49 | 0 | : ext::shared_ptr<FdmQuantoHelper>())); |
50 | |
|
51 | 0 | solver_ = ext::make_shared<Fdm2DimSolver>( |
52 | 0 | solverDesc_, schemeDesc_, op); |
53 | 0 | } |
54 | | |
55 | 0 | Real FdmBatesSolver::valueAt(Real s, Real v) const { |
56 | 0 | calculate(); |
57 | 0 | return solver_->interpolateAt(std::log(s), v); |
58 | 0 | } |
59 | | |
60 | 0 | Real FdmBatesSolver::deltaAt(Real s, Real v) const { |
61 | 0 | calculate(); |
62 | 0 | return solver_->derivativeX(std::log(s), v)/s; |
63 | 0 | } |
64 | | |
65 | 0 | Real FdmBatesSolver::gammaAt(Real s, Real v) const { |
66 | 0 | calculate(); |
67 | 0 | const Real x = std::log(s); |
68 | 0 | return (solver_->derivativeXX(x, v)-solver_->derivativeX(x, v))/(s*s); |
69 | 0 | } |
70 | | |
71 | 0 | Real FdmBatesSolver::thetaAt(Real s, Real v) const { |
72 | 0 | calculate(); |
73 | 0 | return solver_->thetaAt(std::log(s), v); |
74 | 0 | } |
75 | | |
76 | | } |