/src/quantlib/ql/methods/finitedifferences/operators/fdmhestonop.hpp
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 Ralph Schreyer |
6 | | Copyright (C) 2008, 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 | | <http://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 | | /*! \file fdmhestonop.hpp |
24 | | \brief Heston linear operator |
25 | | */ |
26 | | |
27 | | #ifndef quantlib_fdm_heston_op_hpp |
28 | | #define quantlib_fdm_heston_op_hpp |
29 | | |
30 | | #include <ql/processes/hestonprocess.hpp> |
31 | | #include <ql/methods/finitedifferences/utilities/fdmquantohelper.hpp> |
32 | | #include <ql/methods/finitedifferences/operators/firstderivativeop.hpp> |
33 | | #include <ql/methods/finitedifferences/operators/triplebandlinearop.hpp> |
34 | | #include <ql/methods/finitedifferences/operators/ninepointlinearop.hpp> |
35 | | #include <ql/methods/finitedifferences/operators/fdmlinearopcomposite.hpp> |
36 | | #include <ql/termstructures/volatility/equityfx/localvoltermstructure.hpp> |
37 | | |
38 | | namespace QuantLib { |
39 | | |
40 | | class FdmHestonEquityPart { |
41 | | public: |
42 | | FdmHestonEquityPart(const ext::shared_ptr<FdmMesher>& mesher, |
43 | | ext::shared_ptr<YieldTermStructure> rTS, |
44 | | ext::shared_ptr<YieldTermStructure> qTS, |
45 | | ext::shared_ptr<FdmQuantoHelper> quantoHelper, |
46 | | ext::shared_ptr<LocalVolTermStructure> leverageFct = |
47 | | ext::shared_ptr<LocalVolTermStructure>()); |
48 | | |
49 | | void setTime(Time t1, Time t2); |
50 | | const TripleBandLinearOp& getMap() const; |
51 | 0 | const Array& getL() const { return L_; } |
52 | | |
53 | | protected: |
54 | | Array getLeverageFctSlice(Time t1, Time t2) const; |
55 | | |
56 | | Array varianceValues_, volatilityValues_, L_; |
57 | | const FirstDerivativeOp dxMap_; |
58 | | const TripleBandLinearOp dxxMap_; |
59 | | TripleBandLinearOp mapT_; |
60 | | |
61 | | const ext::shared_ptr<FdmMesher> mesher_; |
62 | | const ext::shared_ptr<YieldTermStructure> rTS_, qTS_; |
63 | | const ext::shared_ptr<FdmQuantoHelper> quantoHelper_; |
64 | | const ext::shared_ptr<LocalVolTermStructure> leverageFct_; |
65 | | }; |
66 | | |
67 | | class FdmHestonVariancePart { |
68 | | public: |
69 | | FdmHestonVariancePart(const ext::shared_ptr<FdmMesher>& mesher, |
70 | | ext::shared_ptr<YieldTermStructure> rTS, |
71 | | Real mixedSigma, |
72 | | Real kappa, |
73 | | Real theta); |
74 | | |
75 | | void setTime(Time t1, Time t2); |
76 | | const TripleBandLinearOp& getMap() const; |
77 | | |
78 | | protected: |
79 | | const TripleBandLinearOp dyMap_; |
80 | | TripleBandLinearOp mapT_; |
81 | | |
82 | | const ext::shared_ptr<YieldTermStructure> rTS_; |
83 | | }; |
84 | | |
85 | | |
86 | | class FdmHestonOp : public FdmLinearOpComposite { |
87 | | public: |
88 | | FdmHestonOp(const ext::shared_ptr<FdmMesher>& mesher, |
89 | | const ext::shared_ptr<HestonProcess>& hestonProcess, |
90 | | const ext::shared_ptr<FdmQuantoHelper>& quantoHelper = |
91 | | ext::shared_ptr<FdmQuantoHelper>(), |
92 | | const ext::shared_ptr<LocalVolTermStructure>& leverageFct = |
93 | | ext::shared_ptr<LocalVolTermStructure>(), |
94 | | Real mixingFactor = 1.0); |
95 | | |
96 | | Size size() const override; |
97 | | void setTime(Time t1, Time t2) override; |
98 | | |
99 | | Array apply(const Array& r) const override; |
100 | | Array apply_mixed(const Array& r) const override; |
101 | | |
102 | | Array apply_direction(Size direction, const Array& r) const override; |
103 | | Array solve_splitting(Size direction, const Array& r, Real s) const override; |
104 | | Array preconditioner(const Array& r, Real s) const override; |
105 | | |
106 | | std::vector<SparseMatrix> toMatrixDecomp() const override; |
107 | | |
108 | | private: |
109 | | NinePointLinearOp correlationMap_; |
110 | | FdmHestonVariancePart dyMap_; |
111 | | FdmHestonEquityPart dxMap_; |
112 | | }; |
113 | | } |
114 | | |
115 | | #endif |