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