An index is a value of a hypothetical portfolio or, more generally, a statistical measure for a collection of data points. Indices are usually fixed at specific dates. Individual fixings can be thought of as date-value pairs. In an abstract way indices are very much like time series with the difference that the dates of the fixings are restricted. The Index class acts as an abstract base for all index classes defined in QuantLib. Two abstract methods provide basic information and about the index.
virtual std::string name() const = 0; virtual Calendar fixingCalendar() const = 0;
name() should return the name of the index. The name is used for user output and can be used for comparing different indices but it shouldn’t be used in switch like if statements because the names of indices are not guaranteed to stay the same between versions of QuantLib. The fixingCalendar() method should return the calendar which is used to decide if a given day is a holiday and helps deciding of a date is a valid fixing date. This decision is carried out by the following method.
virtual bool isValidFixingDate(const Date& fixingDate) const = 0;
The method isValidFixingDate() should return true if the date passed to it can be used as a fixing date, that is whether a foxing can be made on that specific date. The central method of Index, which has to be implemented by a concrete class, is the fixing() method.
virtual Real fixing(const Date& fixingDate, bool forecastTodaysFixing = false) const = 0;
This method should return a number corresponding to the fixing date. For dates before the current evaluation date This method usually returns one of the fixings that have been added manually yo the index. For dates after the evaluation date some forecast has to be made. If the fixing date is requested for the evaluation date then a forecast should be attempted only if the optional flag forecastTodaysFixing has been set to true.
The following method are used to manually add fixings to the index.
virtual void addFixing(const Date& fixingDate, Real fixing, bool forceOverwrite = false); template<class DateIterator, class ValueIterator> void addFixings(DateIterator dBegin, DateIterator dEnd, ValueIterator vBegin, bool forceOverwrite = false) void addFixings(const TimeSeries& t, bool forceOverwrite = false);
The first method, addFixing(), adds a single fixing to the index. This fixing is passed to the Index by a single Date and Real pair. The second method adds multiple fixings specified by the iterators dBegin, dEnd, and vBegin. The iterators dBegin and dEnd specify the range of dates for the fixings, while vBegin is the iterator pointing to the first fixing value. It has to be ensured that vBegin can provide enough values for all the dates in the range. Finally, the third method adds the fixings from a time series. As said before a time series contains the same type of data but differs from and index in that the dates are not restricted. All three methods perform a check on the dates to ensure that they are valid fixing dates. If any of the dates are not fixing dates then an exception is thrown. The methods also check if the fixings that are added conflict with existing fixings which are already stored in the index. A conflict occurs when two fixings are added for the same date but with different values. Depending on the the optional flag, forceOverwrite, the conflicting data either replaces the existing value or an exception is thrown. By default forceOverwrite is false which means a conflict will cause an exception to be raised.
const TimeSeries<Real>& timeSeries(); void clearFixings();
It is possible to access the underlying time series directly by calling the timeSeries() method. The clearFixings() method does what you expect it to do and will clear all the fixings stored in the index.