/src/quantlib/ql/experimental/finitedifferences/fdmdupire1dop.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2014 Peter Caspers |
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/experimental/finitedifferences/fdmdupire1dop.hpp> |
21 | | #include <ql/methods/finitedifferences/operators/secondderivativeop.hpp> |
22 | | #include <boost/numeric/ublas/matrix.hpp> |
23 | | |
24 | | namespace QuantLib { |
25 | | |
26 | | FdmDupire1dOp::FdmDupire1dOp(const ext::shared_ptr<FdmMesher> &mesher, |
27 | | const Array &localVolatility) |
28 | 0 | : mesher_(mesher), localVolatility_(localVolatility), |
29 | 0 | mapT_(SecondDerivativeOp(0, mesher) |
30 | 0 | .mult(0.5 * localVolatility * localVolatility)) {} |
31 | | |
32 | 0 | void FdmDupire1dOp::setTime(Time t1, Time t2) {} |
33 | | |
34 | 0 | Size FdmDupire1dOp::size() const { return 1; } |
35 | | |
36 | 0 | Array FdmDupire1dOp::apply(const Array &u) const { |
37 | 0 | return mapT_.apply(u); |
38 | 0 | } |
39 | | |
40 | 0 | Array FdmDupire1dOp::apply_direction(Size direction, const Array &r) const { |
41 | 0 | if (direction == 0) |
42 | 0 | return mapT_.apply(r); |
43 | 0 | QL_FAIL("direction too large"); |
44 | 0 | } |
45 | | |
46 | 0 | Array FdmDupire1dOp::apply_mixed(const Array &r) const { |
47 | 0 | return r; |
48 | 0 | } |
49 | | |
50 | 0 | Array FdmDupire1dOp::solve_splitting(Size direction, const Array &r, Real a) const { |
51 | 0 | if (direction == 0) { |
52 | 0 | return mapT_.solve_splitting(r, a, 1.0); |
53 | 0 | } |
54 | 0 | QL_FAIL("direction too large"); |
55 | 0 | } |
56 | | |
57 | 0 | Array FdmDupire1dOp::preconditioner(const Array &r, Real dt) const { |
58 | |
|
59 | 0 | return solve_splitting(0, r, dt); |
60 | 0 | } |
61 | | |
62 | 0 | std::vector<SparseMatrix> FdmDupire1dOp::toMatrixDecomp() const { |
63 | 0 | return std::vector<SparseMatrix>(1, mapT_.toMatrix()); |
64 | 0 | } |
65 | | |
66 | | } |