Coverage Report

Created: 2025-12-08 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/cashflows/cmscoupon.hpp
Line
Count
Source
1
/*
2
 Copyright (C) 2006 Giorgio Facchinetti
3
 Copyright (C) 2006 Mario Pucci
4
 Copyright (C) 2006, 2007 StatPro Italia srl
5
6
 This file is part of QuantLib, a free-software/open-source library
7
 for financial quantitative analysts and developers - http://quantlib.org/
8
9
 QuantLib is free software: you can redistribute it and/or modify it
10
 under the terms of the QuantLib license.  You should have received a
11
 copy of the license along with this program; if not, please email
12
 <quantlib-dev@lists.sf.net>. The license is also available online at
13
 <https://www.quantlib.org/license.shtml>.
14
15
16
 This program is distributed in the hope that it will be useful, but
17
 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18
 or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */
19
20
/*! \file cmscoupon.hpp
21
    \brief CMS coupon
22
*/
23
24
#ifndef quantlib_cms_coupon_hpp
25
#define quantlib_cms_coupon_hpp
26
27
#include <ql/cashflows/floatingratecoupon.hpp>
28
#include <ql/time/schedule.hpp>
29
30
namespace QuantLib {
31
32
    class SwapIndex;
33
34
    //! CMS coupon class
35
    /*! \warning This class does not perform any date adjustment,
36
                 i.e., the start and end date passed upon construction
37
                 should be already rolled to a business day.
38
    */
39
    class CmsCoupon : public FloatingRateCoupon {
40
      public:
41
        CmsCoupon(const Date& paymentDate,
42
                  Real nominal,
43
                  const Date& startDate,
44
                  const Date& endDate,
45
                  Natural fixingDays,
46
                  const ext::shared_ptr<SwapIndex>& index,
47
                  Real gearing = 1.0,
48
                  Spread spread = 0.0,
49
                  const Date& refPeriodStart = Date(),
50
                  const Date& refPeriodEnd = Date(),
51
                  const DayCounter& dayCounter = DayCounter(),
52
                  bool isInArrears = false,
53
                  const Date& exCouponDate = Date());
54
        //! \name Inspectors
55
        //@{
56
0
        const ext::shared_ptr<SwapIndex>& swapIndex() const {
57
0
            return swapIndex_;
58
0
        }
59
        //@}
60
        //! \name Visitability
61
        //@{
62
        void accept(AcyclicVisitor&) override;
63
        //@}
64
      private:
65
        ext::shared_ptr<SwapIndex> swapIndex_;
66
    };
67
68
69
    //! helper class building a sequence of capped/floored cms-rate coupons
70
    class CmsLeg {
71
      public:
72
        CmsLeg(Schedule schedule, ext::shared_ptr<SwapIndex> swapIndex);
73
        CmsLeg& withNotionals(Real notional);
74
        CmsLeg& withNotionals(const std::vector<Real>& notionals);
75
        CmsLeg& withPaymentDayCounter(const DayCounter&);
76
        CmsLeg& withPaymentAdjustment(BusinessDayConvention);
77
        CmsLeg& withFixingDays(Natural fixingDays);
78
        CmsLeg& withFixingDays(const std::vector<Natural>& fixingDays);
79
        CmsLeg& withGearings(Real gearing);
80
        CmsLeg& withGearings(const std::vector<Real>& gearings);
81
        CmsLeg& withSpreads(Spread spread);
82
        CmsLeg& withSpreads(const std::vector<Spread>& spreads);
83
        CmsLeg& withCaps(Rate cap);
84
        CmsLeg& withCaps(const std::vector<Rate>& caps);
85
        CmsLeg& withFloors(Rate floor);
86
        CmsLeg& withFloors(const std::vector<Rate>& floors);
87
        CmsLeg& inArrears(bool flag = true);
88
        CmsLeg& withZeroPayments(bool flag = true);
89
        CmsLeg& withExCouponPeriod(const Period&,
90
                                   const Calendar&,
91
                                   BusinessDayConvention,
92
                                   bool endOfMonth);
93
        operator Leg() const;
94
      private:
95
        Schedule schedule_;
96
        ext::shared_ptr<SwapIndex> swapIndex_;
97
        std::vector<Real> notionals_;
98
        DayCounter paymentDayCounter_;
99
        BusinessDayConvention paymentAdjustment_ = Following;
100
        std::vector<Natural> fixingDays_;
101
        std::vector<Real> gearings_;
102
        std::vector<Spread> spreads_;
103
        std::vector<Rate> caps_, floors_;
104
        bool inArrears_ = false, zeroPayments_ = false;
105
        Period exCouponPeriod_;
106
        Calendar exCouponCalendar_;
107
        BusinessDayConvention exCouponAdjustment_ = Following;
108
        bool exCouponEndOfMonth_ = false;
109
    };
110
111
}
112
113
#endif