# QuantLib: Interest Rate Index

Previously, I have talked about indices and have looked at the Index class in QuantLib. In this article I will talk about a specialization of the Index class, the InterestRateIndex class. This class extends the basic Index with functionality that is common to all indices that are tied to interest rates. The constructor of InterestRateIndex takes a number of arguments.

InterestRateIndex(
const std::string& familyName,
const Period& tenor,
Natural fixingDays,
const Currency& currency,
const Calendar& fixingCalendar,
const DayCounter& dayCounter);

The first parameter is the family name of the index. This could be something like GBPLibor or Euribor. The second parameter specifies the tenor of the particular index. The third parameter represents the fixing days, that is the number of business days between the fixing date and the value date. This is usually fixed for a particular family of interest rate indices, as is the currency of the index, the fixing calendar and the day counter. These last four parameters are usually specified in the constructor of a derived class and are not left for the user to specify.

std::string name() const;

This method overrides the name() method of the Index class. The name of the index is constructed from the information given in the constructor. It starts with the family name. For indices with a tenor of one day the ending depends on the settlement days and is either ON, TN or SN when settlementDays is 1, 2 or 3. For other tenors the tenor period is appended to the string in short format, e.g. 3M for a three month tenor.

Calendar fixingCalendar() const;
bool isValidFixingDate(const Date& fixingDate) const;

The method fixingCalendar() will return the fixing calendar passed in the constructor. The method isValidFixingDate() is a shortcut and is equivalent to fixingCalendar().isBusinessDay(). Here are a few more inspectors.

std::string familyName() const;
Period tenor() const;
Natural fixingDays() const;
const Currency& currency() const;
const DayCounter& dayCounter() const;

All in all these return pretty much what you would expect. The values returned are just those that were passed in the constructor. The following two methods are used to convert between a value date and the corresponding fixing date.

Date fixingDate(const Date& valueDate) const;
virtual Date valueDate(const Date& fixingDate) const;

The method fixingDate() calculates the fixing date from the value date. The value date lies a number of days after the fixing date, as specified by the fixingDays variable. To find the fixing date, the calendar is used to move backward by that number of days. Conversely, valueDate() will use the calendar to move forward by the number of business days as specified by fixingDays in order to find the value date from the fixing date. Note, how the valueDate() method is declared virtual whereas fixingDate() is not. This allows valueDate() to be re-defined in order to allow for specific conventions.

virtual Date maturityDate(const Date& valueDate) const = 0;

This method should calculate the maturity date from the value date of the index. Usually this will advance the value date by the tenor period. However, since there is a choice of business convention and other convention which influence the outcome, there is no default way of finding the maturity date. For this reason the method has been declared abstract and must be implemented in a concrete interest rate index class.

virtual Rate forecastFixing(const Date& fixingDate) const = 0;
Rate pastFixing(const Date& fixingDate) const;

The method forecastFixing() is an abstract method that needs to be implemented by a concrete class in order to forecast fixings in the future. The method pastFixing(), on the other hand retrieves a previous fixing from the ones that have already been stored in the index.

Rate fixing(const Date& fixingDate,
bool forecastTodaysFixing = false) const;

This method implements the method from Index and returns a fixing for a given date. If the date lies in the past then pastFixing() is called, if the date lies in the future then forecastFixing() is called. If fixing is called with today’s date (the evaluation date set in the global Settings) then the flag forecastTodaysFixing determines whether to forecast today’s fixing or not. If forecastTodaysFixing is true, then fixing() will always return a forecast value for today’s fixing. If, on the other hand, it is false then a past fixing is looked for first. If no past fixing for today is found the behavior depends on the result of

Settings::instance().enforcesTodaysHistoricFixings())

If this method indicates that today’s fixing should always be historic then an exception is thrown if it doesn’t exist. Otherwise fixing() will fall back to forecasting today’s fixing.