Coverage Report

Created: 2025-08-05 06:45

/src/quantlib/ql/cashflows/coupon.hpp
Line
Count
Source (jump to first uncovered line)
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, 2007 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 coupon.hpp
22
    \brief Coupon accruing over a fixed period
23
*/
24
25
#ifndef quantlib_coupon_hpp
26
#define quantlib_coupon_hpp
27
28
#include <ql/cashflow.hpp>
29
30
namespace QuantLib {
31
32
    class DayCounter;
33
34
    //! %coupon accruing over a fixed period
35
    /*! This class implements part of the CashFlow interface but it is
36
        still abstract and provides derived classes with methods for
37
        accrual period calculations.
38
    */
39
    class Coupon : public CashFlow {
40
      public:
41
        /*! \warning the coupon does not adjust the payment date which
42
                     must already be a business day.
43
        */
44
        Coupon(const Date& paymentDate,
45
               Real nominal,
46
               const Date& accrualStartDate,
47
               const Date& accrualEndDate,
48
               const Date& refPeriodStart = Date(),
49
               const Date& refPeriodEnd = Date(),
50
               const Date& exCouponDate = Date());
51
        //! \name Event interface
52
        //@{
53
302M
        Date date() const override { return paymentDate_; }
54
        //@}
55
        //! \name CashFlow interface
56
        //@{
57
0
        Date exCouponDate() const override { return exCouponDate_; }
58
        //@}
59
        //! \name Inspectors
60
        //@{
61
        virtual Real nominal() const;
62
        //! start of the accrual period
63
        const Date& accrualStartDate() const;
64
        //! end of the accrual period
65
        const Date& accrualEndDate() const;
66
        //! start date of the reference period
67
        const Date& referencePeriodStart() const;
68
        //! end date of the reference period
69
        const Date& referencePeriodEnd() const;
70
        //! accrual period as fraction of year
71
        Time accrualPeriod() const;
72
        //! accrual period in days
73
        Date::serial_type accrualDays() const;
74
        //! accrued rate
75
        virtual Rate rate() const = 0;
76
        //! day counter for accrual calculation
77
        virtual DayCounter dayCounter() const = 0;
78
        //! accrued period as fraction of year at the given date
79
        Time accruedPeriod(const Date&) const;
80
        //! accrued days at the given date
81
        Date::serial_type accruedDays(const Date&) const;
82
        //! accrued amount at the given date
83
        virtual Real accruedAmount(const Date&) const = 0;
84
        //@}
85
        //! \name Visitability
86
        //@{
87
        void accept(AcyclicVisitor&) override;
88
        //@}
89
      protected:
90
        Date paymentDate_;
91
        Real nominal_;
92
        Date accrualStartDate_,accrualEndDate_, refPeriodStart_,refPeriodEnd_;
93
        Date exCouponDate_;
94
        mutable Real accrualPeriod_;
95
    };
96
97
98
    // inline definitions
99
100
86.1M
    inline Real Coupon::nominal() const {
101
86.1M
        return nominal_;
102
86.1M
    }
103
104
0
    inline const Date& Coupon::accrualStartDate() const {
105
0
        return accrualStartDate_;
106
0
    }
107
108
0
    inline const Date& Coupon::accrualEndDate() const {
109
0
        return accrualEndDate_;
110
0
    }
111
112
0
    inline const Date& Coupon::referencePeriodStart() const {
113
0
        return refPeriodStart_;
114
0
    }
115
116
0
    inline const Date& Coupon::referencePeriodEnd() const {
117
0
        return refPeriodEnd_;
118
0
    }
119
120
}
121
122
#endif