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