/src/quantlib/ql/experimental/mcbasket/pathpayoff.hpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2008 Andrea Odetti |
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 | | /*! \file pathpayoff.hpp |
21 | | \brief Option payoff classes |
22 | | */ |
23 | | |
24 | | #ifndef quantlib_path_payoff_hpp |
25 | | #define quantlib_path_payoff_hpp |
26 | | |
27 | | #include <ql/math/matrix.hpp> |
28 | | #include <ql/patterns/visitor.hpp> |
29 | | #include <ql/termstructures/yieldtermstructure.hpp> |
30 | | #include <ql/handle.hpp> |
31 | | #include <functional> |
32 | | |
33 | | namespace QuantLib { |
34 | | |
35 | | //! Abstract base class for path-dependent option payoffs |
36 | | class PathPayoff { |
37 | | public: |
38 | 0 | virtual ~PathPayoff() = default; |
39 | | //! \name Payoff interface |
40 | | //@{ |
41 | | /*! \warning This method is used for output and comparison between |
42 | | payoffs. It is <b>not</b> meant to be used for writing |
43 | | switch-on-type code. |
44 | | */ |
45 | | virtual std::string name() const = 0; |
46 | | virtual std::string description() const = 0; |
47 | | |
48 | | |
49 | | /* |
50 | | This function returns all the payoff and early termination payments |
51 | | for a single path. If the option is cancelled at time i, all payments |
52 | | on and before i are taken into account + the value of exercises[i]. |
53 | | i.e.: cancellation at i does not cancel payments[i]! |
54 | | |
55 | | forwardTermStructures contains the yield term structure at each fixing date |
56 | | |
57 | | leave states empty to signal exercise is not possible |
58 | | in that case, exercises[] will not be accessed. |
59 | | */ |
60 | | |
61 | | virtual void value(const Matrix & path, |
62 | | const std::vector<Handle<YieldTermStructure> > & forwardTermStructures, |
63 | | Array & payments, |
64 | | Array & exercises, |
65 | | std::vector<Array> & states) const = 0; |
66 | | |
67 | | /* |
68 | | Dimension of the basis functions. |
69 | | It must be the same as the size of every element of states in value(). |
70 | | */ |
71 | | |
72 | | virtual Size basisSystemDimension() const = 0; |
73 | | |
74 | | //@} |
75 | | //! \name Visitability |
76 | | //@{ |
77 | | virtual void accept(AcyclicVisitor&); |
78 | | //@} |
79 | | }; |
80 | | |
81 | | |
82 | | // inline definitions |
83 | | |
84 | 0 | inline void PathPayoff::accept(AcyclicVisitor& v) { |
85 | 0 | auto* v1 = dynamic_cast<Visitor<PathPayoff>*>(&v); |
86 | 0 | if (v1 != nullptr) |
87 | 0 | v1->visit(*this); |
88 | 0 | else |
89 | | QL_FAIL("not a path-payoff visitor"); |
90 | 0 | } |
91 | | } |
92 | | |
93 | | |
94 | | #endif |