Coverage Report

Created: 2025-12-08 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/cashflows/dividend.hpp
Line
Count
Source
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
 <https://www.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:
38
        Dividend(const Date& date)
39
0
        : date_(date) {}
40
        //! \name Event interface
41
        //@{
42
0
        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:
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:
61
        FixedDividend(Real amount, const Date& date)
62
0
        : Dividend(date), amount_(amount) {}
63
        //! \name Dividend interface
64
        //@{
65
0
        Real amount() const override { return amount_; }
66
0
        Real amount(Real) const override { 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:
76
        FractionalDividend(Real rate, const Date& date)
77
0
        : Dividend(date), rate_(rate), nominal_(Null<Real>()) {}
78
79
        FractionalDividend(Real rate, Real nominal, const Date& date)
80
0
        : Dividend(date), rate_(rate), nominal_(nominal) {}
81
        //! \name Dividend interface
82
        //@{
83
0
        Real amount() const override {
84
0
            QL_REQUIRE(nominal_ != Null<Real>(), "no nominal given");
85
0
            return rate_ * nominal_;
86
0
        }
87
0
        Real amount(Real underlying) const override { return rate_ * underlying; }
88
        //@}
89
        //! \name Inspectors
90
        //@{
91
0
        Real rate() const { return rate_; }
92
0
        Real nominal() const { return nominal_; }
93
        //@}
94
      protected:
95
        Real rate_;
96
        Real nominal_;
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