23#include <boost/numeric/conversion/cast.hpp>
30 Date guessDate = referenceDate
31 +
Period(boost::numeric_cast<Integer>(round(
t * 365.25)),
Days);
34 guessDate +=
Period(boost::numeric_cast<Integer>(
35 round((
t - guessTime)*365.25)),
Days);
36 guessTime = dayCounter.
yearFraction(referenceDate, guessDate);
41 const auto searchDirection = boost::numeric_cast<Integer>(copysign(1.0,
t - guessTime));
47 while (searchDirection*(
50 nextDate = guessDate +
Period(searchDirection, u)) -
t) < 0.0)
54 guessTime = dayCounter.
yearFraction(referenceDate, guessDate);
58 std::abs(guessTime -
t))
61 return guessDate +
Period(searchDirection,
Days);
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
floating-point comparisons
TimeUnit
Units used to describe time periods.
Real Time
continuous quantity with 1-year units
Date yearFractionToDate(const DayCounter &dayCounter, const Date &referenceDate, Time t)
bool close_enough(const Quantity &m1, const Quantity &m2, Size n)
"inverse" of a daycounter