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 
32 namespace 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:
Dividend(const Date & date)38         Dividend(const Date& date)
39         : date_(date) {}
40         //! \name Event interface
41         //@{
date() const42         Date date() const { return date_; }
43         //@}
44         //! \name CashFlow interface
45         //@{
46         virtual Real amount() const = 0;
47         //@}
48         virtual Real amount(Real underlying) const = 0;
49         //! \name Visitability
50         //@{
51         virtual void accept(AcyclicVisitor&);
52         //@}
53       protected:
54         Date date_;
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:
FixedDividend(Real amount,const Date & date)61         FixedDividend(Real amount, const Date& date)
62         : Dividend(date), amount_(amount) {}
63         //! \name Dividend interface
64         //@{
amount() const65         virtual Real amount() const { return amount_; }
amount(Real) const66         virtual Real amount(Real) const { return amount_; }
67         //@}
68       protected:
69         Real amount_;
70     };
71 
72     //! Predetermined cash flow
73     /*! This cash flow pays a fractional amount at a given date. */
74     class FractionalDividend : public Dividend {
75       public:
FractionalDividend(Real rate,const Date & date)76         FractionalDividend(Real rate, const Date& date)
77         : Dividend(date), rate_(rate), nominal_(Null<Real>()) {}
78 
FractionalDividend(Real rate,Real nominal,const Date & date)79         FractionalDividend(Real rate, Real nominal, const Date& date)
80         : Dividend(date), rate_(rate), nominal_(nominal) {}
81         //! \name Dividend interface
82         //@{
amount() const83         virtual Real amount() const {
84             QL_REQUIRE(nominal_ != Null<Real>(), "no nominal given");
85             return rate_ * nominal_;
86         }
amount(Real underlying) const87         virtual Real amount(Real underlying) const {
88             return rate_ * underlying;
89         }
90         //@}
91         //! \name Inspectors
92         //@{
rate() const93         Real rate() const { return rate_; }
nominal() const94         Real nominal() const { return nominal_; }
95         //@}
96       protected:
97         Real rate_;
98         Real nominal_;
99     };
100 
101 
102     //! helper function building a sequence of fixed dividends
103     std::vector<ext::shared_ptr<Dividend> >
104     DividendVector(const std::vector<Date>& dividendDates,
105                    const std::vector<Real>& dividends);
106 
107 }
108 
109 
110 #endif
111