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