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) 2003, 2004, 2005, 2006, 2007, 2009 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 cashflow.hpp
22 \brief Base class for cash flows
23*/
24
25#ifndef quantlib_cash_flow_hpp
26#define quantlib_cash_flow_hpp
27
28#include <ql/event.hpp>
29#include <ql/math/comparison.hpp>
30#include <ql/optional.hpp>
31#include <ql/patterns/lazyobject.hpp>
32#include <vector>
33
34namespace QuantLib {
35
36 //! Base class for cash flows
37 /*! This class is purely virtual and acts as a base class for the
38 actual cash flow implementations.
39 */
40 class CashFlow : public Event, public LazyObject {
41 public:
42 ~CashFlow() override = default;
43 //! \name Event interface
44 //@{
45 //! \note This is inherited from the event class
46 Date date() const override = 0;
47 //! returns true if an event has already occurred before a date
48 /*! overloads Event::hasOccurred in order to take
49 Settings::includeTodaysCashflows in account
50 */
51 bool hasOccurred(const Date& refDate = Date(),
52 ext::optional<bool> includeRefDate = ext::nullopt) const override;
53 //@}
54 //! \name LazyObject interface
55 //@{
56 void performCalculations() const override {}
57 //@}
58 //! \name CashFlow interface
59 //@{
60 //! returns the amount of the cash flow
61 /*! \note The amount is not discounted, i.e., it is the actual
62 amount paid at the cash flow date.
63 */
64 virtual Real amount() const = 0;
65 //! returns the date that the cash flow trades exCoupon
66 virtual Date exCouponDate() const { return {}; };
67 //! returns true if the cashflow is trading ex-coupon on the refDate
68 bool tradingExCoupon(const Date& refDate = Date()) const;
69
70 //@}
71 //! \name Visitability
72 //@{
73 void accept(AcyclicVisitor&) override;
74 //@}
75 };
76
77 //! Sequence of cash-flows
78 typedef std::vector<ext::shared_ptr<CashFlow> > Leg;
79
80 template <>
81 struct earlier_than<CashFlow> {
82 /*! \deprecated Use `auto` or `decltype` instead.
83 Deprecated in version 1.29.
84 */
85 QL_DEPRECATED
86 typedef CashFlow first_argument_type;
87
88 /*! \deprecated Use `auto` or `decltype` instead.
89 Deprecated in version 1.29.
90 */
91 QL_DEPRECATED
92 typedef CashFlow second_argument_type;
93
94 /*! \deprecated Use `auto` or `decltype` instead.
95 Deprecated in version 1.29.
96 */
97 QL_DEPRECATED
98 typedef bool result_type;
99
100 bool operator()(const CashFlow& c1,
101 const CashFlow& c2) const {
102 return c1.date() < c2.date();
103 }
104 };
105
106}
107
108#endif
109

source code of quantlib/ql/cashflow.hpp