25#ifndef quantlib_time_grid_hpp
26#define quantlib_time_grid_hpp
54 template <
class Iterator>
63 "negative times not allowed");
76 std::back_inserter(
dt_));
85 template <
class Iterator>
94 "negative times not allowed");
105 std::vector<Time> diff;
108 std::back_inserter(diff));
109 if (diff.front()==0.0)
110 diff.erase(diff.begin());
111 dtMax = *(std::min_element(diff.begin(), diff.end()));
116 Time periodBegin = 0.0;
117 times_.push_back(periodBegin);
122 if (periodEnd != 0.0) {
124 Size nSteps = std::max(
Size(std::lround((periodEnd - periodBegin)/dtMax)),
Size(1));
125 Time dt = (periodEnd - periodBegin)/nSteps;
129 periodBegin = periodEnd;
134 std::back_inserter(
dt_));
159 typedef std::vector<Time>::const_reverse_iterator
const_reverse_iterator rend() const
std::vector< Time > mandatoryTimes_
TimeGrid(Iterator begin, Iterator end)
Time grid with mandatory time points.
const_iterator begin() const
std::vector< Time >::const_reverse_iterator const_reverse_iterator
TimeGrid(std::initializer_list< Time > times)
Time operator[](Size i) const
TimeGrid(Iterator begin, Iterator end, Size steps)
Time grid with mandatory time points.
std::vector< Time > times_
Time closestTime(Time t) const
returns the time on the grid closest to the given t
Size index(Time t) const
returns the index i such that grid[i] = t
Size closestIndex(Time t) const
returns the index i such that grid[i] is closest to t
const_iterator end() const
const std::vector< Time > & mandatoryTimes() const
TimeGrid(std::initializer_list< Time > times, Size steps)
const_reverse_iterator rbegin() const
std::vector< Time >::const_iterator const_iterator
floating-point comparisons
Classes and functions for error handling.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Real Time
continuous quantity with 1-year units
std::size_t Size
size of a container
bool close_enough(const Quantity &m1, const Quantity &m2, Size n)