Example #1
0
        public virtual void test_valid2()
        {
            ImmutableMap <string, HolidayCalendar> lookup = HolidayCalendarIniLookup.loadFromIni("HolidayCalendarDataValid2.ini");

            assertEquals(lookup.size(), 1);

            HolidayCalendar test = lookup.get("TEST-VALID");

            assertTrue(test.isHoliday(date(2015, 1, 1)));
            assertTrue(test.isHoliday(date(2015, 1, 6)));
            assertTrue(test.isHoliday(date(2015, 4, 5)));
            assertTrue(test.isHoliday(date(2015, 12, 25)));
            assertTrue(test.isHoliday(date(2016, 1, 1)));
            assertEquals(test.Name, "TEST-VALID");
            assertEquals(test.ToString(), "HolidayCalendar[TEST-VALID]");
        }
        //-------------------------------------------------------------------------
        public virtual void test_NO_HOLIDAYS()
        {
            HolidayCalendar test = HolidayCalendars.NO_HOLIDAYS;

            LocalDateUtils.stream(LocalDate.of(2011, 1, 1), LocalDate.of(2015, 1, 31)).forEach(date =>
            {
                assertEquals(test.isBusinessDay(date), true);
                assertEquals(test.isHoliday(date), false);
            });
            assertEquals(test.Name, "NoHolidays");
            assertEquals(test.ToString(), "HolidayCalendar[NoHolidays]");
        }
        //-------------------------------------------------------------------------
        public virtual void test_THU_FRI()
        {
            HolidayCalendar test = HolidayCalendars.THU_FRI;

            LocalDateUtils.stream(LocalDate.of(2011, 1, 1), LocalDate.of(2015, 1, 31)).forEach(date =>
            {
                bool isBusinessDay = date.DayOfWeek != THURSDAY && date.DayOfWeek != FRIDAY;
                assertEquals(test.isBusinessDay(date), isBusinessDay);
                assertEquals(test.isHoliday(date), !isBusinessDay);
            });
            assertEquals(test.Name, "Thu/Fri");
            assertEquals(test.ToString(), "HolidayCalendar[Thu/Fri]");
        }
        //-------------------------------------------------------------------------
        public virtual void test_FRI_SAT()
        {
            HolidayCalendar test = HolidayCalendars.FRI_SAT;

            LocalDateUtils.stream(LocalDate.of(2011, 1, 1), LocalDate.of(2015, 1, 31)).forEach(date =>
            {
                bool isBusinessDay = date.DayOfWeek != FRIDAY && date.DayOfWeek != SATURDAY;
                assertEquals(test.isBusinessDay(date), isBusinessDay);
                assertEquals(test.isHoliday(date), !isBusinessDay);
            });
            assertEquals(test.Name, "Fri/Sat");
            assertEquals(test.ToString(), "HolidayCalendar[Fri/Sat]");
        }
        //-------------------------------------------------------------------------
        public virtual void test_SAT_SUN()
        {
            HolidayCalendar test = HolidayCalendars.SAT_SUN;

            LocalDateUtils.stream(LocalDate.of(2011, 1, 1), LocalDate.of(2015, 1, 31)).forEach(date =>
            {
                bool isBusinessDay = date.DayOfWeek != SATURDAY && date.DayOfWeek != SUNDAY;
                assertEquals(test.isBusinessDay(date), isBusinessDay);
                assertEquals(test.isHoliday(date), !isBusinessDay);
            });
            assertEquals(test.Name, "Sat/Sun");
            assertEquals(test.ToString(), "HolidayCalendar[Sat/Sun]");
        }
        public LocalDate calculateFixingFromMaturity(LocalDate maturityDate, ReferenceData refData)
        {
            // handle case where the input date is not a valid maturity date
            LocalDate maturityBusinessDay = maturityDateCalendar().resolve(refData).nextOrSame(maturityDate);
            // find the fixing date iteratively
            HolidayCalendar fixingCal          = fixingCalendar.resolve(refData);
            DateAdjuster    maturityFromFixing = maturityDateOffset.resolve(refData);
            LocalDate       fixingDate         = maturityBusinessDay;

            while (fixingCal.isHoliday(fixingDate) || maturityFromFixing.adjust(fixingDate).isAfter(maturityBusinessDay))
            {
                fixingDate = fixingDate.minusDays(1);
            }
            return(fixingDate);
        }
        //-------------------------------------------------------------------------
        public virtual void test_combinedWith()
        {
            HolidayCalendar base1 = new MockHolCal();
            HolidayCalendar base2 = HolidayCalendars.FRI_SAT;
            HolidayCalendar test  = base1.combinedWith(base2);

            assertEquals(test.ToString(), "HolidayCalendar[Fri/Sat+Mock]");
            assertEquals(test.Name, "Fri/Sat+Mock");
            assertEquals(test.Equals(base1.combinedWith(base2)), true);
            assertEquals(test.Equals(ANOTHER_TYPE), false);
            assertEquals(test.Equals(null), false);
            assertEquals(test.GetHashCode(), base1.combinedWith(base2).GetHashCode());

            assertEquals(test.isHoliday(THU_2014_07_10), false);
            assertEquals(test.isHoliday(FRI_2014_07_11), true);
            assertEquals(test.isHoliday(SAT_2014_07_12), true);
            assertEquals(test.isHoliday(SUN_2014_07_13), true);
            assertEquals(test.isHoliday(MON_2014_07_14), false);
            assertEquals(test.isHoliday(TUE_2014_07_15), false);
            assertEquals(test.isHoliday(WED_2014_07_16), true);
            assertEquals(test.isHoliday(THU_2014_07_17), false);
            assertEquals(test.isHoliday(FRI_2014_07_18), true);
            assertEquals(test.isHoliday(SAT_2014_07_19), true);
            assertEquals(test.isHoliday(SUN_2014_07_20), true);
            assertEquals(test.isHoliday(MON_2014_07_21), false);
        }