QuantLib: Term Structures

QuantLib defines an abstract class called TermStrucure. This class defines the base for any kind of term structure. The TermStrucure class is inherited by a number of classes such as YieldTermStructure, InflationTermStructure or DefaultProbabilityTermStructure. The YieldTermStructure defines the base for all yield curves, InflationTermStructure acts as a base for all inflation term structures and the DefaultProbabilityTermStructure is the base for term structures of the default risk. Term structures are an important tool for analyzing the market and many different term structure classes are defined in the library.

Here I will talk about the abstract TermStrucure class. In later posts I will talk about the concrete implementations. Term structures need to keep track of a reference date. This reference date can be either fixed to a specific date, it can be given by a fixed number of business days after the evaluation date or it can be linked to the reference date of an underlying structure. Three different constructors are defined for these three cases.

When the reference date is fixed, the following constructor should be used.

TermStructure(const Date& referenceDate,
              const Calendar& calendar = Calendar(),
              const DayCounter& dc = DayCounter());

The first argument of this constructor is the reference date, the second argument passes the calendar to the term structure and the third argument is the day counter that is used for calculating the time intervals as fraction of a year. The calendar and day counter default to the default Calendar and DayCounter classes.

If the reference date is calculated by as fixed offset from today’s date then the following constructor should be used.

TermStructure(Natural settlementDays,
              const Calendar&,
              const DayCounter& dc = DayCounter());

The first parameter gives the number of days after the evaluation date. The evaluation date is taken from the global settings, Settings::evaluationDate(). See the discussion of the global settings object for details of how the evaluation date is determined. The second parameter is the calendar used to advance the date forward from the evaluation date. In contrast to the previous constructor, the calendar cannot be left undefined and should be a concrete implementation of the Calendar class. The third parameter is the day counter which is used to calculate time in fractions of a year.

Finally, the constructor which should only be used if the reference date of the term structure depends on some underlying structure.

TermStructure(const DayCounter& dc = DayCounter());

This constructor only has one,optional, parameter, the day counter u as d to calculate fractions of a year. This constructor should only be used for those classes that have re-implemented the referenceDate() method to reflect the reference date of the underlying structure.

The central method of the term structure returns the reference date.

virtual const Date& referenceDate() const;

The implementation inside the TermStrucure class handles the cases when the reference date is fixed or given as a number of business days after the evaluation date. If other behavior is needed it should be re-implemented in the subclass.

The following methods are utility methods for accessing information about the term structure.

virtual DayCounter dayCounter() const;
Time timeFromReference(const Date& date) const;
virtual Date maxDate() const = 0;
virtual Time maxTime() const;
virtual Calendar calendar() const;
virtual Natural settlementDays() const;
void update();

The method dayCounter() returns the day counter associated with the term structure. To access the time between a date and the reference date use the method timeFromReference(). The value returned by this function is the time in years as calculated by the day counter. maxDate() is an abstract function that should return the maximum date for which the term structure can return values. This method has to be implemented by a concrete term structure. The method maxTime uses the value returned by maxDate() and calculates, by calling timeFromReference(), the maximum time after the reference date for which values can be returned. The calendar used by the term structure is returned by the calendar() method and the method settlementDays() returns the number of days between the current evaluation date and the reference date.

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>