BloombergLP::bbldc::PeriodDayCountUtil::yearsDiff

Return the (signed fractional) number of years between two dates.

Synopsis

Declared in <bbldc_perioddaycountutil.h>

static
double
yearsDiff(
    bdlt::Date const& beginDate,
    bdlt::Date const& endDate,
    bsl::vector<bdlt::Date> const& periodDate,
    double periodYearDiff,
    DayCountConvention::Enum convention);

Description

Return the (signed fractional) number of years between the specified beginDate and endDate according to the specified day-count convention with periods starting on the specified periodDate values and each period having a duration of the specified periodYearDiff years (e.g., 0.25 for quarterly periods). If beginDate <= endDate then the result is non-negative. The behavior is undefined unless periodDate.size() >= 2, the values contained in periodDate are unique and sorted from minimum to maximum, min(beginDate, endDate) >= periodDate.front(), max(beginDate, endDate) <= periodDate.back(), and isSupported(convention). Note that reversing the order of beginDate and endDate negates the result; specifically, |yearsDiff(b,e,pd,pyd,c) + yearsDiff(e,b,pd,pyd,c)| <= 1.0e-15 for all dates b and e, periods pd, and year fraction per period pyd.

Return Value

signed fractional year difference according to convention

Parameters

NameDescription
beginDatestart of the date range
endDateend of the date range
periodDatesorted unique period-boundary dates
periodYearDiffyear fraction of each period
conventionday-count convention to apply