25#ifndef quantlib_timeseries_hpp
26#define quantlib_timeseries_hpp
32#include <boost/iterator/transform_iterator.hpp>
50 template <
class T,
class Container = std::map<Date, T> >
64 template <
class DateIterator,
class ValueIterator>
66 ValueIterator vBegin) {
67 while (dBegin != dEnd)
68 values_[*(dBegin++)] = *(vBegin++);
75 template <
class ValueIterator>
77 ValueIterator
begin, ValueIterator
end) {
100 return found->second;
104 return found->second;
119 template <
class container,
class iterator_category>
121 typedef std::reverse_iterator<typename container::const_iterator>
135 template <
class container>
137 typedef typename container::const_reverse_iterator
147 typedef std::conditional_t<
148 std::is_same_v<iterator_category, std::bidirectional_iterator_tag> ||
149 std::is_base_of_v<std::bidirectional_iterator_tag, iterator_category>,
199 template <
class T,
class C>
201 QL_REQUIRE(!values_.empty(),
"empty timeseries");
202 return values_.begin()->first;
205 template <
class T,
class C>
207 QL_REQUIRE(!values_.empty(),
"empty timeseries");
208 return rbegin()->first;
211 template <
class T,
class C>
213 return values_.size();
216 template <
class T,
class C>
218 return values_.empty();
221 template <
class T,
class C>
224 return values_.begin();
227 template <
class T,
class C>
230 return values_.end();
233 template <
class T,
class C>
236 auto i = values_.find(
d);
237 if (i == values_.end()) {
244 template <
class T,
class C>
248 std::transform(cbegin(), cend(), std::back_inserter(
v),
253 template <
class T,
class C>
257 std::transform(cbegin(), cend(), std::back_inserter(
v),
template class providing a null value for a given type.
Container for historical data.
static const Date & get_time(const container_value_type &v)
const_reverse_iterator rend() const
Container::const_iterator const_iterator
reverse< Container, enable_reverse >::const_reverse_iterator const_reverse_iterator
std::conditional_t< std::is_same_v< iterator_category, std::bidirectional_iterator_tag >||std::is_base_of_v< std::bidirectional_iterator_tag, iterator_category >, std::bidirectional_iterator_tag, std::input_iterator_tag > enable_reverse
const_iterator::iterator_category iterator_category
const_iterator begin() const
const_iterator find(const Date &)
const_iterator cbegin() const
TimeSeries(DateIterator dBegin, DateIterator dEnd, ValueIterator vBegin)
std::function< T(const container_value_type &)> projection_value
std::vector< T > values() const
returns the historical data
Container::value_type container_value_type
bool empty() const
returns whether the series contains any data
std::function< Date(const container_value_type &)> projection_time
T & operator[](const Date &d)
const_iterator cend() const
const_reverse_iterator crbegin() const
TimeSeries(const Date &firstDate, ValueIterator begin, ValueIterator end)
std::vector< Date > dates() const
returns the dates for which historical data exist
Date firstDate() const
returns the first date for which a historical datum exists
Date lastDate() const
returns the last date for which a historical datum exists
const_reverse_iterator crend() const
static const T & get_value(const container_value_type &v)
Size size() const
returns the number of historical data including null ones
const_iterator end() const
T operator[](const Date &d) const
returns the (possibly null) datum corresponding to the given date
const_reverse_iterator rbegin() const
date- and time-related classes, typedefs and enumerations
Classes and functions for error handling.
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Maps function, bind and cref to either the boost or std implementation.
std::size_t Size
size of a container
ext::shared_ptr< BlackVolTermStructure > v
const_reverse_iterator rend() const
container::const_reverse_iterator const_reverse_iterator
reverse(const container &c)
const_reverse_iterator rbegin() const
const_reverse_iterator rend() const
std::reverse_iterator< typename container::const_iterator > const_reverse_iterator
reverse(const container &c)
const_reverse_iterator rbegin() const