Year or Day fraction retriever

This interface replaces ITenorConverter. It converts pillars, such as tenors, into durations expressed in either days or years, as needed.

The IYearOrDayFractionRetriever is the main portal to the objects implementing the conversion.

Process

There are two steps in converting a tenor into a number of days or a number of years:

  1. Decoding: find out what the pillar means. This is done by the IMaturityParser interface.
  2. Computing: convert the pillar and the asOfDate into a number of days or years, performed by the IYearFraction, IDayFraction, and IEndDate interfaces.

Retriever

The interface to inject the tenor converter bean into Atoti plugins is IYearOrDayFractionBuilderAware.

The provided retriever is:

interface IYearOrDayFractionRetriever {
    IDayFraction getDayFraction(String bucketType); // AsOfDate + Tenor to days
    IYearFraction getYearFraction(String bucketType); // AsOfDate + Tenor to years
    IMaturityParser getMaturityParser(String bucketType); // Tenor string to Tenor object
    IEndDate getEndDate(String bucketType); // AsOfDate + Tenor to end date
}

Builder

YearOrDayFractionRetriever.builder() is used to create the retriever.

By default, the builder will create a converter that will use the new way of counting the days, a day count convention A009, and the default cached maturity parser.

The builder can be used to set up each bucket type individually. A bucket is defined according to the default bucket definition and between the .build() statements.

For instance:

IYearOrDayFractionRetriever fractionBuilder = YearOrDayFractionRetriever
    .builder()
        .defaultValues()
            // This is the default bucket
        .build()
        .bucket("MyBucketType")
            // This is a specific bucket type
        .build()
    .build();

There are three types of buckets:

Bucket type How duration is computed
.legacy() Based on the calendar, by taking into account open days.
.standard() Simply defining days and months as year fractions.
.specific(...) User-defined.

Legacy builder

The legacy builder can be customized like this:

IYearOrDayFractionRetriever fractionBuilder = YearOrDayFractionRetriever
    .builder()
        .bucket("LegacyBucket")
            .legacy()
                .dayCountConvention(dayCountConvention)
                .businessDayConvention(businessDayConvention)
                .calendar(calendar)
            .build()
        .build()
    .build();
Parameter Type Default Value Description
dayCountConvention IDayCountConvention DayCountActualActual The way of counting days, months, and years.
businessDayConvention IBusinessDayConvention null The way of finding the closest open day.
calendar IBusinessDayCalendar null The calendar that defines which day is open.

Standard builder

The standard builder can be customized like this:

IYearOrDayFractionRetriever fractionBuilder = YearOrDayFractionRetriever
    .builder()
        .bucket("StandardBucket")
            .standard()
                .dayCountConvention(dayCountConvention)
            .build()
        .build()
    .build();
Parameter Type Default Value Description
dayCountConvention IDayCountConvention DayCountActualActual The way of counting days, months, and years.

Specific builder

The specific builder can be defined like this:

IYearOrDayFractionRetriever fractionBuilder = YearOrDayFractionRetriever
    .builder()
        .bucket("LegacyBucket")
            .specific(yearFraction)
            .specific(dayFraction)
            .specific(endDate)
        .build()
    .build();
Parameter Type Default Value Description
yearFraction IYearFractionFromTenorValue The default bucket value (standard) The conversion from (date, tenor) to years.
dayFraction IDayFractionFromTenorValue The default bucket value (standard) The conversion from (date, tenor) to days.
endDate IEndDateFromTenorValue The default bucket value (standard) The conversion from (date, tenor) to a date.

Maturity parser builder

The maturity parser can also be customized by bucket:

IYearOrDayFractionRetriever fractionBuilder = YearOrDayFractionRetriever
    .builder()
        .bucket("LegacyBucket")
            .cached(cached)
            .maturityParser(maturityParser)
        .build()
    .build();
Parameter Type Default Value Description
cached Boolean The default bucket value (true) Whether the maturity parser is cached.
maturityParser IMaturityParser The default bucket value (MaturityParser) The parser used.

Maturity parser

The interface IMaturityParser is responsible for decoding the tenors. The default implementation is MaturityParser. MaturityParserCached is an implementation that provides a cache of the results of the underlying implementation. As the pillars could be either durations or dates, as an intermediate value, we will use either a date or a duration held in a custom object Tenor, which can store Period, LocalDate, or year fraction.

Input String Input example Output type Computation Output example
Overnight O/N Duration ON = P1D, TN = P2D 1D
Period 3M2D Duration Just parse the string 3M2D
Double 1.25 Double Unit is years, 1/12 is month, and remaining is 1/365 days 1.25
IMM dates MAR24 Date Take the 3rd Wednesday of the month and make a date 2024-03-20
Date 2024-02-03 Date Just parse the string 2024-02-03
Double year 1.25Y Double Unit is years, 1/12 is month, and remainder is 1/365 days 1.25
Other anyString N/A Should be extended by the user to handle extra formats null

If the default implementation can’t decode your pillars, override it and add the extra decoding elements.

Year Fraction

The IYearFraction interface to compute a year fraction from a tenor and an asOfDate. It extends IYearFractionFromTenorValue and IMaturityParser.

The IYearFractionFromTenorValue is the part that actually does the computation, it is implemented by:

  • LegacyYearFraction: computes the fraction by using the calendar to find the target date, then computing the fraction between the asOfDate and the target date.
  • YearFraction: computes the fraction from a duration where the day/month/year is converted by using the daysInYear/daysInMonth/yearsInYear from the IDayCountConvention.

Day Fraction

The IDayFraction interface to compute a day fraction from a tenor and an asOfDate. It extends IDayFractionFromTenorValue and IMaturityParser.

The IDayFractionFromTenorValue is the part that actually does the computation, it is implemented by:

  • LegacyDayFraction: computes the fraction by using the calendar to find the target date, then computing the fraction between the asOfDate and the target date.
  • DayFraction: computes the fraction from a duration where the day/month/year is converted by using the daysInYear/daysInMonth/yearsInYear from the IDayCountConvention.

End date

The IEndDate interface to compute an end date from a tenor and an asOfDate. It extends IEndDateFromTenorValue and IMaturityParser.

The IEndDateFromTenorValue is the part that actually does the computation, it is implemented by:

  • LegacyEndDate: computes the target date by using the calendar to skip closed days.
  • EndDate: computes the end date by simply adding the duration to the asOfDate.