public final class Schedule extends Object implements DayCount.ScheduleInfo, org.joda.beans.ImmutableBean, Serializable
The schedule consists of one or more adjacent periods (date ranges). This is typically used as the basis for financial calculations, such as accrual of interest.
It is recommended to create a Schedule
using a PeriodicSchedule
.
Modifier and Type | Class and Description |
---|---|
static class |
Schedule.Builder
The bean-builder for
Schedule . |
static class |
Schedule.Meta
The meta-bean for
Schedule . |
Modifier and Type | Method and Description |
---|---|
static Schedule.Builder |
builder()
Returns a builder used to create an instance of the bean.
|
boolean |
equals(Object obj) |
LocalDate |
getEndDate()
Gets the end date of the schedule.
|
Optional<SchedulePeriod> |
getFinalStub()
Gets the final stub if it exists.
|
SchedulePeriod |
getFirstPeriod()
Gets the first schedule period.
|
Frequency |
getFrequency()
Gets the periodic frequency used when building the schedule.
|
Optional<SchedulePeriod> |
getInitialStub()
Gets the initial stub if it exists.
|
SchedulePeriod |
getLastPeriod()
Gets the last schedule period.
|
SchedulePeriod |
getPeriod(int index)
Gets a schedule period by index.
|
LocalDate |
getPeriodEndDate(LocalDate date)
Finds the period end date given a date in the period.
|
ImmutableList<SchedulePeriod> |
getPeriods()
Gets the schedule periods.
|
ImmutableList<SchedulePeriod> |
getRegularPeriods()
Gets the regular schedule periods.
|
RollConvention |
getRollConvention()
Gets the roll convention used when building the schedule.
|
LocalDate |
getStartDate()
Gets the start date of the schedule.
|
Pair<Optional<SchedulePeriod>,Optional<SchedulePeriod>> |
getStubs(boolean preferFinal)
Gets the stubs if they exist.
|
ImmutableList<LocalDate> |
getUnadjustedDates()
Gets the complete list of unadjusted dates.
|
LocalDate |
getUnadjustedEndDate()
Gets the unadjusted end date.
|
LocalDate |
getUnadjustedStartDate()
Gets the unadjusted start date.
|
int |
hashCode() |
boolean |
isEndOfMonthConvention()
Checks if the end of month convention is in use.
|
boolean |
isSinglePeriod()
Checks if this schedule has a single period.
|
boolean |
isTerm()
Checks if this schedule represents a single 'Term' period.
|
Schedule |
merge(int groupSize,
LocalDate firstRegularStartDate,
LocalDate lastRegularEndDate)
Merges this schedule to form a new schedule by combining the schedule periods.
|
Schedule |
mergeRegular(int groupSize,
boolean rollForwards)
Merges this schedule to form a new schedule by combining the regular schedule periods.
|
Schedule |
mergeToTerm()
Merges this schedule to form a new schedule with a single 'Term' period.
|
static Schedule.Meta |
meta()
The meta-bean for
Schedule . |
Schedule.Meta |
metaBean() |
static Schedule |
ofTerm(SchedulePeriod period)
Obtains a 'Term' instance based on a single period.
|
int |
size()
Gets the number of periods in the schedule.
|
Schedule |
toAdjusted(DateAdjuster adjuster)
Converts this schedule to a schedule where all the start and end dates are
adjusted using the specified adjuster.
|
Schedule.Builder |
toBuilder()
Returns a builder that allows this bean to be mutated.
|
String |
toString() |
Schedule |
toUnadjusted()
Converts this schedule to a schedule where every adjusted date is reset
to the unadjusted equivalent.
|
public static Schedule ofTerm(SchedulePeriod period)
A 'Term' schedule has one period with a frequency of 'Term'.
period
- the single periodpublic int size()
This returns the number of periods, which will be at least one.
public boolean isTerm()
A 'Term' schedule has one period and a frequency of 'Term'.
public boolean isSinglePeriod()
public SchedulePeriod getPeriod(int index)
This returns a period using a zero-based index.
index
- the zero-based period indexIndexOutOfBoundsException
- if the index is invalidpublic SchedulePeriod getFirstPeriod()
public SchedulePeriod getLastPeriod()
public LocalDate getStartDate()
The first date in the schedule, typically treated as inclusive. If the schedule adjusts for business days, then this is the adjusted date.
getStartDate
in interface DayCount.ScheduleInfo
public LocalDate getEndDate()
The last date in the schedule, typically treated as exclusive. If the schedule adjusts for business days, then this is the adjusted date.
getEndDate
in interface DayCount.ScheduleInfo
public LocalDate getUnadjustedStartDate()
The start date before any business day adjustment.
public LocalDate getUnadjustedEndDate()
The end date before any business day adjustment.
public Optional<SchedulePeriod> getInitialStub()
There is an initial stub if the first period is a stub and the frequency is not 'Term'.
A period will be allocated to one and only one of getInitialStub()
,
getRegularPeriods()
and getFinalStub()
.
public Optional<SchedulePeriod> getFinalStub()
There is a final stub if there is more than one period and the last period is a stub.
A period will be allocated to one and only one of getInitialStub()
,
getRegularPeriods()
and getFinalStub()
.
public Pair<Optional<SchedulePeriod>,Optional<SchedulePeriod>> getStubs(boolean preferFinal)
This method returns the initial and final stub. A flag is used to handle the case where there are no regular periods and it is unclear whether the stub is initial or final.
A period will be allocated to one and only one of getStubs(boolean)
and getRegularPeriods()
.
preferFinal
- true to prefer final if there is only one periodpublic ImmutableList<SchedulePeriod> getRegularPeriods()
The regular periods exclude any initial or final stub.
In most cases, the periods returned will be regular, corresponding to the periodic
frequency and roll convention, however there are cases when this is not true.
This includes the case where isTerm()
returns true.
See SchedulePeriod.isRegular(Frequency, RollConvention)
.
A period will be allocated to one and only one of getInitialStub()
,
getRegularPeriods()
and getFinalStub()
.
public ImmutableList<LocalDate> getUnadjustedDates()
This returns a list including all the unadjusted period boundary dates. This is the same as a list containing the unadjusted start date of the schedule followed by the unadjusted end date of each period.
public boolean isEndOfMonthConvention()
If true then when building a schedule, dates will be at the end-of-month if the first date in the series is at the end-of-month.
isEndOfMonthConvention
in interface DayCount.ScheduleInfo
public LocalDate getPeriodEndDate(LocalDate date)
The first matching period is returned. The adjusted start and end dates of each period are used in the comparison. The start date is included, the end date is excluded.
getPeriodEndDate
in interface DayCount.ScheduleInfo
date
- the date to findpublic Schedule mergeToTerm()
The result will have one period of type 'Term', with dates matching this schedule.
public Schedule merge(int groupSize, LocalDate firstRegularStartDate, LocalDate lastRegularEndDate)
This produces a schedule where some periods are merged together. For example, this could be used to convert a 3 monthly schedule into a 6 monthly schedule.
The merging is controlled by the group size, which defines the number of periods to merge together in the result. For example, to convert a 3 monthly schedule into a 6 monthly schedule the group size would be 2 (6 divided by 3).
A group size of zero or less will throw an exception. A group size of 1 will return this schedule providing that the specified start and end date match. A larger group size will return a schedule where each group of regular periods are merged.
The specified dates must be one of the dates of this schedule (unadjusted or adjusted). All periods of this schedule before the first regular start date, if any, will form a single period in the result. All periods of this schedule after the last regular start date, if any, will form a single period in the result. If this schedule has an initial or final stub, it may be merged with a regular period as part of the process.
For example, a schedule with an initial stub and 5 regular periods can be grouped by 2 if the
specified firstRegularStartDate
equals the end of the first regular period.
groupSize
- the group sizefirstRegularStartDate
- the unadjusted start date of the first regular payment periodlastRegularEndDate
- the unadjusted end date of the last regular payment periodIllegalArgumentException
- if the group size is zero or lessScheduleException
- if the merged schedule cannot be created because the dates don't
match this schedule or the regular periods don't match the grouping sizepublic Schedule mergeRegular(int groupSize, boolean rollForwards)
This produces a schedule where some periods are merged together. For example, this could be used to convert a 3 monthly schedule into a 6 monthly schedule.
The merging is controlled by the group size, which defines the number of periods to merge together in the result. For example, to convert a 3 monthly schedule into a 6 monthly schedule the group size would be 2 (6 divided by 3).
A group size of zero or less will throw an exception. A group size of 1 will return this schedule. A larger group size will return a schedule where each group of regular periods are merged. The roll flag is used to determine the direction in which grouping occurs.
Any existing stub periods are considered to be special, and are not merged. Even if the grouping results in an excess period, such as 10 periods with a group size of 3, the excess period will not be merged with a stub.
If this period is a 'Term' period, this schedule is returned.
groupSize
- the group sizerollForwards
- whether to roll forwards (true) or backwards (false)IllegalArgumentException
- if the group size is zero or lesspublic Schedule toAdjusted(DateAdjuster adjuster)
The result will have the same number of periods, but each start date and end date is replaced by the adjusted date as returned by the adjuster. The unadjusted start date and unadjusted end date of each period will not be changed.
adjuster
- the adjuster to usepublic Schedule toUnadjusted()
The result will have the same number of periods, but each start date and end date is replaced by the matching unadjusted start or end date.
public static Schedule.Meta meta()
Schedule
.public static Schedule.Builder builder()
public Schedule.Meta metaBean()
metaBean
in interface org.joda.beans.Bean
public ImmutableList<SchedulePeriod> getPeriods()
There will be at least one period. The periods are ordered from earliest to latest. It is intended that each period is adjacent to the next one, however each period is independent and non-adjacent periods are allowed.
public Frequency getFrequency()
If the schedule was not built from a regular periodic frequency, then the frequency should be a suitable estimate.
getFrequency
in interface DayCount.ScheduleInfo
public RollConvention getRollConvention()
If the schedule was not built from a regular periodic frequency, then the convention should be 'None'.
public Schedule.Builder toBuilder()
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.