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