Class BusinessCalendar

java.lang.Object
com.quantfinlib.rates.BusinessCalendar

public final class BusinessCalendar extends Object
Business-day calendar: weekends plus a holiday set, with the standard roll conventions, settlement-lag arithmetic, and coupon schedule generation.

Why this is a finance class and not a util: cash cannot move on a day the payment system is closed, so every real-world date in a trade (the settlement date, spot = trade + 2 business days in most FX pairs and T+1 for US equities; each coupon date; an option expiry) must land on a business day, and which way a weekend date rolls changes the accrual period and therefore the payment (DayCount then converts the rolled dates to a year fraction). MODIFIED_FOLLOWING (roll forward unless that crosses month-end, then backward) is the near-universal swap convention precisely because plain following would occasionally push a month's payment into the next month and break month-bucketed accounting. A holiday missing from the set silently shifts settlement by a day: the classic source of small unexplained cash breaks between two systems that disagree about, say, Whit Monday.

  • Method Details

    • weekendsOnly

      public static BusinessCalendar weekendsOnly()
    • withHolidays

      public static BusinessCalendar withHolidays(Set<LocalDate> holidays)
    • withHolidays

      public static BusinessCalendar withHolidays(LocalDate... holidays)
    • union

      public BusinessCalendar union(BusinessCalendar other)
      The joint calendar of two trading centers: a day is a business day only when it is one in both (holiday sets union). This is the FX settlement rule — one calendar object, so every roll convention and schedule helper works unchanged on the pair, instead of each caller re-implementing dual-calendar walks.
    • isBusinessDay

      public boolean isBusinessDay(LocalDate date)
    • roll

      public LocalDate roll(LocalDate date, BusinessCalendar.Roll convention)
      Applies the roll convention to a date.
    • addBusinessDays

      public LocalDate addBusinessDays(LocalDate date, int n)
      Adds n >= 0 business days — e.g. T+2 settlement from a trade date.
    • subtractBusinessDays

      public LocalDate subtractBusinessDays(LocalDate date, int n)
      Walks back n >= 0 business days — e.g. a fixing lag before settlement.
    • schedule

      public List<LocalDate> schedule(LocalDate effectiveDate, LocalDate maturity, int paymentsPerYear, BusinessCalendar.Roll convention)
      Coupon payment schedule: unadjusted dates generated backward from maturity every 12/paymentsPerYear months (short front stub, no end-of-month rule), then rolled. Returns the adjusted payment dates strictly after effectiveDate, ascending (last = adjusted maturity).
    • schedule

      public List<LocalDate> schedule(LocalDate effectiveDate, LocalDate maturity, int paymentsPerYear, BusinessCalendar.Roll convention, BusinessCalendar.StubType stub, boolean endOfMonth)
      As schedule(LocalDate, LocalDate, int, Roll) with a stub type and EOM rule.
    • unadjustedSchedule

      public static List<LocalDate> unadjustedSchedule(LocalDate effectiveDate, LocalDate maturity, int paymentsPerYear)
      Unadjusted coupon dates strictly after effectiveDate: short front stub, no EOM rule.
    • unadjustedSchedule

      public static List<LocalDate> unadjustedSchedule(LocalDate effectiveDate, LocalDate maturity, int paymentsPerYear, BusinessCalendar.StubType stub, boolean endOfMonth)
      Unadjusted (theoretical) period end dates strictly after effectiveDate, ascending, the last one being maturity (or, for back stubs, also maturity).

      Every date is computed from the fixed anchor (maturity for front stubs, the effective date for back stubs) as anchor ± k·months, never by stepping from the previous date: LocalDate.minusMonths(long) clamps the day of month, and stepping would carry a clamp forward (31 Aug, 28 Feb, then 28 Aug instead of 31 Aug).

      With endOfMonth and an anchor on the last day of its month, every generated date is moved to the last day of its month (the EOM rule used for bonds and swaps; a 28 Feb 2027 maturity then pays on 31 Aug, not 28 Aug).

    • shiftMonths

      public static LocalDate shiftMonths(LocalDate anchor, long months, boolean endOfMonth)
      anchor shifted by months; with endOfMonth and an anchor on its month's last day, the result is the last day of its month.