BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bbldc_basicdaycountutil.h
Go to the documentation of this file.
1/// @file bbldc_basicdaycountutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bbldc_basicdaycountutil.h -*-C++-*-
8#ifndef INCLUDED_BBLDC_BASICDAYCOUNTUTIL
9#define INCLUDED_BBLDC_BASICDAYCOUNTUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bbldc_basicdaycountutil bbldc_basicdaycountutil
15/// @brief Support for day-count calculations of `enum`-specified conventions.
16/// @addtogroup bbl
17/// @{
18/// @addtogroup bbldc
19/// @{
20/// @addtogroup bbldc_basicdaycountutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bbldc_basicdaycountutil-purpose"> Purpose</a>
25/// * <a href="#bbldc_basicdaycountutil-classes"> Classes </a>
26/// * <a href="#bbldc_basicdaycountutil-description"> Description </a>
27/// * <a href="#bbldc_basicdaycountutil-usage"> Usage </a>
28/// * <a href="#bbldc_basicdaycountutil-example-1-computing-day-count-and-year-fraction"> Example 1: Computing Day Count and Year Fraction </a>
29///
30/// # Purpose {#bbldc_basicdaycountutil-purpose}
31/// Support for day-count calculations of `enum`-specified conventions.
32///
33/// # Classes {#bbldc_basicdaycountutil-classes}
34///
35/// - bbldc::BasicDayCountUtil: `enum`-specified day-count calculation procedures
36///
37/// @see bbldc_daycountconvention
38///
39/// # Description {#bbldc_basicdaycountutil-description}
40/// This component provides a `struct`, `bbldc::BasicDayCountUtil`,
41/// that defines a suite of date-related functions used to compute the day count
42/// and the year fraction between two dates as prescribed by an enumerated
43/// day-count convention. Specifically, the `daysDiff` and `yearsDiff` methods
44/// defined in `bbldc::BasicDayCountUtil` take a trailing
45/// `DayCountConvention::Enum` argument indicating which particular day-count
46/// convention to apply.
47///
48/// ## Usage {#bbldc_basicdaycountutil-usage}
49///
50///
51/// This section illustrates intended use of this component.
52///
53/// ### Example 1: Computing Day Count and Year Fraction {#bbldc_basicdaycountutil-example-1-computing-day-count-and-year-fraction}
54///
55///
56/// The following snippets of code illustrate how to use
57/// `bbldc::BasicDayCountUtil` methods. First, create two `bdlt::Date`
58/// variables, `d1` and `d2`:
59/// @code
60/// const bdlt::Date d1(2003, 10, 19);
61/// const bdlt::Date d2(2003, 12, 31);
62/// @endcode
63/// Now, compute the day count between `d1` and `d2` according to the ISDA
64/// Actual/Actual convention:
65/// @code
66/// const int daysDiff = bbldc::BasicDayCountUtil::daysDiff(
67/// d1,
68/// d2,
69/// bbldc::DayCountConvention::e_ISDA_ACTUAL_ACTUAL);
70/// assert(73 == daysDiff);
71/// @endcode
72/// Finally, compute the year fraction between the two dates according to the
73/// ISDA Actual/Actual convention:
74/// @code
75/// const double yearsDiff = bbldc::BasicDayCountUtil::yearsDiff(
76/// d1,
77/// d2,
78/// bbldc::DayCountConvention::e_ISDA_ACTUAL_ACTUAL);
79/// // Need fuzzy comparison since 'yearsDiff' is a 'double'.
80/// assert(0.1999 < yearsDiff && 0.2001 > yearsDiff);
81/// @endcode
82/// @}
83/** @} */
84/** @} */
85
86/** @addtogroup bbl
87 * @{
88 */
89/** @addtogroup bbldc
90 * @{
91 */
92/** @addtogroup bbldc_basicdaycountutil
93 * @{
94 */
95
96#include <bblscm_version.h>
97
99
100#include <bdlt_date.h>
101
102
103namespace bbldc {
104
105 // ========================
106 // struct BasicDayCountUtil
107 // ========================
108
109/// This `struct` provides a namespace for a suite of pure functions that
110/// compute values based on dates according to enumerated day-count
111/// conventions.
112///
113/// See @ref bbldc_basicdaycountutil
115
116 // CLASS METHODS
117
118 /// Return the (signed) number of days between the specified `beginDate`
119 /// and `endDate` according to the specified day-count `convention`.
120 ///
121 /// \pre The behavior is undefined unless `isSupported(convention)`. If
122 /// `beginDate <= endDate` then the result is non-negative.
123 ///
124 /// \note Note that reversing the order of `beginDate` and `endDate` negates the result.
125 static int daysDiff(const bdlt::Date& beginDate,
126 const bdlt::Date& endDate,
127 DayCountConvention::Enum convention);
128
129 /// Return `true` if the specified `convention` is valid for use in
130 /// `daysDiff` and `yearsDiff`, and `false` otherwise.
131 static bool isSupported(DayCountConvention::Enum convention);
132
133 /// Return the (signed fractional) number of years between the specified
134 /// `beginDate` and `endDate` according to the specified day-count
135 /// `convention`. If `beginDate <= endDate` then the result is non-negative.
136 ///
137 /// \pre The behavior is undefined unless `isSupported(convention)`.
138 ///
139 /// \note Note that reversing the order of
140 /// `beginDate` and `endDate` negates the result; specifically,
141 /// `|yearsDiff(b, e, c) + yearsDiff(e, b, c)| <= 1.0e-15` for all dates
142 /// `b` and `e`, and day-count conventions `c`.
143 static double yearsDiff(const bdlt::Date& beginDate,
144 const bdlt::Date& endDate,
145 DayCountConvention::Enum convention);
146};
147
148} // close package namespace
149
150
151#endif
152
153// ----------------------------------------------------------------------------
154// Copyright 2015 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_basicdaycountutil.h:114
static int daysDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate, DayCountConvention::Enum convention)
static double yearsDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate, DayCountConvention::Enum convention)
static bool isSupported(DayCountConvention::Enum convention)
Enum
Definition bbldc_daycountconvention.h:134