BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bbldc_terminatedisda30360eom.h
Go to the documentation of this file.
1/// @file bbldc_terminatedisda30360eom.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bbldc_terminatedisda30360eom.h -*-C++-*-
8#ifndef INCLUDED_BBLDC_TERMINATEDISDA30360EOM
9#define INCLUDED_BBLDC_TERMINATEDISDA30360EOM
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bbldc_terminatedisda30360eom bbldc_terminatedisda30360eom
15/// @brief Provide stateless functions for ISDA 30/360 eom convention.
16/// @addtogroup bbl
17/// @{
18/// @addtogroup bbldc
19/// @{
20/// @addtogroup bbldc_terminatedisda30360eom
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bbldc_terminatedisda30360eom-purpose"> Purpose</a>
25/// * <a href="#bbldc_terminatedisda30360eom-classes"> Classes </a>
26/// * <a href="#bbldc_terminatedisda30360eom-description"> Description </a>
27/// * <a href="#bbldc_terminatedisda30360eom-isda-30360-eom-day-count-algorithm"> ISDA 30360 eom Day Count Algorithm </a>
28/// * <a href="#bbldc_terminatedisda30360eom-usage"> Usage </a>
29/// * <a href="#bbldc_terminatedisda30360eom-example-1-computing-day-count-and-year-fraction"> Example 1: Computing Day Count and Year Fraction </a>
30///
31/// # Purpose {#bbldc_terminatedisda30360eom-purpose}
32/// Provide stateless functions for ISDA 30/360 eom convention.
33///
34/// # Classes {#bbldc_terminatedisda30360eom-classes}
35///
36/// - bbldc::TerminatedIsda30360Eom: ISDA 30/360 eom stateless functions
37///
38/// # Description {#bbldc_terminatedisda30360eom-description}
39/// This component provides a `struct`,
40/// `bbldc::TerminatedIsda30360Eom`, that serves as a namespace for defining a
41/// suite of date-related functions used to compute the day count and year
42/// fraction between two dates as prescribed by the International Swaps and
43/// Derivatives Association (ISDA) 30/360 day-count convention with end-of-month
44/// (eom) adjustments. In this day-count convention (also known as "30E/360
45/// ISDA"), each year is assumed to have 12 months and 360 days, with each month
46/// consisting of exactly 30 days. Special end-of-month rule adjustments *are*
47/// made to account for the last day of February. Note that in this day-count
48/// convention, the second date may or may not be adjusted depending on the
49/// termination date (e.g., maturity date).
50///
51/// ## ISDA 30360 eom Day Count Algorithm {#bbldc_terminatedisda30360eom-isda-30360-eom-day-count-algorithm}
52///
53///
54/// Given `beginDate` and `endDate`, let:
55/// @code
56/// Ye = year of earlier date Yl = year of later date
57/// Me = month of earlier date Ml = month of later date
58/// De = day of earlier date Dl = day of later date
59///
60/// o If Dl is the last day of the month, unless Dl is the termination date
61/// and is in February, change Dl to 30.
62///
63/// o If De is the last day of the month, change De to 30.
64///
65/// daysDiff ::= sign(endDate - beginDate) *
66/// (Yl - Ye) * 360 + (Ml - Me) * 30 + Dl - De
67/// @endcode
68/// Reference: http://www.isda.org/c_and_a/docs/30-360-2006ISDADefs.xls
69/// (tab labeled "30E-360 ISDA")
70///
71/// The year fraction is simply the day count divided by 360.
72///
73/// ## Usage {#bbldc_terminatedisda30360eom-usage}
74///
75///
76/// This section illustrates intended use of this component.
77///
78/// ### Example 1: Computing Day Count and Year Fraction {#bbldc_terminatedisda30360eom-example-1-computing-day-count-and-year-fraction}
79///
80///
81/// The following snippets of code illustrate how to use
82/// `bbldc::TerminatedIsda30360Eom` methods. First, create two `bdlt::Date`
83/// variables, `d1` and `d2`:
84/// @code
85/// const bdlt::Date d1(2004, 9, 30);
86/// const bdlt::Date d2(2004, 12, 31);
87/// @endcode
88/// Then, compute the day count between the two dates:
89/// @code
90/// const int daysDiff = bbldc::TerminatedIsda30360Eom::daysDiff(d1, d2);
91/// assert(90 == daysDiff);
92/// @endcode
93/// Finally, compute the year fraction between the two dates:
94/// @code
95/// const double yearsDiff = bbldc::TerminatedIsda30360Eom::yearsDiff(d1, d2);
96/// assert(0.25 == yearsDiff);
97/// @endcode
98/// @}
99/** @} */
100/** @} */
101
102/** @addtogroup bbl
103 * @{
104 */
105/** @addtogroup bbldc
106 * @{
107 */
108/** @addtogroup bbldc_terminatedisda30360eom
109 * @{
110 */
111
112#include <bblscm_version.h>
113
114#include <bdlt_date.h>
115
116#include <bsls_platform.h>
117
118
119namespace bbldc {
120
121 // =============================
122 // struct TerminatedIsda30360Eom
123 // =============================
124
125/// This `struct` provides a namespace for a suite of pure functions that
126/// compute values based on dates according to the ISDA 30/360 end-of-month
127/// day-count convention.
129
130 // CLASS METHODS
131
132 /// Return the (signed) number of days between the specified `beginDate`
133 /// and `endDate`, with the optionally specified `terminationDate`,
134 /// according to the ISDA 30/360 end-of-month day-count convention. If
135 /// `beginDate <= endDate`, then the result is non-negative. Note that
136 /// reversing the order of `beginDate` and `endDate` negates the result.
137 /// Also note that, in accordance with the convention definition, there
138 /// are no constraints upon the supplied dates.
139 static int daysDiff(const bdlt::Date& beginDate,
140 const bdlt::Date& endDate,
141 const bdlt::Date& terminationDate = bdlt::Date());
142
143 /// Return the (signed fractional) number of years between the specified
144 /// `beginDate` and `endDate`, with the optionally specified
145 /// `terminationDate`, according to the ISDA 30/360 end-of-month
146 /// day-count convention. If `beginDate <= endDate`, then the result is
147 /// non-negative. Note that reversing the order of `beginDate` and
148 /// `endDate` negates the result; specifically,
149 /// `|yearsDiff(b, e) + yearsDiff(e, b)| <= 1.0e-15` for all dates `b`
150 /// and `e`. Also note that, in accordance with the convention
151 /// definition, there are no constraints upon the supplied dates.
152 static double yearsDiff(const bdlt::Date& beginDate,
153 const bdlt::Date& endDate,
154 const bdlt::Date& terminationDate
155 = bdlt::Date(9999, 12, 31));
156};
157
158// ============================================================================
159// INLINE DEFINITIONS
160// ============================================================================
161
162 // -----------------------------
163 // struct TerminatedIsda30360Eom
164 // -----------------------------
165
166// CLASS METHODS
167inline
169 const bdlt::Date& endDate,
170 const bdlt::Date& terminationDate)
171{
172#if defined(BSLS_PLATFORM_CMP_GNU) && (BSLS_PLATFORM_CMP_VERSION >= 50301)
173 // Storing the result value in a 'volatile double' removes extra-precision
174 // available in floating-point registers.
175
176 const volatile double rv =
177#else
178 const double rv =
179#endif
180 static_cast<double>(daysDiff(beginDate,
181 endDate,
182 terminationDate)) / 360.0;
183
184 return rv;
185}
186
187} // close package namespace
188
189
190#endif
191
192// ----------------------------------------------------------------------------
193// Copyright 2017 Bloomberg Finance L.P.
194//
195// Licensed under the Apache License, Version 2.0 (the "License");
196// you may not use this file except in compliance with the License.
197// You may obtain a copy of the License at
198//
199// http://www.apache.org/licenses/LICENSE-2.0
200//
201// Unless required by applicable law or agreed to in writing, software
202// distributed under the License is distributed on an "AS IS" BASIS,
203// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
204// See the License for the specific language governing permissions and
205// limitations under the License.
206// ----------------------------- END-OF-FILE ----------------------------------
207
208/** @} */
209/** @} */
210/** @} */
Definition bdlt_date.h:294
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bbldc_basicactual360.h:107
Definition bbldc_terminatedisda30360eom.h:128
static int daysDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate, const bdlt::Date &terminationDate=bdlt::Date())
static double yearsDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate, const bdlt::Date &terminationDate=bdlt::Date(9999, 12, 31))
Definition bbldc_terminatedisda30360eom.h:168