/src/quantlib/ql/cashflows/simplecashflow.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) 2000, 2001, 2002, 2003 RiskMap srl |
5 | | Copyright (C) 2010 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 simplecashflow.hpp |
22 | | \brief Predetermined cash flow |
23 | | */ |
24 | | |
25 | | #ifndef quantlib_simple_cash_flow_hpp |
26 | | #define quantlib_simple_cash_flow_hpp |
27 | | |
28 | | #include <ql/patterns/visitor.hpp> |
29 | | #include <ql/cashflow.hpp> |
30 | | |
31 | | namespace QuantLib { |
32 | | |
33 | | //! Predetermined cash flow |
34 | | /*! This cash flow pays a predetermined amount at a given date. */ |
35 | | class SimpleCashFlow : public CashFlow { |
36 | | public: |
37 | | SimpleCashFlow(Real amount, |
38 | | const Date& date); |
39 | | //! \name Event interface |
40 | | //@{ |
41 | 274M | Date date() const override { return date_; } |
42 | | //@} |
43 | | //! \name CashFlow interface |
44 | | //@{ |
45 | 28.8M | Real amount() const override { return amount_; } |
46 | | //@} |
47 | | //! \name Visitability |
48 | | //@{ |
49 | | void accept(AcyclicVisitor&) override; |
50 | | //@} |
51 | | private: |
52 | | Real amount_; |
53 | | Date date_; |
54 | | }; |
55 | | |
56 | | |
57 | | //! Bond redemption |
58 | | /*! This class specializes SimpleCashFlow so that visitors |
59 | | can perform more detailed cash-flow analysis. |
60 | | */ |
61 | | class Redemption : public SimpleCashFlow { |
62 | | public: |
63 | | Redemption(Real amount, |
64 | | const Date& date) |
65 | 80.0k | : SimpleCashFlow(amount, date) {} |
66 | | //! \name Visitability |
67 | | //@{ |
68 | | void accept(AcyclicVisitor&) override; |
69 | | //@} |
70 | | }; |
71 | | |
72 | | //! Amortizing payment |
73 | | /*! This class specializes SimpleCashFlow so that visitors |
74 | | can perform more detailed cash-flow analysis. |
75 | | */ |
76 | | class AmortizingPayment : public SimpleCashFlow { |
77 | | public: |
78 | | AmortizingPayment(Real amount, |
79 | | const Date& date) |
80 | 28.7M | : SimpleCashFlow(amount, date) {} |
81 | | //! \name Visitability |
82 | | //@{ |
83 | | void accept(AcyclicVisitor&) override; |
84 | | //@} |
85 | | }; |
86 | | |
87 | | |
88 | | // inline definitions |
89 | | |
90 | 0 | inline void SimpleCashFlow::accept(AcyclicVisitor& v) { |
91 | 0 | auto* v1 = dynamic_cast<Visitor<SimpleCashFlow>*>(&v); |
92 | 0 | if (v1 != nullptr) |
93 | 0 | v1->visit(*this); |
94 | 0 | else |
95 | 0 | CashFlow::accept(v); |
96 | 0 | } |
97 | | |
98 | 0 | inline void Redemption::accept(AcyclicVisitor& v) { |
99 | 0 | auto* v1 = dynamic_cast<Visitor<Redemption>*>(&v); |
100 | 0 | if (v1 != nullptr) |
101 | 0 | v1->visit(*this); |
102 | 0 | else |
103 | 0 | SimpleCashFlow::accept(v); |
104 | 0 | } |
105 | | |
106 | 0 | inline void AmortizingPayment::accept(AcyclicVisitor& v) { |
107 | 0 | auto* v1 = dynamic_cast<Visitor<AmortizingPayment>*>(&v); |
108 | 0 | if (v1 != nullptr) |
109 | 0 | v1->visit(*this); |
110 | 0 | else |
111 | 0 | SimpleCashFlow::accept(v); |
112 | 0 | } |
113 | | |
114 | | } |
115 | | |
116 | | #endif |