def test_Monthly_BondAnnuity(): settlement_date = Date(20, 6, 2018) face = 1000000 #Monthly Frequency maturity_date = Date(20, 6, 2028) coupon = 0.05 freq_type = FrequencyTypes.MONTHLY calendar_type = CalendarTypes.WEEKEND bus_day_adjust_type = BusDayAdjustTypes.FOLLOWING date_gen_rule_type = DateGenRuleTypes.BACKWARD basis_type = DayCountTypes.ACT_360 annuity = BondAnnuity(maturity_date, coupon, freq_type, calendar_type, bus_day_adjust_type, date_gen_rule_type, basis_type, face) annuity.calculate_payments(settlement_date) assert len(annuity._flow_amounts) == 10 * 12 + 1 assert len(annuity._flow_dates) == 10 * 12 + 1 assert annuity._flow_dates[0] == settlement_date assert annuity._flow_dates[-1] == maturity_date assert annuity._flow_amounts[0] == 0.0 assert round(annuity._flow_amounts[-1]) == 4306.0 assert annuity.calc_accrued_interest(settlement_date) == 0.0
def test_SemiAnnual_BondAnnuity(): settlement_date = Date(20, 6, 2018) face = 1000000 #Semi-Annual Frequency maturity_date = Date(20, 6, 2019) coupon = 0.05 freq_type = FrequencyTypes.SEMI_ANNUAL calendar_type = CalendarTypes.WEEKEND bus_day_adjust_type = BusDayAdjustTypes.FOLLOWING date_gen_rule_type = DateGenRuleTypes.BACKWARD basis_type = DayCountTypes.ACT_360 annuity = BondAnnuity(maturity_date, coupon, freq_type, calendar_type, bus_day_adjust_type, date_gen_rule_type, basis_type, face) annuity.calculate_payments(settlement_date) assert len(annuity._flow_amounts) == 2 * 1 + 1 assert len(annuity._flow_dates) == 2 * 1 + 1 assert annuity._flow_dates[0] == settlement_date assert annuity._flow_dates[-1] == maturity_date assert annuity._flow_amounts[0] == 0.0 assert round(annuity._flow_amounts[-1]) == 25278.0 assert annuity.calc_accrued_interest(settlement_date) == 0.0
def test_ForwardGenWithLongEndStub_BondAnnuity(): settlement_date = Date(20, 6, 2018) face = 1000000 maturity_date = Date(20, 6, 2028) coupon = 0.05 freq_type = FrequencyTypes.SEMI_ANNUAL calendar_type = CalendarTypes.WEEKEND bus_day_adjust_type = BusDayAdjustTypes.FOLLOWING date_gen_rule_type = DateGenRuleTypes.FORWARD basis_type = DayCountTypes.ACT_360 annuity = BondAnnuity(maturity_date, coupon, freq_type, calendar_type, bus_day_adjust_type, date_gen_rule_type, basis_type, face) annuity.calculate_payments(settlement_date) assert len(annuity._flow_amounts) == 10 * 2 + 1 assert len(annuity._flow_dates) == 10 * 2 + 1 assert annuity._flow_dates[0] == settlement_date assert annuity._flow_dates[-1] == maturity_date assert round(annuity._flow_amounts[0]) == 0.0 assert round(annuity._flow_amounts[-1]) == 25417.0 assert annuity.calc_accrued_interest(settlement_date) == 0.0
def test_BondAnnuity(): settlement_date = Date(20, 6, 2018) # print("==============================================================") # print("SEMI-ANNUAL FREQUENCY") # print("==============================================================") maturity_date = Date(20, 6, 2019) coupon = 0.05 freq_type = FrequencyTypes.SEMI_ANNUAL calendar_type = CalendarTypes.WEEKEND bus_day_adjust_type = BusDayAdjustTypes.FOLLOWING date_gen_rule_type = DateGenRuleTypes.BACKWARD basis_type = DayCountTypes.ACT_360 face = 1000000 annuity = BondAnnuity(maturity_date, coupon, freq_type, calendar_type, bus_day_adjust_type, date_gen_rule_type, basis_type, face) annuity.calculate_payments(settlement_date) testCases.header("Date", "Flow") num_flows = len(annuity._flow_dates) for i in range(1, num_flows): dt = annuity._flow_dates[i] flow = annuity._flow_amounts[i] testCases.print(dt, flow) # print("===============================================================") # print("QUARTERLY FREQUENCY") # print("===============================================================") maturity_date = Date(20, 6, 2028) coupon = 0.05 freq_type = FrequencyTypes.SEMI_ANNUAL calendar_type = CalendarTypes.WEEKEND bus_day_adjust_type = BusDayAdjustTypes.FOLLOWING date_gen_rule_type = DateGenRuleTypes.BACKWARD basis_type = DayCountTypes.ACT_360 annuity = BondAnnuity( maturity_date, coupon, freq_type, calendar_type, bus_day_adjust_type, date_gen_rule_type, basis_type, face) annuity.calculate_payments(settlement_date) testCases.header("Date", "Flow") num_flows = len(annuity._flow_dates) for i in range(1, num_flows): dt = annuity._flow_dates[i] flow = annuity._flow_amounts[i] testCases.print(dt, flow) # print("==================================================================") # print("MONTHLY FREQUENCY") # print("==================================================================") maturity_date = Date(20, 6, 2028) coupon = 0.05 freq_type = FrequencyTypes.MONTHLY calendar_type = CalendarTypes.WEEKEND bus_day_adjust_type = BusDayAdjustTypes.FOLLOWING date_gen_rule_type = DateGenRuleTypes.BACKWARD basis_type = DayCountTypes.ACT_360 annuity = BondAnnuity(maturity_date, coupon, freq_type, calendar_type, bus_day_adjust_type, date_gen_rule_type, basis_type, face) annuity.calculate_payments(settlement_date) testCases.header("Date", "Flow") num_flows = len(annuity._flow_dates) for i in range(1, num_flows): dt = annuity._flow_dates[i] flow = annuity._flow_amounts[i] testCases.print(dt, flow) # print("==================================================================") # print("FORWARD GEN") # print("==================================================================") maturity_date = Date(20, 6, 2028) coupon = 0.05 freq_type = FrequencyTypes.ANNUAL calendar_type = CalendarTypes.WEEKEND bus_day_adjust_type = BusDayAdjustTypes.FOLLOWING date_gen_rule_type = DateGenRuleTypes.FORWARD basis_type = DayCountTypes.ACT_360 annuity = BondAnnuity(maturity_date, coupon, freq_type, calendar_type, bus_day_adjust_type, date_gen_rule_type, basis_type, face) annuity.calculate_payments(settlement_date) testCases.header("Date", "Flow") num_flows = len(annuity._flow_dates) for i in range(1, num_flows): dt = annuity._flow_dates[i] flow = annuity._flow_amounts[i] testCases.print(dt, flow) # print("==================================================================") # print("BACKWARD GEN WITH SHORT END STUB") # print("==================================================================") maturity_date = Date(20, 6, 2028) coupon = 0.05 freq_type = FrequencyTypes.ANNUAL calendar_type = CalendarTypes.WEEKEND bus_day_adjust_type = BusDayAdjustTypes.FOLLOWING date_gen_rule_type = DateGenRuleTypes.FORWARD basis_type = DayCountTypes.ACT_360 annuity = BondAnnuity(maturity_date, coupon, freq_type, calendar_type, bus_day_adjust_type, date_gen_rule_type, basis_type, face) annuity.calculate_payments(settlement_date) testCases.header("Date", "Flow") num_flows = len(annuity._flow_dates) for i in range(1, num_flows): dt = annuity._flow_dates[i] flow = annuity._flow_amounts[i] testCases.print(dt, flow) # print("==================================================================") # print("FORWARD GEN WITH LONG END STUB") # print("==================================================================") maturity_date = Date(20, 6, 2028) coupon = 0.05 freq_type = FrequencyTypes.SEMI_ANNUAL calendar_type = CalendarTypes.WEEKEND bus_day_adjust_type = BusDayAdjustTypes.FOLLOWING date_gen_rule_type = DateGenRuleTypes.FORWARD basis_type = DayCountTypes.ACT_360 annuity = BondAnnuity(maturity_date, coupon, freq_type, calendar_type, bus_day_adjust_type, date_gen_rule_type, basis_type, face) annuity.calculate_payments(settlement_date) testCases.header("Date", "Flow") num_flows = len(annuity._flow_dates) for i in range(1, num_flows): dt = annuity._flow_dates[i] flow = annuity._flow_amounts[i] testCases.print(dt, flow)