def test_Calendar():

    set_date_format(DateFormatTypes.US_LONGEST)
    end_date = Date(31, 12, 2030)

    for calendar_type in CalendarTypes:

        testCases.banner("================================")
        testCases.banner("================================")

        testCases.header("CALENDAR", "HOLIDAY")
        testCases.print("STARTING", calendar_type)

        cal = Calendar(calendar_type)
        next_date = Date(31, 12, 2020)

        while next_date < end_date:
            next_date = next_date.add_days(1)

            if next_date._d == 1 and next_date._m == 1:
                testCases.banner("================================")
#                print("=========================")

            is_holidayDay = cal.is_holiday(next_date)
            if is_holidayDay is True:
                testCases.print(cal, next_date)
#                print(cal, next_date)

    set_date_format(DateFormatTypes.US_LONG)
def test_add_business_day():
    for calendar_type in CalendarTypes:
        num_days = bus_days_in_decade[str(calendar_type)]
        cal = Calendar(calendar_type)
        start = Date(3, 1, 2020)
        end = Date(3, 1, 2030)

        assert cal.add_business_days(start, num_days) == end, \
            f"Landed on incorrect business day using {calendar_type}"
Exemple #3
0
def test_FinScheduleAlignment(eomFlag):

    valuation_date = Date(29, 3, 2005)
    effDate = valuation_date.add_tenor("2d")
    freq_type = FrequencyTypes.SEMI_ANNUAL
    bus_day_adjust_type = BusDayAdjustTypes.MODIFIED_FOLLOWING
    date_gen_rule_type = DateGenRuleTypes.BACKWARD
    calendar_type = CalendarTypes.UNITED_STATES
    adjust_termination_date = False

    matDate1 = effDate.add_tenor("4Y")
    matDate2 = effDate.add_tenor("50Y")

#    print(matDate1)
#    print(matDate2)

    myCal = Calendar(calendar_type)

    adjustedMatDate1 = myCal.adjust(matDate1, bus_day_adjust_type)
    adjustedMatDate2 = myCal.adjust(matDate2, bus_day_adjust_type)

#    print(adjustedMatDate1)
#    print(adjustedMatDate2)

    sched1 = Schedule(effDate,
                      adjustedMatDate1,
                      freq_type,
                      calendar_type,
                      bus_day_adjust_type,
                      date_gen_rule_type,
                      adjust_termination_date,
                      eomFlag)

#    print(sched1)

    sched2 = Schedule(effDate,
                      adjustedMatDate2,
                      freq_type,
                      calendar_type,
                      bus_day_adjust_type,
                      date_gen_rule_type,
                      adjust_termination_date,
                      eomFlag)

    compare = (
        sched1._adjusted_dates[-1] == sched2._adjusted_dates[len(sched1._adjusted_dates)-1])
    assert(compare == eomFlag)