public final class DaysAdjustment extends Object implements Resolvable<DateAdjuster>, org.joda.beans.ImmutableBean, Serializable
When processing dates in finance, the rules for adjusting a date by a number of days can be complex. This class represents those rules, which operate in two steps - addition followed by adjustment. There are two main ways to perform the addition:
ofCalendarDays() factory methods.
When adding a number of days to a date the addition is simple, no holidays or weekends apply.
For example, two days after Friday 15th August would be Sunday 17th, even though this is typically a weekend.
There are two steps in the calculation:
In step one, the number of days is added without skipping any dates.
In step two, the result of step one is optionally adjusted to be a business day
using a BusinessDayAdjustment.
This approach is triggered by using the ofBusinessDays() factory methods.
The distinction between business days, holidays and weekends is made using the specified holiday calendar.
There are two steps in the calculation:
In step one, the number of days is added using HolidayCalendar.shift(LocalDate, int).
In step two, the result of step one is optionally adjusted to be a business day
using a BusinessDayAdjustment.
At first glance, step two may seem pointless, as the result of step one will always be a valid business day. However, the step two adjustment allows the possibility of applying a different holiday calendar.
For example, a rule might have two parts: "first add 2 London business days, and then adjust the result to be a valid New York business day using the 'ModifiedFollowing' convention". Note that the holiday calendar differs in the two parts of the rule.
| Modifier and Type | Class and Description |
|---|---|
static class |
DaysAdjustment.Builder
The bean-builder for
DaysAdjustment. |
static class |
DaysAdjustment.Meta
The meta-bean for
DaysAdjustment. |
| Modifier and Type | Field and Description |
|---|---|
static DaysAdjustment |
NONE
An instance that performs no adjustment.
|
| Modifier and Type | Method and Description |
|---|---|
LocalDate |
adjust(LocalDate date,
ReferenceData refData)
Adjusts the date, adding the period in days using the holiday calendar
and then applying the business day adjustment.
|
static DaysAdjustment.Builder |
builder()
Returns a builder used to create an instance of the bean.
|
boolean |
equals(Object obj) |
BusinessDayAdjustment |
getAdjustment()
Gets the business day adjustment that is performed to the result of the addition.
|
HolidayCalendarId |
getCalendar()
Gets the holiday calendar that defines the meaning of a day when performing the addition.
|
int |
getDays()
Gets the number of days to be added.
|
HolidayCalendarId |
getResultCalendar()
Gets the holiday calendar that will be applied to the result.
|
int |
hashCode() |
static DaysAdjustment.Meta |
meta()
The meta-bean for
DaysAdjustment. |
DaysAdjustment.Meta |
metaBean() |
DaysAdjustment |
normalized()
Normalizes the adjustment.
|
static DaysAdjustment |
ofBusinessDays(int numberOfDays,
HolidayCalendarId holidayCalendar)
Obtains an instance that can adjust a date by a specific number of business days.
|
static DaysAdjustment |
ofBusinessDays(int numberOfDays,
HolidayCalendarId holidayCalendar,
BusinessDayAdjustment adjustment)
Obtains an instance that can adjust a date by a specific number of business days.
|
static DaysAdjustment |
ofCalendarDays(int numberOfDays)
Obtains an instance that can adjust a date by a specific number of calendar days.
|
static DaysAdjustment |
ofCalendarDays(int numberOfDays,
BusinessDayAdjustment adjustment)
Obtains an instance that can adjust a date by a specific number of calendar days.
|
DateAdjuster |
resolve(ReferenceData refData)
Resolves this adjustment using the specified reference data, returning an adjuster.
|
DaysAdjustment.Builder |
toBuilder()
Returns a builder that allows this bean to be mutated.
|
String |
toString()
Returns a string describing the adjustment.
|
public static final DaysAdjustment NONE
public static DaysAdjustment ofCalendarDays(int numberOfDays)
When adjusting a date, the specified number of calendar days is added. Holidays and weekends are not taken into account in the calculation.
No business day adjustment is applied to the result of the addition.
numberOfDays - the number of dayspublic static DaysAdjustment ofCalendarDays(int numberOfDays, BusinessDayAdjustment adjustment)
When adjusting a date, the specified number of calendar days is added. Holidays and weekends are not taken into account in the calculation.
The business day adjustment is applied to the result of the addition.
numberOfDays - the number of daysadjustment - the business day adjustment to apply to the result of the additionpublic static DaysAdjustment ofBusinessDays(int numberOfDays, HolidayCalendarId holidayCalendar)
When adjusting a date, the specified number of business days is added. This is equivalent to repeatedly finding the next business day.
No business day adjustment is applied to the result of the addition.
If the input is a holiday, the first business day counted will be the next business day. If the input is a holiday and the number of days to add is zero, the result will be the next business day.
numberOfDays - the number of daysholidayCalendar - the calendar that defines holidays and business dayspublic static DaysAdjustment ofBusinessDays(int numberOfDays, HolidayCalendarId holidayCalendar, BusinessDayAdjustment adjustment)
When adjusting a date, the specified number of business days is added. This is equivalent to repeatedly finding the next business day.
The business day adjustment is applied to the result of the addition.
numberOfDays - the number of daysholidayCalendar - the calendar that defines holidays and business daysadjustment - the business day adjustment to apply to the result of the additionpublic LocalDate adjust(LocalDate date, ReferenceData refData)
The calculation is performed in two steps.
Step one, use HolidayCalendar.shift(LocalDate, int) to add the number of days.
If the holiday calendar is 'None' this will effectively add calendar days.
Step two, use BusinessDayAdjustment.adjust(LocalDate, ReferenceData) to adjust the result of step one.
date - the date to adjustrefData - the reference data, used to find the holiday calendarpublic DateAdjuster resolve(ReferenceData refData)
This returns a DateAdjuster that performs the same calculation as this adjustment.
It binds the holiday calendar, looked up from the reference data, into the result.
As such, there is no need to pass the reference data in again.
The resulting adjuster will be normalized.
resolve in interface Resolvable<DateAdjuster>refData - the reference data, used to find the holiday calendarpublic HolidayCalendarId getResultCalendar()
This adjustment may contain more than one holiday calendar. This method returns the calendar used last. As such, the adjusted date will always be valid according to this calendar.
public DaysAdjustment normalized()
If the number of days is zero, the calendar is set no 'NoHolidays'. If the number of days is non-zero and the calendar equals the adjustment calendar, the adjustment is removed.
public String toString()
public static DaysAdjustment.Meta meta()
DaysAdjustment.public static DaysAdjustment.Builder builder()
public DaysAdjustment.Meta metaBean()
metaBean in interface org.joda.beans.Beanpublic int getDays()
When the adjustment is performed, this amount will be added to the input date using the calendar to determine the addition type.
public HolidayCalendarId getCalendar()
When the adjustment is performed, this calendar is used to determine which days are business days.
If the holiday calendar is 'None' then addition uses simple date addition arithmetic without considering any days as holidays or weekends. If the holiday calendar is anything other than 'None' then addition uses that calendar, effectively repeatedly finding the next business day.
See the class-level documentation for more information.
public BusinessDayAdjustment getAdjustment()
This adjustment is applied to the result of the period addition calculation. If the addition is performed using business days then any adjustment here is expected to have a different holiday calendar to that used during addition.
If no adjustment is required, use the 'None' business day adjustment.
See the class-level documentation for more information.
public DaysAdjustment.Builder toBuilder()
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.