Class SchedulePeriod
- java.lang.Object
-
- com.opengamma.strata.basics.schedule.SchedulePeriod
-
- All Implemented Interfaces:
Serializable
,Comparable<SchedulePeriod>
,org.joda.beans.Bean
,org.joda.beans.ImmutableBean
public final class SchedulePeriod extends Object implements org.joda.beans.ImmutableBean, Comparable<SchedulePeriod>, Serializable
A period in a schedule.This consists of a single period (date range) within a schedule. This is typically used as the basis for financial calculations, such as accrual of interest.
Two pairs of dates are provided, start/end and unadjustedStart/unadjustedEnd. The period itself runs from
startDate
toendDate
. TheunadjustedStartDate
andunadjustedEndDate
are the dates used to calculate thestartDate
andendDate
when applying business day adjustment.For example, consider a schedule that has periods every three months on the 10th of the month. From time to time, the scheduled date will be a weekend or holiday. In this case, a rule may apply moving the date to a valid business day. If this happens, then the "unadjusted" date is the original date in the periodic schedule and the "adjusted" date is the related valid business day. Note that not all schedules apply a business day adjustment.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SchedulePeriod.Builder
The bean-builder forSchedulePeriod
.static class
SchedulePeriod.Meta
The meta-bean forSchedulePeriod
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SchedulePeriod.Builder
builder()
Returns a builder used to create an instance of the bean.int
compareTo(SchedulePeriod other)
Compares this period to another by unadjusted start date, then unadjusted end date.boolean
contains(LocalDate date)
Checks if this period contains the specified date.boolean
equals(Object obj)
LocalDate
getEndDate()
Gets the end date of this period, used for financial calculations such as interest accrual.LocalDate
getStartDate()
Gets the start date of this period, used for financial calculations such as interest accrual.LocalDate
getUnadjustedEndDate()
Gets the unadjusted end date.LocalDate
getUnadjustedStartDate()
Gets the unadjusted start date.int
hashCode()
boolean
isRegular(Frequency frequency, RollConvention rollConvention)
Checks if this period is regular according to the specified frequency and roll convention.Period
length()
Returns the length of the period.int
lengthInDays()
Calculates the number of days in the period.static SchedulePeriod.Meta
meta()
The meta-bean forSchedulePeriod
.SchedulePeriod.Meta
metaBean()
static SchedulePeriod
of(LocalDate startDate, LocalDate endDate)
Obtains an instance from two dates.static SchedulePeriod
of(LocalDate startDate, LocalDate endDate, LocalDate unadjustedStartDate, LocalDate unadjustedEndDate)
Obtains an instance from the adjusted and unadjusted dates.PeriodicSchedule
subSchedule(Frequency frequency, RollConvention rollConvention, StubConvention stubConvention, BusinessDayAdjustment adjustment)
Creates a sub-schedule within this period.SchedulePeriod
toAdjusted(DateAdjuster adjuster)
Converts this period to one where the start and end dates are adjusted using the specified adjuster.SchedulePeriod.Builder
toBuilder()
Returns a builder that allows this bean to be mutated.String
toString()
SchedulePeriod
toUnadjusted()
Converts this period to one where the start and end dates are set to the unadjusted dates.double
yearFraction(DayCount dayCount, Schedule schedule)
Calculates the year fraction using the specified day count.
-
-
-
Method Detail
-
of
public static SchedulePeriod of(LocalDate startDate, LocalDate endDate, LocalDate unadjustedStartDate, LocalDate unadjustedEndDate)
Obtains an instance from the adjusted and unadjusted dates.- Parameters:
startDate
- the start date, used for financial calculations such as interest accrualendDate
- the end date, used for financial calculations such as interest accrualunadjustedStartDate
- the unadjusted start dateunadjustedEndDate
- the adjusted end date- Returns:
- the period
-
of
public static SchedulePeriod of(LocalDate startDate, LocalDate endDate)
Obtains an instance from two dates.This factory is used when there is no business day adjustment of schedule dates.
- Parameters:
startDate
- the start date, used for financial calculations such as interest accrualendDate
- the end date, used for financial calculations such as interest accrual- Returns:
- the period
-
length
public Period length()
Returns the length of the period.This returns the length of the period, considering the adjusted start and end dates. The calculation does not involve a day count or holiday calendar. The period is calculated using
Period.between(LocalDate, LocalDate)
and as such includes the start date and excludes the end date.- Returns:
- the length of the period
-
lengthInDays
public int lengthInDays()
Calculates the number of days in the period.This returns the actual number of days in the period, considering the adjusted start and end dates. The calculation does not involve a day count or holiday calendar. The length includes one date and excludes the other.
- Returns:
- the actual number of days in the period
-
yearFraction
public double yearFraction(DayCount dayCount, Schedule schedule)
Calculates the year fraction using the specified day count.Additional information from the schedule is made available to the day count algorithm.
- Parameters:
dayCount
- the day count conventionschedule
- the schedule that contains this period- Returns:
- the year fraction, calculated via the day count
-
isRegular
public boolean isRegular(Frequency frequency, RollConvention rollConvention)
Checks if this period is regular according to the specified frequency and roll convention.A schedule period is normally created from a frequency and roll convention. These can therefore be used to determine if the period is regular, which simply means that the period end date can be generated from the start date and vice versa.
- Parameters:
frequency
- the frequencyrollConvention
- the roll convention- Returns:
- true if the period is regular
-
contains
public boolean contains(LocalDate date)
Checks if this period contains the specified date.The adjusted start and end dates are used in the comparison. The start date is included, the end date is excluded.
- Parameters:
date
- the date to check- Returns:
- true if this period contains the date
-
subSchedule
public PeriodicSchedule subSchedule(Frequency frequency, RollConvention rollConvention, StubConvention stubConvention, BusinessDayAdjustment adjustment)
Creates a sub-schedule within this period.The sub-schedule will have the one or more periods. The schedule is bounded by the unadjusted start and end date of this period. The frequency and roll convention are used to build unadjusted schedule dates. The stub convention is used to handle any remaining time when the new frequency does not evenly divide into the period.
- Parameters:
frequency
- the frequency of the sub-schedulerollConvention
- the roll convention to use for rollingstubConvention
- the stub convention to use for any excessadjustment
- the business day adjustment to apply to the sub-schedule- Returns:
- the sub-schedule
- Throws:
ScheduleException
- if the schedule cannot be created
-
toAdjusted
public SchedulePeriod toAdjusted(DateAdjuster adjuster)
Converts this period to one where the start and end dates are adjusted using the specified adjuster.The start date of the result will be the start date of this period as altered by the specified adjuster. The end date of the result will be the end date of this period as altered by the specified adjuster. The unadjusted start date and unadjusted end date will be the same as in this period.
The adjuster will typically be obtained from
BusinessDayAdjustment.resolve(ReferenceData)
.- Parameters:
adjuster
- the adjuster to use- Returns:
- the adjusted schedule period
- Throws:
IllegalArgumentException
- if a period is invalid once adjusted
-
toUnadjusted
public SchedulePeriod toUnadjusted()
Converts this period to one where the start and end dates are set to the unadjusted dates.The start date of the result will be the unadjusted start date of this period. The end date of the result will be the unadjusted end date of this period. The unadjusted start date and unadjusted end date will be the same as in this period.
- Returns:
- the unadjusted schedule period
-
compareTo
public int compareTo(SchedulePeriod other)
Compares this period to another by unadjusted start date, then unadjusted end date.- Specified by:
compareTo
in interfaceComparable<SchedulePeriod>
- Parameters:
other
- the other period- Returns:
- the comparison value
-
meta
public static SchedulePeriod.Meta meta()
The meta-bean forSchedulePeriod
.- Returns:
- the meta-bean, not null
-
builder
public static SchedulePeriod.Builder builder()
Returns a builder used to create an instance of the bean.- Returns:
- the builder, not null
-
metaBean
public SchedulePeriod.Meta metaBean()
- Specified by:
metaBean
in interfaceorg.joda.beans.Bean
-
getStartDate
public LocalDate getStartDate()
Gets the start date of this period, used for financial calculations such as interest accrual.The first date in the schedule period, typically treated as inclusive. If the schedule adjusts for business days, then this is the adjusted date.
- Returns:
- the value of the property, not null
-
getEndDate
public LocalDate getEndDate()
Gets the end date of this period, used for financial calculations such as interest accrual.The last date in the schedule period, typically treated as exclusive. If the schedule adjusts for business days, then this is the adjusted date.
- Returns:
- the value of the property, not null
-
getUnadjustedStartDate
public LocalDate getUnadjustedStartDate()
Gets the unadjusted start date.The start date before any business day adjustment. If the schedule adjusts for business days, then this is typically the regular periodic date. If the schedule does not adjust for business days, then this is the same as the start date.
When building, this will default to the start date if not specified.
- Returns:
- the value of the property, not null
-
getUnadjustedEndDate
public LocalDate getUnadjustedEndDate()
Gets the unadjusted end date.The end date before any business day adjustment. If the schedule adjusts for business days, then this is typically the regular periodic date. If the schedule does not adjust for business days, then this is the same as the end date.
When building, this will default to the end date if not specified.
- Returns:
- the value of the property, not null
-
toBuilder
public SchedulePeriod.Builder toBuilder()
Returns a builder that allows this bean to be mutated.- Returns:
- the mutable builder, not null
-
-