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