| 1 | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | |
| 3 | /* |
| 4 | Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb |
| 5 | Copyright (C) 2004, 2005 StatPro Italia srl |
| 6 | |
| 7 | This file is part of QuantLib, a free-software/open-source library |
| 8 | for financial quantitative analysts and developers - http://quantlib.org/ |
| 9 | |
| 10 | QuantLib is free software: you can redistribute it and/or modify it |
| 11 | under the terms of the QuantLib license. You should have received a |
| 12 | copy of the license along with this program; if not, please email |
| 13 | <quantlib-dev@lists.sf.net>. The license is also available online at |
| 14 | <http://quantlib.org/license.shtml>. |
| 15 | |
| 16 | This program is distributed in the hope that it will be useful, but WITHOUT |
| 17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 18 | FOR A PARTICULAR PURPOSE. See the license for more details. |
| 19 | */ |
| 20 | |
| 21 | /*! \file numericalmethod.hpp |
| 22 | \brief Numerical method class |
| 23 | */ |
| 24 | |
| 25 | #ifndef quantlib_lattice_hpp |
| 26 | #define quantlib_lattice_hpp |
| 27 | |
| 28 | #include <ql/math/array.hpp> |
| 29 | #include <ql/timegrid.hpp> |
| 30 | #include <utility> |
| 31 | |
| 32 | namespace QuantLib { |
| 33 | |
| 34 | class DiscretizedAsset; |
| 35 | |
| 36 | //! %Lattice (tree, finite-differences) base class |
| 37 | class Lattice { |
| 38 | public: |
| 39 | explicit Lattice(TimeGrid timeGrid) : t_(std::move(timeGrid)) {} |
| 40 | virtual ~Lattice() = default; |
| 41 | |
| 42 | //!\name Inspectors |
| 43 | //{ |
| 44 | const TimeGrid& timeGrid() const { return t_; } |
| 45 | //@} |
| 46 | |
| 47 | /*! \name Numerical method interface |
| 48 | |
| 49 | These methods are to be used by discretized assets and |
| 50 | must be overridden by developers implementing numerical |
| 51 | methods. Users are advised to use the corresponding |
| 52 | methods of DiscretizedAsset instead. |
| 53 | |
| 54 | @{ |
| 55 | */ |
| 56 | |
| 57 | //! initialize an asset at the given time. |
| 58 | virtual void initialize(DiscretizedAsset&, |
| 59 | Time time) const = 0; |
| 60 | |
| 61 | /*! Roll back an asset until the given time, performing any |
| 62 | needed adjustment. |
| 63 | */ |
| 64 | virtual void rollback(DiscretizedAsset&, |
| 65 | Time to) const = 0; |
| 66 | |
| 67 | /*! Roll back an asset until the given time, but do not perform |
| 68 | the final adjustment. |
| 69 | |
| 70 | \warning In version 0.3.7 and earlier, this method was |
| 71 | called rollAlmostBack method and performed |
| 72 | pre-adjustment. This is no longer true; when |
| 73 | migrating your code, you'll have to replace calls |
| 74 | such as: |
| 75 | \code |
| 76 | method->rollAlmostBack(asset,t); |
| 77 | \endcode |
| 78 | with the two statements: |
| 79 | \code |
| 80 | method->partialRollback(asset,t); |
| 81 | asset->preAdjustValues(); |
| 82 | \endcode |
| 83 | */ |
| 84 | virtual void partialRollback(DiscretizedAsset&, |
| 85 | Time to) const = 0; |
| 86 | |
| 87 | //! computes the present value of an asset. |
| 88 | virtual Real presentValue(DiscretizedAsset&) const = 0; |
| 89 | |
| 90 | //@} |
| 91 | |
| 92 | // this is a smell, but we need it. We'll rethink it later. |
| 93 | virtual Array grid(Time) const = 0; |
| 94 | protected: |
| 95 | TimeGrid t_; |
| 96 | }; |
| 97 | |
| 98 | } |
| 99 | |
| 100 | |
| 101 | #endif |
| 102 | |