BDE 4.14.0 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.
113
114 // CLASS METHODS
115
116 /// Return the (signed) number of days between the specified `beginDate`
117 /// and `endDate` according to the specified day-count `convention`.
118 /// The behavior is undefined unless `isSupported(convention)`. If
119 /// `beginDate <= endDate` then the result is non-negative. Note that
120 /// reversing the order of `beginDate` and `endDate` negates the result.
121 static int daysDiff(const bdlt::Date& beginDate,
122 const bdlt::Date& endDate,
123 DayCountConvention::Enum convention);
124
125 /// Return `true` if the specified `convention` is valid for use in
126 /// `daysDiff` and `yearsDiff`, and `false` otherwise.
127 static bool isSupported(DayCountConvention::Enum convention);
128
129 /// Return the (signed fractional) number of years between the specified
130 /// `beginDate` and `endDate` according to the specified day-count
131 /// `convention`. If `beginDate <= endDate` then the result is
132 /// non-negative. The behavior is undefined unless
133 /// `isSupported(convention)`. Note that reversing the order of
134 /// `beginDate` and `endDate` negates the result; specifically,
135 /// `|yearsDiff(b, e, c) + yearsDiff(e, b, c)| <= 1.0e-15` for all dates
136 /// `b` and `e`, and day-count conventions `c`.
137 static double yearsDiff(const bdlt::Date& beginDate,
138 const bdlt::Date& endDate,
139 DayCountConvention::Enum convention);
140};
141
142} // close package namespace
143
144
145#endif
146
147// ----------------------------------------------------------------------------
148// Copyright 2015 Bloomberg Finance L.P.
149//
150// Licensed under the Apache License, Version 2.0 (the "License");
151// you may not use this file except in compliance with the License.
152// You may obtain a copy of the License at
153//
154// http://www.apache.org/licenses/LICENSE-2.0
155//
156// Unless required by applicable law or agreed to in writing, software
157// distributed under the License is distributed on an "AS IS" BASIS,
158// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
159// See the License for the specific language governing permissions and
160// limitations under the License.
161// ----------------------------- END-OF-FILE ----------------------------------
162
163/** @} */
164/** @} */
165/** @} */
Definition bdlt_date.h:294
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bbldc_basicactual360.h:107
Definition bbldc_basicdaycountutil.h:112
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:131