Lamma I/O

Lamma Date

Your ultimate date generation solution for Java / Scala

Basic date manipulation

Date(2014, 7, 2) + 3  // result: Date(2014, 7, 5)

Date(2014, 7, 8) - Date(2014, 7, 2)  // result: 6

Date(2014, 7, 8) > Date(2014, 7, 2) // result: true
Date(2014, 7, 2).plusDays(3);  // result: Date(2014, 7, 5)

Date(2014, 7, 8).minus(Date(2014, 7, 2));  // result: 6

Date(2014, 7, 8).isAfter(Date(2014, 7, 2)); // result: true

Advanced dates generation

Date(2014, 1, 1) to Date(2014, 1, 30) by 10 except Weekends
import static io.lamma.LammaJavaImports.*;

Dates.from(2014, 1, 1).to(2014, 1, 30).byDays(10).except(weekends()).build(); 

Result:

List(Date(2014,1,1), Date(2014,1,21)) // Date(2014, 1, 11) is not in the list because it's a weekend

Professional schedule generation

Generate coupon schedule for following FCN:

  • Tenor: 37 months
  • Issue Date: 2014-03-01
  • Expiry Date: 2017-03-31 // merge last stub period
  • Frequency: every 6 months (semi-annual)
  • Coupon Date: Last day of month, modified following (last working day of the month)
  • Settlement Date: Coupon Date + 2 working days
Got it!
// a real business calendar will be used in production
val calendar = WeekendCalendar
// coupon date = end date of each generated period, modified following convention
val couponDate = DateDef("CouponDate", relativeTo = PeriodEnd, selector = ModifiedFollowing(calendar))
// settlement date = coupon date + 2 working days with the same calendar
val settlementDate = DateDef("SettlementDate", relativeTo = OtherDate("CouponDate"), shifter = ShiftWorkingDays(2, calendar))

Schedule(start = Date(2014, 3, 1),   // issue date = 2014-03-01
         end = Date(2017, 3, 31),    // expiry date = 2017-03-31
         pattern = Months(6, LastDayOfMonth),    // recurring the last day of every 6 months
         periodBuilder = StubRulePeriodBuilder(endRule = LongEnd(270)),  // merge last stub if the merged period is no longer than 270 days
         dateDefs = couponDate :: settlementDate :: Nil    // generate coupon date and settlement date for each period
)
// a real business calendar will be used in production
Calendar cal = weekendCalendar();
// coupon date = end date of each generated period, modified following convention
DateDef couponDate = dateDef("CouponDate", periodEnd(), modifiedFollowing(cal));
// settlement date = coupon date + 2 working days with the same calendar
DateDef settlementDate = dateDef("SettlementDate", otherDate("CouponDate"), shiftWorkingDays(2, cal));

// io.lamma.Lamma4j is used here instead of Lamma, it's a Java wrapper of the scala library (hide nasty things)
Schedule4j result = Lamma4j.schedule(
    date(2014, 3, 1),             // issue date = 2014-03-01
    date(2017, 3, 31),            // expiry date = 2017-03-31
    months(6, lastDayOfMonth()),      // recurring the last day of every 6 months
    stubRulePeriodBuilder(longEnd(270)),   // merge last stub if the merged period is no longer than 270 days
    list(couponDate, settlementDate));   // generate coupon date and settlement date for each period
Generated Schedule
Period From Date To Date CouponDate SettlementDate
1 2014-03-01 2014-08-31 12014-08-29 42014-09-02
2 2014-09-01 2015-02-28 12015-02-27 42015-03-03
3 2015-03-01 2015-08-31 2015-08-31 2015-09-02
4 2015-09-01 22016-02-29 22016-02-29 2016-03-02
5 2016-03-01 2016-08-31 2016-08-31 2016-09-02
6 2016-09-01 32017-03-31 2017-03-31 42017-04-04

What do you get?

  1. Modified Following convention is applied based on holiday calendar.
  2. Leap year is handled properly.
  3. End stub month (2017-03) is merged automatically to the last period.
  4. Non-working days are skipped when calculating settlement date from coupon date.

Want to give it a try?

Visit our quick start page.