BDE 4.14.0 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.
124
125 // CLASS METHODS
126
127 /// Return the (signed) number of days between the specified `beginDate`
128 /// and `endDate` according to the specified day-count `convention` with
129 /// the specified `calendar` providing the definition of business days.
130 /// If `beginDate <= endDate` then the result is non-negative. The
131 /// behavior is undefined unless `isSupported(convention)`,
132 /// `calendar.isInRange(beginDate)`, and `calendar.isInRange(endDate)`.
133 /// Note that reversing the order of `beginDate` and `endDate` negates
134 /// the result and that the result is 0 when `beginDate == endDate`.
135 static int daysDiff(const bdlt::Date& beginDate,
136 const bdlt::Date& endDate,
137 const bdlt::Calendar& calendar,
138 DayCountConvention::Enum convention);
139
140 /// Return `true` if the specified `convention` is valid for use in
141 /// `daysDiff` and `yearsDiff`, and `false` otherwise.
142 static bool isSupported(DayCountConvention::Enum convention);
143
144 /// Return the (signed fractional) number of years between the specified
145 /// `beginDate` and `endDate` according to the specified day-count
146 /// `convention` with the specified `calendar` providing the definition
147 /// of business days. If `beginDate <= endDate` then the result is
148 /// non-negative. The behavior is undefined unless
149 /// `isSupported(convention)`, `calendar.isInRange(beginDate)`, and
150 /// `calendar.isInRange(endDate)`. Note that reversing the order of
151 /// `beginDate` and `endDate` negates the result; specifically,
152 /// `|yearsDiff(b, e, cal, c) + yearsDiff(e, b, cal, c)| <= 1.0e-15` for
153 /// all calendars `cal`, valid dates `b` and `e`, and day-count
154 /// conventions `c`.
155 static double yearsDiff(const bdlt::Date& beginDate,
156 const bdlt::Date& endDate,
157 const bdlt::Calendar& calendar,
158 DayCountConvention::Enum convention);
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_calendar.h:569
Definition bdlt_date.h:294
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bbldc_basicactual360.h:107
Definition bbldc_calendardaycountutil.h:123
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:131