BDE 4.14.0 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.
119
120 // CLASS METHODS
121
122 /// Return the (signed) number of days between the specified `beginDate`
123 /// and `endDate` according to the Actual/365 fixed day-count
124 /// convention. If `beginDate <= endDate`, then the result is
125 /// non-negative. Note that reversing the order of `beginDate` and
126 /// `endDate` negates the result.
127 static int daysDiff(const bdlt::Date& beginDate,
128 const bdlt::Date& endDate);
129
130 /// Return the (signed fractional) number of years between the specified
131 /// `beginDate` and `endDate` according to the Actual/365 fixed
132 /// day-count convention. If `beginDate <= endDate`, then the result is
133 /// non-negative. Note that reversing the order of `beginDate` and
134 /// `endDate` negates the result; specifically,
135 /// `|yearsDiff(b, e) + yearsDiff(e, b)| <= 1.0e-15` for all dates `b`
136 /// and `e`.
137 static double yearsDiff(const bdlt::Date& beginDate,
138 const bdlt::Date& endDate);
139};
140
141// ============================================================================
142// INLINE DEFINITIONS
143// ============================================================================
144
145 // --------------------------
146 // struct BasicActual365Fixed
147 // --------------------------
148
149// CLASS METHODS
150inline
152 const bdlt::Date& endDate)
153{
154 return endDate - beginDate;
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_basicactual365fixed.h:118
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:151