public interface DateSequence extends Named
This interface encapsulates a sequence of dates as used in standard financial instruments. The most common are the quarterly IMM dates, which are on the third Wednesday of March, June, September and December.
The most common implementations are provided in DateSequences.
Note that the dates produced by the sequence may not be business days. The application of a holiday calendar is typically the responsibility of the caller.
All implementations of this interface must be immutable and thread-safe.
| Modifier and Type | Method and Description |
|---|---|
default DateSequence |
baseSequence()
Returns the simpler "base" sequence underlying this one.
|
LocalDate |
dateMatching(YearMonth yearMonth)
Finds the date in the sequence that corresponds to the specified year-month.
|
static ExtendedEnum<DateSequence> |
extendedEnum()
Gets the extended enum helper.
|
String |
getName()
Gets the name that uniquely identifies this sequence.
|
default LocalDate |
next(LocalDate date)
Finds the next date in the sequence, always returning a date later than the input date.
|
LocalDate |
nextOrSame(LocalDate date)
Finds the next date in the sequence, returning the input date if it is a date in the sequence.
|
default LocalDate |
nth(LocalDate date,
int sequenceNumber)
Finds the nth date in the sequence after the input date,
always returning a date later than the input date.
|
default LocalDate |
nthOrSame(LocalDate date,
int sequenceNumber)
Finds the nth date in the sequence on or after the input date,
returning the input date if it is a date in the sequence.
|
static DateSequence |
of(String uniqueName)
Obtains an instance from the specified unique name.
|
default LocalDate |
selectDate(LocalDate inputDate,
SequenceDate sequenceDate)
Selects a date from the sequence.
|
default LocalDate |
selectDateOrSame(LocalDate inputDate,
SequenceDate sequenceDate)
Selects a date from the sequence.
|
static DateSequence of(String uniqueName)
uniqueName - the unique nameIllegalArgumentException - if the name is not knownstatic ExtendedEnum<DateSequence> extendedEnum()
This helper allows instances of the sequence to be looked up. It also provides the complete set of available instances.
default DateSequence baseSequence()
Many date sequences have two interlinked sequences. One is considered to be the base sequence, the other is considered to be the full sequence.
For example, the "base sequence" of a future is often March, June, September and December. But additionally, the nearest two "serial" months are also listed. Together these make the "full sequence".
If this instance represents the "full sequence", this method returns the "base sequence".
If this instance represents the "base sequence", or there is no "base sequence", this method returns this.
default LocalDate next(LocalDate date)
Given an input date, this method returns the next date after it from the sequence.
date - the input dateIllegalArgumentException - if there are no more sequence datesLocalDate nextOrSame(LocalDate date)
Given an input date, this method returns a date from the sequence. If the input date is in the sequence, it is returned. Otherwise, the next date in the sequence after the input date is returned.
date - the input dateIllegalArgumentException - if there are no more sequence datesdefault LocalDate nth(LocalDate date, int sequenceNumber)
Given an input date, this method returns a date from the sequence. If the sequence number is 1, then the first date in the sequence after the input date is returned.
If the sequence number is 2 or larger, then the date referred to by sequence number 1 is calculated, and the nth matching sequence date after that date returned.
date - the input datesequenceNumber - the 1-based index of the date to findIllegalArgumentException - if the sequence number is zero or negative or if there are no more sequence datesdefault LocalDate nthOrSame(LocalDate date, int sequenceNumber)
Given an input date, this method returns a date from the sequence. If the sequence number is 1, then either the input date or the first date in the sequence after the input date is returned.
If the sequence number is 2 or larger, then the date referred to by sequence number 1 is calculated, and the nth matching sequence date after that date returned.
date - the input datesequenceNumber - the 1-based index of the date to findIllegalArgumentException - if the sequence number is zero or negative or if there are no more sequence datesLocalDate dateMatching(YearMonth yearMonth)
Given an input month, this method returns the date from the sequence that is associated with the year-month. In most cases, the returned date will be in the same month as the input month, but this is not guaranteed.
yearMonth - the input year-monthIllegalArgumentException - if there are no more sequence datesdefault LocalDate selectDate(LocalDate inputDate, SequenceDate sequenceDate)
Given an input date, this uses the SequenceDate to select a single matching date from the sequence.
If the SequenceDate specifies a year-month, the match starts from the first date of the specified month.
Otherwise, the match starts from the day after the input date.
inputDate - the input datesequenceDate - the instructions specifying which date to selectIllegalArgumentException - if there are no more sequence datesdefault LocalDate selectDateOrSame(LocalDate inputDate, SequenceDate sequenceDate)
Given an input date, this uses the SequenceDate to select a single matching date from the sequence.
If the SequenceDate specifies a year-month, the match starts from the first date of the specified month.
Otherwise, the match starts from the input date.
inputDate - the input datesequenceDate - the instructions specifying which date to selectIllegalArgumentException - if there are no more sequence datesString 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.