Interface DayCount

  • All Superinterfaces:
    Named

    public interface DayCount
    extends Named
    A convention defining how to calculate fractions of a year.

    The purpose of this convention is to define how to convert dates into numeric year fractions. The is of use when calculating accrued interest over time.

    The most common implementations are provided in DayCounts. Additional implementations may be added by implementing this interface.

    All implementations of this interface must be immutable and thread-safe.

    • Method Detail

      • of

        static DayCount of​(String uniqueName)
        Obtains an instance from the specified unique name.
        Parameters:
        uniqueName - the unique name
        Returns:
        the day count
        Throws:
        IllegalArgumentException - if the name is not known
      • ofBus252

        static DayCount ofBus252​(HolidayCalendarId calendar)
        Obtains an instance of the 'Bus/252' day count based on a specific calendar.

        The 'Bus/252' day count is unusual in that it relies on a specific holiday calendar. The calendar is stored within the day count.

        To avoid widespread complexity in the system, the holiday calendar associated with 'Bus/252' holiday calendars is looked up using the standard reference data.

        This day count is typically used in Brazil.

        Parameters:
        calendar - the holiday calendar
        Returns:
        the day count
      • extendedEnum

        static ExtendedEnum<DayCount> extendedEnum()
        Gets the extended enum helper.

        This helper allows instances of the day count to be looked up. It also provides the complete set of available instances.

        Returns:
        the extended enum helper
      • yearFraction

        default double yearFraction​(LocalDate firstDate,
                                    LocalDate secondDate)
        Gets the year fraction between the specified dates.

        Given two dates, this method returns the fraction of a year between these dates according to the convention. The dates must be in order.

        This uses a simple DayCount.ScheduleInfo which has the end-of-month convention set to true, but throws an exception for other methods. Certain implementations of DayCount need the missing information, and thus will throw an exception.

        Parameters:
        firstDate - the first date
        secondDate - the second date, on or after the first date
        Returns:
        the year fraction
        Throws:
        IllegalArgumentException - if the dates are not in order
        UnsupportedOperationException - if the year fraction cannot be obtained
      • yearFraction

        double yearFraction​(LocalDate firstDate,
                            LocalDate secondDate,
                            DayCount.ScheduleInfo scheduleInfo)
        Gets the year fraction between the specified dates.

        Given two dates, this method returns the fraction of a year between these dates according to the convention. The dates must be in order.

        Parameters:
        firstDate - the first date
        secondDate - the second date, on or after the first date
        scheduleInfo - the schedule information
        Returns:
        the year fraction, zero or greater
        Throws:
        IllegalArgumentException - if the dates are not in order
        UnsupportedOperationException - if the year fraction cannot be obtained
      • relativeYearFraction

        default double relativeYearFraction​(LocalDate firstDate,
                                            LocalDate secondDate)
        Gets the relative year fraction between the specified dates.

        Given two dates, this method returns the fraction of a year between these dates according to the convention. The result of this method will be negative if the first date is after the second date. The result is calculated using yearFraction(LocalDate, LocalDate, ScheduleInfo).

        This uses a simple DayCount.ScheduleInfo which has the end-of-month convention set to true, but throws an exception for other methods. Certain implementations of DayCount need the missing information, and thus will throw an exception.

        Parameters:
        firstDate - the first date
        secondDate - the second date, which may be before the first date
        Returns:
        the year fraction, may be negative
        Throws:
        UnsupportedOperationException - if the year fraction cannot be obtained
      • relativeYearFraction

        default double relativeYearFraction​(LocalDate firstDate,
                                            LocalDate secondDate,
                                            DayCount.ScheduleInfo scheduleInfo)
        Gets the relative year fraction between the specified dates.

        Given two dates, this method returns the fraction of a year between these dates according to the convention. The result of this method will be negative if the first date is after the second date. The result is calculated using yearFraction(LocalDate, LocalDate, ScheduleInfo).

        Parameters:
        firstDate - the first date
        secondDate - the second date, which may be before the first date
        scheduleInfo - the schedule information
        Returns:
        the year fraction, may be negative
        Throws:
        UnsupportedOperationException - if the year fraction cannot be obtained
      • days

        int days​(LocalDate firstDate,
                 LocalDate secondDate)
        Calculates the number of days between the specified dates using the rules of this day count.

        A day count is typically defines as a count of days divided by a year estimate. This method returns the count of days, which is the numerator of the division. For example, the 'Act/Act' day count will return the actual number of days between the two dates, but the '30/360 ISDA' will return a value based on 30 day months.

        Parameters:
        firstDate - the first date
        secondDate - the second date, which may be before the first date
        Returns:
        the number of days, as determined by the day count
      • getName

        String getName()
        Gets the name that uniquely identifies this convention.

        This name is used in serialization and can be parsed using of(String).

        Specified by:
        getName in interface Named
        Returns:
        the unique name