Coverage Report

Created: 2025-10-14 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/time/daycounters/thirty360.hpp
Line
Count
Source
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) 2018 Alexey Indiryakov
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 thirty360.hpp
22
    \brief 30/360 day counters
23
*/
24
25
#ifndef quantlib_thirty360_day_counter_h
26
#define quantlib_thirty360_day_counter_h
27
28
#include <ql/time/daycounter.hpp>
29
30
namespace QuantLib {
31
32
    //! 30/360 day count convention
33
    /*! The 30/360 day count can be calculated according to a
34
        number of conventions.
35
36
        US convention: if the starting date is the 31st of a month or
37
        the last day of February, it becomes equal to the 30th of the
38
        same month.  If the ending date is the 31st of a month and the
39
        starting date is the 30th or 31th of a month, the ending date
40
        becomes equal to the 30th.  If the ending date is the last of
41
        February and the starting date is also the last of February,
42
        the ending date becomes equal to the 30th.
43
        Also known as "30/360" or "360/360".
44
45
        Bond Basis convention: if the starting date is the 31st of a
46
        month, it becomes equal to the 30th of the same month.
47
        If the ending date is the 31st of a month and the starting
48
        date is the 30th or 31th of a month, the ending date
49
        also becomes equal to the 30th of the month.
50
        Also known as "US (ISMA)".
51
52
        European convention: starting dates or ending dates that
53
        occur on the 31st of a month become equal to the 30th of the
54
        same month.
55
        Also known as "30E/360", or "Eurobond Basis".
56
57
        Italian convention: starting dates or ending dates that
58
        occur on February and are greater than 27 become equal to 30
59
        for computational sake.
60
61
        ISDA convention: starting or ending dates on the 31st of the
62
        month become equal to 30; starting dates or ending dates that
63
        occur on the last day of February also become equal to 30,
64
        except for the termination date.  Also known as "30E/360
65
        ISDA", "30/360 ISDA", or "30/360 German".
66
67
        NASD convention: if the starting date is the 31st of a
68
        month, it becomes equal to the 30th of the same month.
69
        If the ending date is the 31st of a month and the starting
70
        date is earlier than the 30th of a month, the ending date
71
        becomes equal to the 1st of the next month, otherwise the
72
        ending date becomes equal to the 30th of the same month.
73
74
        \ingroup daycounters
75
    */
76
    class Thirty360 : public DayCounter {
77
      public:
78
        enum Convention {
79
            USA,
80
            BondBasis,
81
            European,
82
            EurobondBasis,
83
            Italian,
84
            German,
85
            ISMA,
86
            ISDA,
87
            NASD
88
        };
89
      private:
90
        class Thirty360_Impl : public DayCounter::Impl {
91
          public:
92
            Time yearFraction(const Date& d1, const Date& d2,
93
0
                              const Date&, const Date&) const override {
94
0
                return dayCount(d1,d2)/360.0;
95
0
            }
96
        };
97
        class US_Impl final : public Thirty360_Impl {
98
          public:
99
0
            std::string name() const override { return std::string("30/360 (US)"); }
100
            Date::serial_type dayCount(const Date& d1, const Date& d2) const override;
101
        };
102
        class ISMA_Impl final : public Thirty360_Impl {
103
          public:
104
0
            std::string name() const override { return std::string("30/360 (Bond Basis)"); }
105
            Date::serial_type dayCount(const Date& d1, const Date& d2) const override;
106
        };
107
        class EU_Impl final : public Thirty360_Impl {
108
          public:
109
0
            std::string name() const override { return std::string("30E/360 (Eurobond Basis)"); }
110
            Date::serial_type dayCount(const Date& d1, const Date& d2) const override;
111
        };
112
        class IT_Impl final : public Thirty360_Impl {
113
          public:
114
0
            std::string name() const override { return std::string("30/360 (Italian)"); }
115
            Date::serial_type dayCount(const Date& d1, const Date& d2) const override;
116
        };
117
        class ISDA_Impl final : public Thirty360_Impl {
118
          public:
119
            explicit ISDA_Impl(const Date& terminationDate)
120
0
            : terminationDate_(terminationDate) {}
121
0
            std::string name() const override { return std::string("30E/360 (ISDA)"); }
122
            Date::serial_type dayCount(const Date& d1, const Date& d2) const override;
123
          private:
124
            Date terminationDate_;
125
        };
126
        class NASD_Impl final : public Thirty360_Impl {
127
          public:
128
0
            std::string name() const override { return std::string("30/360 (NASD)"); }
129
            Date::serial_type dayCount(const Date& d1, const Date& d2) const override;
130
        };
131
        static ext::shared_ptr<DayCounter::Impl>
132
        implementation(Convention c, const Date& terminationDate);
133
      public:
134
        explicit Thirty360(Convention c, const Date& terminationDate = Date())
135
6
        : DayCounter(implementation(c, terminationDate)) {}
136
    };
137
138
}
139
140
#endif