public interface HolidayCalendar extends Named
Many calculations in finance require knowledge of whether a date is a business day or not. This class encapsulates that knowledge, with each day treated as a holiday or a business day. Weekends are effectively treated as a special kind of holiday.
Applications should refer to holidays using HolidayCalendarId
.
The identifier must be resolved
to a HolidayCalendar
before the holiday data methods can be accessed.
See HolidayCalendarIds
for a standard set of identifiers available in ReferenceData.standard()
.
All implementations of this interface must be immutable and thread-safe.
ImmutableHolidayCalendar
Modifier and Type | Method and Description |
---|---|
default TemporalAdjuster |
adjustBy(int amount)
Returns an adjuster that changes the date.
|
default Stream<LocalDate> |
businessDays(LocalDate startInclusive,
LocalDate endExclusive)
Gets the stream of business days between the two dates.
|
default HolidayCalendar |
combinedWith(HolidayCalendar other)
Combines this holiday calendar with another.
|
default int |
daysBetween(LocalDate startInclusive,
LocalDate endExclusive)
Calculates the number of business days between two dates.
|
HolidayCalendarId |
getId()
Gets the identifier for the calendar.
|
default String |
getName()
Gets the name that identifies this calendar.
|
default Stream<LocalDate> |
holidays(LocalDate startInclusive,
LocalDate endExclusive)
Gets the stream of holidays between the two dates.
|
default boolean |
isBusinessDay(LocalDate date)
Checks if the specified date is a business day.
|
boolean |
isHoliday(LocalDate date)
Checks if the specified date is a holiday.
|
default boolean |
isLastBusinessDayOfMonth(LocalDate date)
Checks if the specified date is the last business day of the month.
|
default LocalDate |
lastBusinessDayOfMonth(LocalDate date)
Calculates the last business day of the month.
|
default HolidayCalendar |
linkedWith(HolidayCalendar other)
Combines this holiday calendar with another.
|
default LocalDate |
next(LocalDate date)
Finds the next business day, always returning a later date.
|
default LocalDate |
nextOrSame(LocalDate date)
Finds the next business day, returning the input date if it is a business day.
|
default LocalDate |
nextSameOrLastInMonth(LocalDate date)
Finds the next business day within the month, returning the input date if it is a business day,
or the last business day of the month if the next business day is in a different month.
|
default LocalDate |
previous(LocalDate date)
Finds the previous business day, always returning an earlier date.
|
default LocalDate |
previousOrSame(LocalDate date)
Finds the previous business day, returning the input date if it is a business day.
|
default LocalDate |
shift(LocalDate date,
int amount)
Shifts the date by the specified number of business days.
|
boolean isHoliday(LocalDate date)
This is the opposite of isBusinessDay(LocalDate)
.
A weekend is treated as a holiday.
date
- the date to checkIllegalArgumentException
- if the date is outside the supported rangedefault boolean isBusinessDay(LocalDate date)
This is the opposite of isHoliday(LocalDate)
.
A weekend is treated as a holiday.
date
- the date to checkIllegalArgumentException
- if the date is outside the supported rangedefault TemporalAdjuster adjustBy(int amount)
The adjuster is intended to be used with the method Temporal.with(TemporalAdjuster)
.
For example:
threeDaysLater = date.with(businessDays.adjustBy(3)); twoDaysEarlier = date.with(businessDays.adjustBy(-2));
amount
- the number of business days to adjust byIllegalArgumentException
- if the calculation is outside the supported rangedefault LocalDate shift(LocalDate date, int amount)
If the amount is zero, the input date is returned. If the amount is positive, later business days are chosen. If the amount is negative, earlier business days are chosen.
date
- the date to adjustamount
- the number of business days to adjust byIllegalArgumentException
- if the calculation is outside the supported rangedefault LocalDate next(LocalDate date)
Given a date, this method returns the next business day.
date
- the date to adjustIllegalArgumentException
- if the calculation is outside the supported rangedefault LocalDate nextOrSame(LocalDate date)
Given a date, this method returns a business day. If the input date is a business day, it is returned. Otherwise, the next business day is returned.
date
- the date to adjustIllegalArgumentException
- if the calculation is outside the supported rangedefault LocalDate previous(LocalDate date)
Given a date, this method returns the previous business day.
date
- the date to adjustIllegalArgumentException
- if the calculation is outside the supported rangedefault LocalDate previousOrSame(LocalDate date)
Given a date, this method returns a business day. If the input date is a business day, it is returned. Otherwise, the previous business day is returned.
date
- the date to adjustIllegalArgumentException
- if the calculation is outside the supported rangedefault LocalDate nextSameOrLastInMonth(LocalDate date)
Given a date, this method returns a business day. If the input date is a business day, it is returned. If the next business day is within the same month, it is returned. Otherwise, the last business day of the month is returned.
Note that the result of this method may be earlier than the input date.
This corresponds to the modified following business day convention.
date
- the date to adjustIllegalArgumentException
- if the calculation is outside the supported rangedefault boolean isLastBusinessDayOfMonth(LocalDate date)
This returns true if the date specified is the last valid business day of the month.
date
- the date to checkIllegalArgumentException
- if the date is outside the supported rangedefault LocalDate lastBusinessDayOfMonth(LocalDate date)
Given a date, this method returns the date of the last business day of the month.
date
- the date to checkIllegalArgumentException
- if the date is outside the supported rangedefault int daysBetween(LocalDate startInclusive, LocalDate endExclusive)
This calculates the number of business days within the range. If the dates are equal, zero is returned. If the end is before the start, an exception is thrown.
startInclusive
- the start dateendExclusive
- the end dateIllegalArgumentException
- if either date is outside the supported rangedefault Stream<LocalDate> businessDays(LocalDate startInclusive, LocalDate endExclusive)
This method will treat weekends as holidays. If the dates are equal, an empty stream is returned. If the end is before the start, an exception is thrown.
startInclusive
- the start dateendExclusive
- the end dateIllegalArgumentException
- if either date is outside the supported rangedefault Stream<LocalDate> holidays(LocalDate startInclusive, LocalDate endExclusive)
This method will treat weekends as holidays. If the dates are equal, an empty stream is returned. If the end is before the start, an exception is thrown.
startInclusive
- the start dateendExclusive
- the end dateIllegalArgumentException
- if either date is outside the supported rangedefault HolidayCalendar combinedWith(HolidayCalendar other)
The resulting calendar will declare a day as a business day if it is a business day in both source calendars.
other
- the other holiday calendarIllegalArgumentException
- if unable to combine the calendarsdefault HolidayCalendar linkedWith(HolidayCalendar other)
The resulting calendar will declare a day as a business day if it is a business day in either source calendar.
other
- the other holiday calendarHolidayCalendarId getId()
This identifier is used to locate the index in ReferenceData
.
default String getName()
This is the name associated with the identifier.
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.