QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
thirty360.hpp
Go to the documentation of this file.
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 <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 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
29
30namespace 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:
87 NASD
88 };
89 private:
91 public:
92 Time yearFraction(const Date& d1, const Date& d2,
93 const Date&, const Date&) const override {
94 return dayCount(d1,d2)/360.0;
95 }
96 };
97 class US_Impl final : public Thirty360_Impl {
98 public:
99 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 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 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 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 : terminationDate_(terminationDate) {}
121 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:
125 };
126 class NASD_Impl final : public Thirty360_Impl {
127 public:
128 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 : DayCounter(implementation(c, terminationDate)) {}
136 };
137
138}
139
140#endif
Concrete date class.
Definition: date.hpp:125
std::int_fast32_t serial_type
serial number type
Definition: date.hpp:128
abstract base class for day counter implementations
Definition: daycounter.hpp:47
virtual Date::serial_type dayCount(const Date &d1, const Date &d2) const
to be overloaded by more complex day counters
Definition: daycounter.hpp:52
day counter class
Definition: daycounter.hpp:44
Date::serial_type dayCount(const Date &d1, const Date &d2) const override
to be overloaded by more complex day counters
Definition: thirty360.cpp:84
std::string name() const override
Definition: thirty360.hpp:109
Date::serial_type dayCount(const Date &d1, const Date &d2) const override
to be overloaded by more complex day counters
Definition: thirty360.cpp:111
ISDA_Impl(const Date &terminationDate)
Definition: thirty360.hpp:119
std::string name() const override
Definition: thirty360.hpp:121
Date::serial_type dayCount(const Date &d1, const Date &d2) const override
to be overloaded by more complex day counters
Definition: thirty360.cpp:72
std::string name() const override
Definition: thirty360.hpp:104
Date::serial_type dayCount(const Date &d1, const Date &d2) const override
to be overloaded by more complex day counters
Definition: thirty360.cpp:96
std::string name() const override
Definition: thirty360.hpp:114
Date::serial_type dayCount(const Date &d1, const Date &d2) const override
to be overloaded by more complex day counters
Definition: thirty360.cpp:127
std::string name() const override
Definition: thirty360.hpp:128
Time yearFraction(const Date &d1, const Date &d2, const Date &, const Date &) const override
Definition: thirty360.hpp:92
Date::serial_type dayCount(const Date &d1, const Date &d2) const override
to be overloaded by more complex day counters
Definition: thirty360.cpp:57
std::string name() const override
Definition: thirty360.hpp:99
30/360 day count convention
Definition: thirty360.hpp:76
static ext::shared_ptr< DayCounter::Impl > implementation(Convention c, const Date &terminationDate)
Definition: thirty360.cpp:35
Thirty360(Convention c, const Date &terminationDate=Date())
Definition: thirty360.hpp:134
day counter class
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
Definition: any.hpp:35