public interface DayCount extends Named
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.
| Modifier and Type | Interface and Description |
|---|---|
static interface |
DayCount.ScheduleInfo
Information about the schedule necessary to calculate the day count.
|
| Modifier and Type | Method and Description |
|---|---|
int |
days(LocalDate firstDate,
LocalDate secondDate)
Calculates the number of days between the specified dates using the rules of this day count.
|
static ExtendedEnum<DayCount> |
extendedEnum()
Gets the extended enum helper.
|
String |
getName()
Gets the name that uniquely identifies this convention.
|
static DayCount |
of(String uniqueName)
Obtains an instance from the specified unique name.
|
static DayCount |
ofBus252(HolidayCalendarId calendar)
Obtains an instance of the 'Bus/252' day count based on a specific calendar.
|
default double |
relativeYearFraction(LocalDate firstDate,
LocalDate secondDate)
Gets the relative year fraction between the specified dates.
|
default double |
relativeYearFraction(LocalDate firstDate,
LocalDate secondDate,
DayCount.ScheduleInfo scheduleInfo)
Gets the relative year fraction between the specified dates.
|
default double |
yearFraction(LocalDate firstDate,
LocalDate secondDate)
Gets the year fraction between the specified dates.
|
double |
yearFraction(LocalDate firstDate,
LocalDate secondDate,
DayCount.ScheduleInfo scheduleInfo)
Gets the year fraction between the specified dates.
|
static DayCount of(String uniqueName)
uniqueName - the unique nameIllegalArgumentException - if the name is not knownstatic DayCount ofBus252(HolidayCalendarId 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.
calendar - the holiday calendarstatic ExtendedEnum<DayCount> extendedEnum()
This helper allows instances of the day count to be looked up. It also provides the complete set of available instances.
default double yearFraction(LocalDate firstDate, LocalDate secondDate)
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.
firstDate - the first datesecondDate - the second date, on or after the first dateIllegalArgumentException - if the dates are not in orderUnsupportedOperationException - if the year fraction cannot be obtaineddouble yearFraction(LocalDate firstDate, LocalDate secondDate, DayCount.ScheduleInfo scheduleInfo)
Given two dates, this method returns the fraction of a year between these dates according to the convention. The dates must be in order.
firstDate - the first datesecondDate - the second date, on or after the first datescheduleInfo - the schedule informationIllegalArgumentException - if the dates are not in orderUnsupportedOperationException - if the year fraction cannot be obtaineddefault double relativeYearFraction(LocalDate firstDate, LocalDate secondDate)
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.
firstDate - the first datesecondDate - the second date, which may be before the first dateUnsupportedOperationException - if the year fraction cannot be obtaineddefault double relativeYearFraction(LocalDate firstDate, LocalDate secondDate, DayCount.ScheduleInfo scheduleInfo)
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).
firstDate - the first datesecondDate - the second date, which may be before the first datescheduleInfo - the schedule informationUnsupportedOperationException - if the year fraction cannot be obtainedint days(LocalDate firstDate, LocalDate secondDate)
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.
firstDate - the first datesecondDate - the second date, which may be before the first dateString getName()
This name is used in serialization and can be parsed using of(String).
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.