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