net.objectlab.kit.datecalc.common
Interface DateCalculator<E>

Package class diagram package DateCalculator
Type Parameters:
E - a representation of a date, typically JDK: Date, Calendar; Joda:LocalDate, YearMonthDay
All Known Implementing Classes:
AbstractDateCalculator, CalendarDateCalculator, DateDateCalculator, LocalDateCalculator, YearMonthDayDateCalculator

public interface DateCalculator<E>

A DateCalculator is a lightweight container with an optional reference to a set of holidays, a WorkingWeek (Mon-Fri by default), a startDate and a current business date. The Calculator also uses a HolidayHandler to determine what to do when the calculated current Business Date falls on a weekend or holiday (non-working day). The CurrentDate date is changed everytime that the moveByDays or moveByBusinessDays methods are called. 'E' will be parameterized to be a Date-like class, i.e. java.util.Date or java.util.Calendar (and LocalDate or YearMonthDay for Joda-time).

Version:
$Revision: 334 $ $Date: 2010-03-30 07:06:50 -0400 (Tue, 30 Mar 2010) $
Author:
Benoit Xhenseval, $LastChangedBy: marchy $

Method Summary
 List<E> calculateTenorDates(List<Tenor> tenors)
          Calculate a series of Tenor codes in one go based on current day, this does NOT change the current business date.
 List<E> calculateTenorDates(List<Tenor> tenors, int spotLag)
          Calculate a series of Tenor codes in one go based on SPOT day (calculated with the spot lag), this does NOT change the current business date.
 DateCalculator<E> combine(DateCalculator<E> calculator)
          Allows DateCalculators to be combined into a new one, the startDate and currentBusinessDate will be the ones from the existing calendar (not the parameter one).
 E getCurrentBusinessDate()
          Gives the current business date held by the calculator.
 int getCurrentIncrement()
          return the current increment in the calculator, this is used by the handler.
 HolidayCalendar<E> getHolidayCalendar()
          Returns an immutable version of the HolidayCalendar.
 String getHolidayHandlerType()
          Gives the name of the holiday handler algorithm, see HolidayHandlerType for some standard values.
 String getName()
          This is typically the name of the associated set of holidays.
 E getStartDate()
          Gives the startDate of this calculator (immutable once set via setStartDate).
 boolean isCurrentDateNonWorking()
          Is the current business day a non-working day, this is useful if the calculator does not have any algorithm to change the date when it falls on a non-working day.
 boolean isNonWorkingDay(E date)
          Is the given date a non working day, i.e.
 boolean isWeekend(E date)
          Is the given date falling on a weekend, according to the WorkingWeek.
 DateCalculator<E> moveByBusinessDays(int businessDays)
          This changes the current business date held in the calculator, it moves the current date by a number of business days, this means that if a date is either a 'weekend' or holiday along the way, it will be skipped acording to the holiday handler and not count towards the number of days to move.
 DateCalculator<E> moveByDays(int days)
          This changes the current business date held in the calculator, it moves the new current business date by the number of days and, if it falls on a weekend or holiday, moves it further according to the HolidayHandler given in this DateCalculator.
 DateCalculator<E> moveByTenor(Tenor tenor)
          Move the current date by a given tenor, please note that all tenors are relative to the CURRENT day (and NOT from spot).
 DateCalculator<E> moveByTenor(Tenor tenor, int spotLag)
          Move the current date by a given tenor, please note that all tenors are relative to the SPOT day which is a number of days from the current date.
 E setCurrentBusinessDate(E date)
          Gives a current business date, it may be moved acording to the HolidayHandler algorithm if it falls on a non-working day.
 void setCurrentIncrement(int increment)
          This would be used by delegate methods to detect if the increment if positive or negative (this will allow us to define a Handler that can act as Forward if positive and Backward if negative).
 void setHolidayCalendar(HolidayCalendar<E> calendar)
          This is typically used at the construction of a DateCalculator to give a reference to a Holiday Calendar, if not the case, the calculator will make an immutable copy of the HolidayCalendar.
 void setStartDate(E startDate)
          Setting the start date also sets the current business date (and if this is a non-working day, the current business date will be moved to the next business day acording to the HolidayHandler algorithm given).
 void setWorkingWeek(WorkingWeek week)
          Allows user to define what their Working Week should be (default is Mon-Fri).
 

Method Detail

getName

String getName()
This is typically the name of the associated set of holidays.

Returns:
calculator name (Typically the name associated with the holiday set).

setStartDate

void setStartDate(E startDate)
Setting the start date also sets the current business date (and if this is a non-working day, the current business date will be moved to the next business day acording to the HolidayHandler algorithm given).

Parameters:
startDate - the reference date for this calculator, the current business date is also updated and may be moved if it falls on a non working day (holiday/weekend).

getStartDate

E getStartDate()
Gives the startDate of this calculator (immutable once set via setStartDate).

Returns:
startDate the reference date for this calculator.

getCurrentBusinessDate

E getCurrentBusinessDate()
Gives the current business date held by the calculator.

Returns:
a date.

isWeekend

boolean isWeekend(E date)
Is the given date falling on a weekend, according to the WorkingWeek.

