BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bbldc_calendardaycountutil.h
Go to the documentation of this file.
1/// @file bbldc_calendardaycountutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bbldc_calendardaycountutil.h -*-C++-*-
8#ifndef INCLUDED_BBLDC_CALENDARDAYCOUNTUTIL
9#define INCLUDED_BBLDC_CALENDARDAYCOUNTUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bbldc_calendardaycountutil bbldc_calendardaycountutil
15/// @brief Support for day-count calculations of `enum`-specified conventions.
16/// @addtogroup bbl
17/// @{
18/// @addtogroup bbldc
19/// @{
20/// @addtogroup bbldc_calendardaycountutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bbldc_calendardaycountutil-purpose"> Purpose</a>
25/// * <a href="#bbldc_calendardaycountutil-classes"> Classes </a>
26/// * <a href="#bbldc_calendardaycountutil-description"> Description </a>
27/// * <a href="#bbldc_calendardaycountutil-usage"> Usage </a>
28/// * <a href="#bbldc_calendardaycountutil-example-1-computing-day-count-and-year-fraction"> Example 1: Computing Day Count and Year Fraction </a>
29///
30/// # Purpose {#bbldc_calendardaycountutil-purpose}
31/// Support for day-count calculations of `enum`-specified conventions.
32///
33/// # Classes {#bbldc_calendardaycountutil-classes}
34///
35/// - bbldc::CalendarDayCountUtil: `enum`-specified day-count calculations
36///
37/// @see bbldc_daycountconvention, bbldc_calendarbus252
38///
39/// # Description {#bbldc_calendardaycountutil-description}
40/// This component provides a `struct`,
41/// `bbldc::CalendarDayCountUtil`, that defines a suite of date-related
42/// functions used to compute the day count and the year fraction between two
43/// dates as prescribed by an enumerated day-count convention. Specifically,
44/// the `daysDiff` and `yearsDiff` methods defined in
45/// `bbldc::CalendarDayCountUtil` take a trailing `DayCountConvention::Enum`
46/// argument indicating which particular day-count convention to apply.
47///
48/// ## Usage {#bbldc_calendardaycountutil-usage}
49///
50///
51/// This section illustrates intended use of this component.
52///
53/// ### Example 1: Computing Day Count and Year Fraction {#bbldc_calendardaycountutil-example-1-computing-day-count-and-year-fraction}
54///
55///
56/// The following snippets of code illustrate how to use
57/// `bbldc::CalendarDayCountUtil` 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/// Then, create a `calendar` with a valid range spanning 2003 and typical
64/// weekend days:
65/// @code
66/// bdlt::Calendar calendar;
67/// calendar.setValidRange(bdlt::Date(2003, 1, 1), bdlt::Date(2003, 12, 31));
68/// calendar.addWeekendDay(bdlt::DayOfWeek::e_SUN);
69/// calendar.addWeekendDay(bdlt::DayOfWeek::e_SAT);
70/// @endcode
71/// Now, compute the day count between `d1` and `d2` according to the BUS-252
72/// day-count convention:
73/// @code
74/// const int daysDiff = bbldc::CalendarDayCountUtil::daysDiff(
75/// d1,
76/// d2,
77/// calendar,
78/// bbldc::DayCountConvention::e_CALENDAR_BUS_252);
79/// assert(52 == daysDiff);
80/// @endcode
81/// Finally, compute the year fraction between the two dates according to the
82/// BUS-252 day-count convention:
83/// @code
84/// const double yearsDiff = bbldc::CalendarDayCountUtil::yearsDiff(
85/// d1,
86/// d2,
87/// calendar,
88/// bbldc::DayCountConvention::e_CALENDAR_BUS_252);
89/// // Need fuzzy comparison since 'yearsDiff' is a 'double'.
90/// assert(0.2063 < yearsDiff && 0.2064 > yearsDiff);
91/// @endcode
92/// @}
93/** @} */
94/** @} */
95
96/** @addtogroup bbl
97 * @{
98 */
99/** @addtogroup bbldc
100 * @{
101 */
102/** @addtogroup bbldc_calendardaycountutil
103 * @{
104 */
105
106#include <bblscm_version.h>
107
109
110#include <bdlt_calendar.h>
111#include <bdlt_date.h>
112
113
114namespace bbldc {
115
116 // ===========================
117 // struct CalendarDayCountUtil
118 // ===========================
119
120/// This `struct` provides a namespace for a suite of pure functions that
121/// compute values based on dates according to enumerated day-count
122/// conventions.
123///
124/// See @ref bbldc_calendardaycountutil
126
127 // CLASS METHODS
128
129 /// Return the (signed) number of days between the specified `beginDate`
130 /// and `endDate` according to the specified day-count `convention` with
131 /// the specified `calendar` providing the definition of business days.
132 /// If `beginDate <= endDate` then the result is non-negative.
133 ///
134 /// \pre The behavior is undefined unless `isSupported(convention)`,
135 /// `calendar.isInRange(beginDate)`, and `calendar.isInRange(endDate)`.
136 ///
137 /// \note Note that reversing the order of `beginDate` and `endDate` negates
138 /// the result and that the result is 0 when `beginDate == endDate`.
139 static int daysDiff(const bdlt::Date& beginDate,
140 const bdlt::Date& endDate,
141 const bdlt::Calendar& calendar,
142 DayCountConvention::Enum convention);
143
144 /// Return `true` if the specified `convention` is valid for use in
145 /// `daysDiff` and `yearsDiff`, and `false` otherwise.
146 static bool isSupported(DayCountConvention::Enum convention);
147
148 /// Return the (signed fractional) number of years between the specified
149 /// `beginDate` and `endDate` according to the specified day-count
150 /// `convention` with the specified `calendar` providing the definition
151 /// of business days. If `beginDate <= endDate` then the result is non-negative.
152 ///
153 /// \pre The behavior is undefined unless
154 /// `isSupported(convention)`, `calendar.isInRange(beginDate)`, and `calendar.isInRange(endDate)`.
155 ///
156 /// \note Note that reversing the order of
157 /// `beginDate` and `endDate` negates the result; specifically,
158 /// `|yearsDiff(b, e, cal, c) + yearsDiff(e, b, cal, c)| <= 1.0e-15` for
159 /// all calendars `cal`, valid dates `b` and `e`, and day-count
160 /// conventions `c`.
161 static double yearsDiff(const bdlt::Date& beginDate,
162 const bdlt::Date& endDate,
163 const bdlt::Calendar& calendar,
164 DayCountConvention::Enum convention);
165};
166
167} // close package namespace
168
169
170#endif
171
172// ----------------------------------------------------------------------------
173// Copyright 2015 Bloomberg Finance L.P.
174//
175// Licensed under the Apache License, Version 2.0 (the "License");
176// you may not use this file except in compliance with the License.
177// You may obtain a copy of the License at
178//
179// http://www.apache.org/licenses/LICENSE-2.0
180//
181// Unless required by applicable law or agreed to in writing, software
182// distributed under the License is distributed on an "AS IS" BASIS,
183// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
184// See the License for the specific language governing permissions and
185// limitations under the License.
186// ----------------------------- END-OF-FILE ----------------------------------
187
188/** @} */
189/** @} */
190/** @} */
Definition bdlt_calendar.h:570
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_calendardaycountutil.h:125
static bool isSupported(DayCountConvention::Enum convention)
static double yearsDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate, const bdlt::Calendar &calendar, DayCountConvention::Enum convention)
static int daysDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate, const bdlt::Calendar &calendar, DayCountConvention::Enum convention)
Enum
Definition bbldc_daycountconvention.h:134