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