27#ifndef quantlib_index_hpp
28#define quantlib_index_hpp
52 virtual std::string
name()
const = 0;
63 virtual Real fixing(
const Date& fixingDate,
bool forecastTodaysFixing =
false)
const = 0;
87 template <
class DateIterator,
class ValueIterator>
91 bool forceOverwrite =
false) {
93 std::string tag =
name();
95 bool noInvalidFixing =
true, noDuplicatedFixing =
true;
96 Date invalidDate, duplicatedDate;
100 while (dBegin != dEnd) {
102 Real currentValue = h[*dBegin];
103 bool missingFixing = forceOverwrite || currentValue == nullValue;
106 h[*(dBegin++)] = *(vBegin++);
107 else if (
close(currentValue, *(vBegin))) {
111 noDuplicatedFixing =
false;
112 duplicatedDate = *(dBegin++);
113 duplicatedValue = *(vBegin++);
116 noInvalidFixing =
false;
117 invalidDate = *(dBegin++);
118 invalidValue = *(vBegin++);
122 QL_REQUIRE(noInvalidFixing,
"At least one invalid fixing provided: "
123 << invalidDate.
weekday() <<
" " << invalidDate <<
", "
125 QL_REQUIRE(noDuplicatedFixing,
"At least one duplicated fixing provided: "
126 << duplicatedDate <<
", " << duplicatedValue
127 <<
" while " << h[duplicatedDate]
128 <<
" value is already present");
purely virtual base class for indexes
virtual Calendar fixingCalendar() const =0
returns the calendar defining valid fixing dates
virtual Real fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const =0
returns the fixing at the given date
bool hasHistoricalFixing(const Date &fixingDate) const
returns whether a historical fixing was stored for the given date
void clearFixings()
clears all stored historical fixings
virtual bool allowsNativeFixings()
check if index allows for native fixings.
const TimeSeries< Real > & timeSeries() const
returns the fixing TimeSeries
virtual void addFixing(const Date &fixingDate, Real fixing, bool forceOverwrite=false)
stores the historical fixing at the given date
void addFixings(const TimeSeries< Real > &t, bool forceOverwrite=false)
stores historical fixings from a TimeSeries
virtual std::string name() const =0
Returns the name of the index.
virtual bool isValidFixingDate(const Date &fixingDate) const =0
returns TRUE if the fixing date is a valid one
void addFixings(DateIterator dBegin, DateIterator dEnd, ValueIterator vBegin, bool forceOverwrite=false)
stores historical fixings at the given dates
~Index() override=default
void checkNativeFixingsAllowed()
check if index allows for native fixings
const TimeSeries< Real > & getHistory(const std::string &name) const
returns the (possibly empty) history of the index fixings
bool hasHistoricalFixing(const std::string &name, const Date &fixingDate) const
returns whether a specific historical fixing was stored for the index and date
void setHistory(const std::string &name, TimeSeries< Real > history)
stores the historical fixings of the index
template class providing a null value for a given type.
Object that notifies its changes to a set of observers.
static IndexManager & instance()
access to the unique instance
Container for historical data.
floating-point comparisons
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
global repository for past index fixings
bool close(const Quantity &m1, const Quantity &m2, Size n)