24#ifndef quantlib_index_manager_hpp
25#define quantlib_index_manager_hpp
47 std::vector<std::string>
histories()
const;
56 [[deprecated(
"Use Index::hasHistoricalFixing instead")]]
57 bool hasHistory(
const std::string& name)
const;
62 [[deprecated(
"Use Index::timeSeries instead")]]
68 [[deprecated(
"Use Index::clearFixings instead")]]
74 [[deprecated(
"Use Index::hasHistoricalFixing instead")]]
80 [[deprecated(
"Use Index::addFixings instead")]]
86 [[deprecated(
"Register with the relevant index instead")]]
87 ext::shared_ptr<Observable>
notifier(
const std::string& name)
const;
91 bool operator()(
const std::string& s1,
const std::string& s2)
const {
92 return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), s2.end(), [](
const auto& c1,
const auto& c2) {
93 return std::toupper(static_cast<unsigned char>(c1)) < std::toupper(static_cast<unsigned char>(c2));
99 mutable std::map<std::string, ext::shared_ptr<Observable>>
notifiers_;
103 const Date& fixingDate,
105 bool forceOverwrite =
false);
107 template <
class DateIterator,
class ValueIterator>
111 ValueIterator vBegin,
112 bool forceOverwrite =
false,
113 const std::function<
bool(
const Date&
d)>& isValidFixingDate = {}) {
114 auto& h =
data_[name];
115 bool noInvalidFixing =
true, noDuplicatedFixing =
true;
116 Date invalidDate, duplicatedDate;
120 while (dBegin != dEnd) {
121 bool validFixing = isValidFixingDate ? isValidFixingDate(*dBegin) : true;
122 Real currentValue = h[*dBegin];
123 bool missingFixing = forceOverwrite || currentValue == nullValue;
126 h[*(dBegin++)] = *(vBegin++);
127 else if (
close(currentValue, *(vBegin))) {
131 noDuplicatedFixing =
false;
132 duplicatedDate = *(dBegin++);
133 duplicatedValue = *(vBegin++);
136 noInvalidFixing =
false;
137 invalidDate = *(dBegin++);
138 invalidValue = *(vBegin++);
144 QL_REQUIRE(noInvalidFixing,
"At least one invalid fixing provided: "
145 << invalidDate.
weekday() <<
" " << invalidDate <<
", "
147 QL_REQUIRE(noDuplicatedFixing,
"At least one duplicated fixing provided: "
148 << duplicatedDate <<
", " << duplicatedValue
149 <<
" while " << h[duplicatedDate]
150 <<
" value is already present");
purely virtual base class for indexes
global repository for past index fixings
std::map< std::string, TimeSeries< Real >, CaseInsensitiveCompare > data_
std::map< std::string, ext::shared_ptr< Observable > > notifiers_
const TimeSeries< Real > & getHistory(const std::string &name) const
bool hasHistoricalFixing(const std::string &name, const Date &fixingDate) const
void setHistory(const std::string &name, TimeSeries< Real > history)
void clearHistories()
clears all stored fixings
void addFixing(const std::string &name, const Date &fixingDate, Real fixing, bool forceOverwrite=false)
add a fixing
ext::shared_ptr< Observable > notifier(const std::string &name) const
void addFixings(const std::string &name, DateIterator dBegin, DateIterator dEnd, ValueIterator vBegin, bool forceOverwrite=false, const std::function< bool(const Date &d)> &isValidFixingDate={})
add fixings
std::vector< std::string > histories() const
returns all names of the indexes for which fixings were stored
void clearHistory(const std::string &name)
bool hasHistory(const std::string &name) const
template class providing a null value for a given type.
Basic support for the singleton pattern.
Container for historical data.
floating-point comparisons
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
bool close(const Quantity &m1, const Quantity &m2, Size n)
observable and assignable proxy to concrete value
#define QL_DEPRECATED_DISABLE_WARNING
#define QL_DEPRECATED_ENABLE_WARNING
basic support for the singleton pattern
bool operator()(const std::string &s1, const std::string &s2) const
Container for historical data.