QuantLib: Day Counting Conventions

In order to properly carry out financial calculations involving date intervals, day counting conventions have to be properly taken care of. In QuantLib, these are handled by a series of classes, all implementing the DayCounter interface. The DayCounter class defines three methods.

std::string name();
Integer dayCount(Date &start, Date &end);
Time yearFraction(Date &start, Date &end, 
                  Date &refDateStart, Date &refDateEnd);

The name() method returns the name of the day counting convention. This is used for output and for comparison between different day counter objects. Note that the names are not guaranteed to stay the same from one version of QuantLib to another. For this reason it is discouraged to use the names in a switch-like statement.

The dayCount() method returns the number of business days between the start date and the end date. This number is calculated using the day counting convention defined by the specific implementation.

Similarly, the yearFraction() method returns the number of business days, expressed as fractions of a year, according to the day counting convention. The reference start and end days are only used in the ISMA variant of the Actual/Actual day counter. Here the fraction of a year depend on a reference time period. For all other day counters these values are ignored and do not have to be specified.

The DayCounter class is implemented using the bridge design pattern. This means that the actual work is done by a nested class, called the implementation. A DayCounter object will hold a pointer to a specific implementation which can be copied to other day counters. In this way the DayCounter obtains value semantics.

DayCounter dc = ActualActualDayCounter();

In the above example, the dc object holds a day counter implementing the actual actual day counting convention, even though dc itself is of the base type DayCounter.

Predefined Day Counters

There are a number of day counters predefined in the header files found in the date/daycounters subdirectory. These should be sufficient for most everyday calculations.

SimpleDayCounter is a day counter intended for theoretical calculations. This day counter does not correspond to any convention in the real world. Whole month distances are returned as simple fractions of a year. This means that two dates which are 3 months apart correspond to exactly 1/4 of a year. One month is 1/12 of a year and all other multiples of month are returned as multiples of 1/12 of a year. Warning: In situations when day counters are used together with calendars, the SimpleDayCounter should be used only in conjunction with the NullCalendar, otherwise the results may not be correct.

Thirty360 implements the 30/360 day counting convention and its variations. In the pure 30/360 convention a starting date on or after the 30th of a month becomes the 30th of that month. An ending date on the 31st becomes the 1st of the following month if the starting date is before the 30th of a month, otherwise the ending date will become the 30th of its month. This variant is named the USA or BondBasis variant.

The European variant of the 30/360, the 30E/360 convention will always shift the ending date to the 30th of its month if it falls on the 31st.

In the Italian variant, dates on or after the 28th of February is shifted to the 30th of February for computational sake.

The variant can be chosen in the constructor of the Thirty360 class. The Thirty360::Convention enum defines the values USA, BondBasis, European, EurobondBasis, and Italian. These values are passed to the constructor to specify the variant.

Actual360 implements the Actual/360 day count convention, abbreviated as Act/360 or A/360.

Actual365Fixed implements the
Actual/365 (Fixed) day count convention. This is also abbreviated as Act/365 (Fixed), A/365 (Fixed), or A/365F.

ActualActual implements the Actual/Actual day count convention and its variants. The ISDA convention, which is the same as Actual/Actual (Historical), Actual/Actual, Act/Act, and Act/365. The ISMA and US Treasury convention, which is the same as Actual/Actual (Bond). In the ISMA convention a reference time period should be specified when calculating the fraction of a year between two dates. And finally the AFB convention, which is the same as Actual/Actual (Euro). The choice of the variant is made by passing a ActualActual::Convention value to the constructor of ActualActual. This enum defines the values ISMA, Bond, ISDA, Historical, Actual365, AFB, and Euro corresponding to the different variants.

Business252 implements the Business/252 day count convention used in Brazil. By default this convention uses the Brazil calendar but any other calendar can be passed in the constructor.