QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
dividend.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) 2005 Joseph Wang
5 Copyright (C) 2006 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 dividend.hpp
22 \brief A stock dividend
23*/
24
25#ifndef quantlib_dividend_hpp
26#define quantlib_dividend_hpp
27
28#include <ql/cashflow.hpp>
29#include <ql/utilities/null.hpp>
30#include <vector>
31
32namespace QuantLib {
33
34 //! Predetermined cash flow
35 /*! This cash flow pays a predetermined amount at a given date. */
36 class Dividend : public CashFlow {
37 public:
39 : date_(date) {}
40 //! \name Event interface
41 //@{
42 Date date() const override { return date_; }
43 //@}
44 //! \name CashFlow interface
45 //@{
46 Real amount() const override = 0;
47 //@}
48 virtual Real amount(Real underlying) const = 0;
49 //! \name Visitability
50 //@{
51 void accept(AcyclicVisitor&) override;
52 //@}
53 protected:
55 };
56
57 //! Predetermined cash flow
58 /*! This cash flow pays a predetermined amount at a given date. */
59 class FixedDividend : public Dividend {
60 public:
63 //! \name Dividend interface
64 //@{
65 Real amount() const override { return amount_; }
66 Real amount(Real) const override { return amount_; }
67 //@}
68 protected:
70 };
71
72 //! Predetermined cash flow
73 /*! This cash flow pays a fractional amount at a given date. */
75 public:
78
81 //! \name Dividend interface
82 //@{
83 Real amount() const override {
84 QL_REQUIRE(nominal_ != Null<Real>(), "no nominal given");
85 return rate_ * nominal_;
86 }
87 Real amount(Real underlying) const override { return rate_ * underlying; }
88 //@}
89 //! \name Inspectors
90 //@{
91 Real rate() const { return rate_; }
92 Real nominal() const { return nominal_; }
93 //@}
94 protected:
97 };
98
99
100 //! helper function building a sequence of fixed dividends
101 std::vector<ext::shared_ptr<Dividend> >
102 DividendVector(const std::vector<Date>& dividendDates,
103 const std::vector<Real>& dividends);
104
105}
106
107
108#endif
Base class for cash flows.
degenerate base class for the Acyclic Visitor pattern
Definition: visitor.hpp:33
Base class for cash flows.
Definition: cashflow.hpp:40
Concrete date class.
Definition: date.hpp:125
Predetermined cash flow.
Definition: dividend.hpp:36
Dividend(const Date &date)
Definition: dividend.hpp:38
virtual Real amount(Real underlying) const =0
void accept(AcyclicVisitor &) override
Definition: dividend.cpp:26
Real amount() const override=0
returns the amount of the cash flow
Date date() const override
Definition: dividend.hpp:42
Predetermined cash flow.
Definition: dividend.hpp:59
FixedDividend(Real amount, const Date &date)
Definition: dividend.hpp:61
Real amount() const override
returns the amount of the cash flow
Definition: dividend.hpp:65
Real amount(Real) const override
Definition: dividend.hpp:66
Predetermined cash flow.
Definition: dividend.hpp:74
FractionalDividend(Real rate, const Date &date)
Definition: dividend.hpp:76
Real amount() const override
returns the amount of the cash flow
Definition: dividend.hpp:83
Real amount(Real underlying) const override
Definition: dividend.hpp:87
FractionalDividend(Real rate, Real nominal, const Date &date)
Definition: dividend.hpp:79
template class providing a null value for a given type.
Definition: null.hpp:76
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
std::vector< ext::shared_ptr< Dividend > > DividendVector(const std::vector< Date > &dividendDates, const std::vector< Real > &dividends)
helper function building a sequence of fixed dividends
Definition: dividend.cpp:35
null values