Returns:
true if the date falls on a weekend.

isNonWorkingDay

boolean isNonWorkingDay(E date)
Is the given date a non working day, i.e. either a "weekend" or a holiday?

Returns:
true if the given date is non-working.

isCurrentDateNonWorking

boolean isCurrentDateNonWorking()
Is the current business day a non-working day, this is useful if the calculator does not have any algorithm to change the date when it falls on a non-working day. This method can then be used to show a warning to the user.

Returns:
true if the current date is either a weekend or a holiday.

setHolidayCalendar

void setHolidayCalendar(HolidayCalendar<E> calendar)
This is typically used at the construction of a DateCalculator to give a reference to a Holiday Calendar, if not the case, the calculator will make an immutable copy of the HolidayCalendar.

Parameters:
calendar - the holiday calendar (if null, no holidays taken into account)
Since:
1.1.0

getHolidayCalendar

HolidayCalendar<E> getHolidayCalendar()
Returns an immutable version of the HolidayCalendar.

Returns:
a copy of the holiday calendar
Since:
1.1.0

setWorkingWeek

void setWorkingWeek(WorkingWeek week)
Allows user to define what their Working Week should be (default is Mon-Fri).

Parameters:
week - an immutable definition of a week.

setCurrentBusinessDate

E setCurrentBusinessDate(E date)
Gives a current business date, it may be moved acording to the HolidayHandler algorithm if it falls on a non-working day.

Parameters:
date -
Returns:
new current business date if moved.

getHolidayHandlerType

String getHolidayHandlerType()
Gives the name of the holiday handler algorithm, see HolidayHandlerType for some standard values.

Returns:
the holiday handler type, can be null

moveByDays

DateCalculator<E> moveByDays(int days)
This changes the current business date held in the calculator, it moves the new current business date by the number of days and, if it falls on a weekend or holiday, moves it further according to the HolidayHandler given in this DateCalculator.

Parameters:
days - number of days (can be <0 or >0)
Returns:
the DateCalculator (so one can do calendar.moveByDays(-2).getCurrentBusinessDate();)

moveByBusinessDays

DateCalculator<E> moveByBusinessDays(int businessDays)
This changes the current business date held in the calculator, it moves the current date by a number of business days, this means that if a date is either a 'weekend' or holiday along the way, it will be skipped acording to the holiday handler and not count towards the number of days to move.

Parameters:
businessDays - (can be <0 or >0)
Returns:
the current DateCalculator (so one can do calendar.moveByBusinessDays(2).getCurrentBusinessDate();)
Throws:
IllegalArgumentException - if the HolidayHandlerType is (MODIFIED_PRECEDING or BACKWARD) and businessDays > 0 or (MODIFIED_FOLLOWING or FORWARD) and businessDays < 0

combine

DateCalculator<E> combine(DateCalculator<E> calculator)
Allows DateCalculators to be combined into a new one, the startDate and currentBusinessDate will be the ones from the existing calendar (not the parameter one). The name will be combined name1+"/"+calendar.getName(). If the Calendars have Early or Late boundaries, the result is the narrowest interval (e.g. the later Early boundary and the earliest Late boundary).

Parameters:
calculator - return the same DateCalculator if calender is null or the original calendar (but why would you want to do that?)
Throws:
IllegalArgumentException - if both calendars have different types of HolidayHandlers or WorkingWeek; Also, it is required that BOTH calendars either have Early/Late Boundaries or none.

moveByTenor

DateCalculator<E> moveByTenor(Tenor tenor,
                              int spotLag)
Move the current date by a given tenor, please note that all tenors are relative to the SPOT day which is a number of days from the current date. This method therefore, calculates the SPOT day first, moves it if it falls on a holiday and then goes to the calculated day according to the Tenor.

Parameters:
tenor - the Tenor to reach.
spotLag - number of days to "spot" days, this can vary from one market to the other. It is sometimes called "settlement interval" or "offset".
Returns:
the current DateCalculator

moveByTenor

DateCalculator<E> moveByTenor(Tenor tenor)
Move the current date by a given tenor, please note that all tenors are relative to the CURRENT day (and NOT from spot).

Parameters:
tenor - the Tenor to reach.
Returns:
the current DateCalculator
Since:
1.1.0

calculateTenorDates

List<E> calculateTenorDates(List<Tenor> tenors)
Calculate a series of Tenor codes in one go based on current day, this does NOT change the current business date.

Returns:
list of dates in same order as tenors.
Since:
1.1.0

calculateTenorDates

List<E> calculateTenorDates(List<Tenor> tenors,
                            int spotLag)
Calculate a series of Tenor codes in one go based on SPOT day (calculated with the spot lag), this does NOT change the current business date.

Returns:
list of dates in same order as tenors.
Since:
1.1.0

getCurrentIncrement

int getCurrentIncrement()
return the current increment in the calculator, this is used by the handler.


setCurrentIncrement

void setCurrentIncrement(int increment)
This would be used by delegate methods to detect if the increment if positive or negative (this will allow us to define a Handler that can act as Forward if positive and Backward if negative).

Parameters:
increment -


Copyright © 2006-2010 Appendium - Portfolio Financing Platform. All Rights Reserved.