BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bbldc_basicisma30360.h
Go to the documentation of this file.
1/// @file bbldc_basicisma30360.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bbldc_basicisma30360.h -*-C++-*-
8#ifndef INCLUDED_BBLDC_BASICISMA30360
9#define INCLUDED_BBLDC_BASICISMA30360
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bbldc_basicisma30360 bbldc_basicisma30360
15/// @brief Provide stateless functions for the ISMA 30/360 convention.
16/// @addtogroup bbl
17/// @{
18/// @addtogroup bbldc
19/// @{
20/// @addtogroup bbldc_basicisma30360
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bbldc_basicisma30360-purpose"> Purpose</a>
25/// * <a href="#bbldc_basicisma30360-classes"> Classes </a>
26/// * <a href="#bbldc_basicisma30360-description"> Description </a>
27/// * <a href="#bbldc_basicisma30360-isma-30360-day-count-algorithm"> ISMA 30360 Day Count Algorithm </a>
28/// * <a href="#bbldc_basicisma30360-usage"> Usage </a>
29/// * <a href="#bbldc_basicisma30360-example-1-computing-day-count-and-year-fraction"> Example 1: Computing Day Count and Year Fraction </a>
30///
31/// # Purpose {#bbldc_basicisma30360-purpose}
32/// Provide stateless functions for the ISMA 30/360 convention.
33///
34/// # Classes {#bbldc_basicisma30360-classes}
35///
36/// - bbldc::BasicIsma30360: ISMA 30/360 convention stateless functions
37///
38/// # Description {#bbldc_basicisma30360-description}
39/// This component provides a `struct`, `bbldc::BasicIsma30360`,
40/// that serves as a namespace for defining a suite of date-related functions
41/// used to compute the day count and year fraction between two dates as per the
42/// ISMA 30/360 day-count convention. In this day-count convention (also known
43/// as "European 30/360"), each year is assumed to have 12 months and 360 days,
44/// with each month consisting of exactly 30 days. End-of-month rule
45/// adjustments are *not* made to account for the last day of February.
46///
47/// ## ISMA 30360 Day Count Algorithm {#bbldc_basicisma30360-isma-30360-day-count-algorithm}
48///
49///
50/// Given `beginDate` and `endDate`, let:
51/// @code
52/// Ye = year of earlier date Yl = year of later date
53/// Me = month of earlier date Ml = month of later date
54/// De = day of earlier date Dl = day of later date
55///
56/// o If De is 31, change De to 30.
57///
58/// o If Dl is 31, change Dl to 30.
59///
60/// daysDiff ::= sign(endDate - beginDate) *
61/// (Yl - Ye) * 360 + (Ml - Me) * 30 + Dl - De
62/// @endcode
63/// Reference: Formulae For Yield And Other Calculations (1992)
64/// ISBN: 0-9515474-0-2
65///
66/// Note that in this day-count convention, dates (`De` and `Dl`) are adjusted
67/// independently of each other.
68///
69/// The year fraction is simply the day count divided by 360.
70///
71/// ## Usage {#bbldc_basicisma30360-usage}
72///
73///
74/// This section illustrates intended use of this component.
75///
76/// ### Example 1: Computing Day Count and Year Fraction {#bbldc_basicisma30360-example-1-computing-day-count-and-year-fraction}
77///
78///
79/// The following snippets of code illustrate how to use `bbldc::BasicIsma30360`
80/// methods. First, create two `bdlt::Date` variables, `d1` and `d2`:
81/// @code
82/// const bdlt::Date d1(2004, 9, 30);
83/// const bdlt::Date d2(2004, 12, 31);
84/// @endcode
85/// Then, compute the day count between the two dates:
86/// @code
87/// const int daysDiff = bbldc::BasicIsma30360::daysDiff(d1, d2);
88/// assert(90 == daysDiff);
89/// @endcode
90/// Finally, compute the year fraction between the two dates:
91/// @code
92/// const double yearsDiff = bbldc::BasicIsma30360::yearsDiff(d1, d2);
93/// assert(0.25 == yearsDiff);
94/// @endcode
95/// @}
96/** @} */
97/** @} */
98
99/** @addtogroup bbl
100 * @{
101 */
102/** @addtogroup bbldc
103 * @{
104 */
105/** @addtogroup bbldc_basicisma30360
106 * @{
107 */
108
109#include <bblscm_version.h>
110
111
112namespace bdlt {
113
114class Date;
115
116} // close namespace bdlt
117
118namespace bbldc {
119
120 // =====================
121 // struct BasicIsma30360
122 // =====================
123
124/// This `struct` provides a namespace for a suite of pure functions that
125/// compute values based on dates according to the ISMA 30/360 day-count
126/// convention.
128
129 // CLASS METHODS
130
131 /// Return the (signed) number of days between the specified `beginDate`
132 /// and `endDate` according to the ISMA 30/360 day-count convention. If
133 /// `beginDate <= endDate`, then the result is non-negative. Note that
134 /// reversing the order of `beginDate` and `endDate` negates the result.
135 static int daysDiff(const bdlt::Date& beginDate,
136 const bdlt::Date& endDate);
137
138 /// Return the (signed fractional) number of years between the specified
139 /// `beginDate` and `endDate` according to the ISMA 30/360 day-count
140 /// convention. If `beginDate <= endDate`, then the result is
141 /// non-negative. Note that reversing the order of `beginDate` and
142 /// `endDate` negates the result; specifically,
143 /// `|yearsDiff(b, e) + yearsDiff(e, b)| <= 1.0e-15` for all dates `b`
144 /// and `e`.
145 static double yearsDiff(const bdlt::Date& beginDate,
146 const bdlt::Date& endDate);
147};
148
149} // close package namespace
150
151
152#endif
153
154// ----------------------------------------------------------------------------
155// Copyright 2015 Bloomberg Finance L.P.
156//
157// Licensed under the Apache License, Version 2.0 (the "License");
158// you may not use this file except in compliance with the License.
159// You may obtain a copy of the License at
160//
161// http://www.apache.org/licenses/LICENSE-2.0
162//
163// Unless required by applicable law or agreed to in writing, software
164// distributed under the License is distributed on an "AS IS" BASIS,
165// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
166// See the License for the specific language governing permissions and
167// limitations under the License.
168// ----------------------------- END-OF-FILE ----------------------------------
169
170/** @} */
171/** @} */
172/** @} */
Definition bdlt_date.h:294
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bbldc_basicactual360.h:107
Definition bbldc_basicisma30360.h:112
Definition bbldc_basicisma30360.h:127
static int daysDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate)
static double yearsDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate)