BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bbldc_basicisdaactualactual.h
Go to the documentation of this file.
1/// @file bbldc_basicisdaactualactual.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bbldc_basicisdaactualactual.h -*-C++-*-
8#ifndef INCLUDED_BBLDC_BASICISDAACTUALACTUAL
9#define INCLUDED_BBLDC_BASICISDAACTUALACTUAL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bbldc_basicisdaactualactual bbldc_basicisdaactualactual
15/// @brief Provide stateless functions for the ISDA Actual/Actual convention.
16/// @addtogroup bbl
17/// @{
18/// @addtogroup bbldc
19/// @{
20/// @addtogroup bbldc_basicisdaactualactual
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bbldc_basicisdaactualactual-purpose"> Purpose</a>
25/// * <a href="#bbldc_basicisdaactualactual-classes"> Classes </a>
26/// * <a href="#bbldc_basicisdaactualactual-description"> Description </a>
27/// * <a href="#bbldc_basicisdaactualactual-usage"> Usage </a>
28/// * <a href="#bbldc_basicisdaactualactual-example-1-computing-day-count-and-year-fraction"> Example 1: Computing Day Count and Year Fraction </a>
29///
30/// # Purpose {#bbldc_basicisdaactualactual-purpose}
31/// Provide stateless functions for the ISDA Actual/Actual convention.
32///
33/// # Classes {#bbldc_basicisdaactualactual-classes}
34///
35/// - bbldc::BasicIsdaActualActual: ISDA Actual/Actual stateless functions
36///
37/// # Description {#bbldc_basicisdaactualactual-description}
38/// This component provides a `struct`,
39/// `bbldc::BasicIsdaActualActual`, that serves as a namespace for defining a
40/// suite of date-related functions used to compute the day count and the year
41/// fraction between two dates as per the ISDA Actual/Actual day-count
42/// convention. In this day-count convention, the day count between two dates
43/// is exactly the number of days occurring in the time period and the year
44/// fraction between two dates is the number of full calendar years between the
45/// dates plus front-stub and back-stub adjustments.
46///
47/// ## Usage {#bbldc_basicisdaactualactual-usage}
48///
49///
50/// This section illustrates intended use of this component.
51///
52/// ### Example 1: Computing Day Count and Year Fraction {#bbldc_basicisdaactualactual-example-1-computing-day-count-and-year-fraction}
53///
54///
55/// The following snippets of code illustrate how to use
56/// `bbldc::BasicIsdaActualActual` methods. First, create two `bdlt::Date`
57/// variables, `d1` and `d2`:
58/// @code
59/// const bdlt::Date d1(2003, 10, 19);
60/// const bdlt::Date d2(2003, 12, 31);
61/// @endcode
62/// Then, compute the day count between the two dates:
63/// @code
64/// const int daysDiff = bbldc::BasicIsdaActualActual::daysDiff(d1, d2);
65/// assert(73 == daysDiff);
66/// @endcode
67/// Finally, compute the year fraction between the two dates:
68/// @code
69/// const double yearsDiff = bbldc::BasicIsdaActualActual::yearsDiff(d1, d2);
70/// // Need fuzzy comparison since 'yearsDiff' is a 'double'.
71/// assert(yearsDiff > 0.1999 && yearsDiff < 0.2001);
72/// @endcode
73/// @}
74/** @} */
75/** @} */
76
77/** @addtogroup bbl
78 * @{
79 */
80/** @addtogroup bbldc
81 * @{
82 */
83/** @addtogroup bbldc_basicisdaactualactual
84 * @{
85 */
86
87#include <bblscm_version.h>
88
89#include <bdlt_date.h>
90
91
92namespace bbldc {
93
94 // ============================
95 // struct BasicIsdaActualActual
96 // ============================
97
98/// This `struct` provides a namespace for a suite of pure functions that
99/// compute values based on dates according to the ISDA Actual/Actual
100/// day-count convention.
102
103 // CLASS METHODS
104
105 /// Return the (signed) number of days between the specified `beginDate`
106 /// and `endDate` according to the ISDA Actual/Actual day-count
107 /// convention. If `beginDate <= endDate`, then the result is
108 /// non-negative. Note that reversing the order of `beginDate` and
109 /// `endDate` negates the result.
110 static int daysDiff(const bdlt::Date& beginDate,
111 const bdlt::Date& endDate);
112
113 /// Return the (signed fractional) number of years between the specified
114 /// `beginDate` and `endDate` according to the ISDA Actual/Actual
115 /// day-count convention. If `beginDate <= endDate`, then the result is
116 /// non-negative. Note that reversing the order of `beginDate` and
117 /// `endDate` negates the result; specifically,
118 /// `|yearsDiff(b, e) + yearsDiff(e, b)| <= 1.0e-15` for all dates `b`
119 /// and `e`.
120 static double yearsDiff(const bdlt::Date& beginDate,
121 const bdlt::Date& endDate);
122};
123
124// ============================================================================
125// INLINE DEFINITIONS
126// ============================================================================
127
128 // -----------------------
129 // struct IsdaActualActual
130 // -----------------------
131
132// CLASS METHODS
133inline
135 const bdlt::Date& endDate)
136{
137 return endDate - beginDate;
138}
139
140} // close package namespace
141
142
143#endif
144
145// ----------------------------------------------------------------------------
146// Copyright 2015 Bloomberg Finance L.P.
147//
148// Licensed under the Apache License, Version 2.0 (the "License");
149// you may not use this file except in compliance with the License.
150// You may obtain a copy of the License at
151//
152// http://www.apache.org/licenses/LICENSE-2.0
153//
154// Unless required by applicable law or agreed to in writing, software
155// distributed under the License is distributed on an "AS IS" BASIS,
156// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
157// See the License for the specific language governing permissions and
158// limitations under the License.
159// ----------------------------- END-OF-FILE ----------------------------------
160
161/** @} */
162/** @} */
163/** @} */
Definition bdlt_date.h:294
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bbldc_basicactual360.h:107
Definition bbldc_basicisdaactualactual.h:101
static int daysDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate)
Definition bbldc_basicisdaactualactual.h:134
static double yearsDiff(const bdlt::Date &beginDate, const bdlt::Date &endDate)