QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
cashflow.hpp
Go to the documentation of this file.
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>
30#include <ql/optional.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 <>
82 bool operator()(const CashFlow& c1,
83 const CashFlow& c2) const {
84 return c1.date() < c2.date();
85 }
86 };
87
88}
89
90#endif
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Base class for cash flows.
Definition: cashflow.hpp:40
bool hasOccurred(const Date &refDate=Date(), ext::optional< bool > includeRefDate=ext::nullopt) const override
returns true if an event has already occurred before a date
Definition: cashflow.cpp:27
void performCalculations() const override
Definition: cashflow.hpp:56
virtual Date exCouponDate() const
returns the date that the cash flow trades exCoupon
Definition: cashflow.hpp:66
bool tradingExCoupon(const Date &refDate=Date()) const
returns true if the cashflow is trading ex-coupon on the refDate
Definition: cashflow.cpp:51
void accept(AcyclicVisitor &) override
Definition: cashflow.cpp:63
Date date() const override=0
virtual Real amount() const =0
returns the amount of the cash flow
~CashFlow() override=default
Concrete date class.
Definition: date.hpp:125
Base class for event.
Definition: event.hpp:40
Framework for calculation on demand and result caching.
Definition: lazyobject.hpp:35
floating-point comparisons
Base class for events associated with a given date.
QL_REAL Real
real number
Definition: types.hpp:50
framework for calculation on demand and result caching
const boost::none_t & nullopt
Definition: optional.cpp:27
Definition: any.hpp:35
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
Maps optional to either the boost or std implementation.
bool operator()(const CashFlow &c1, const CashFlow &c2) const
Definition: cashflow.hpp:82
compare two objects by date
Definition: comparison.hpp:130