def test_reference_evaluation_data_changed(self): """Testing term structure against evaluation date change... """ quote = SimpleQuote() term_structure = FlatForward(settlement_days=self.settlement_days, forward=quote, calendar=NullCalendar(), daycounter=Actual360()) quote.value = 0.03 expected = [] for days in [10, 30, 60, 120, 360, 720]: expected.append( term_structure.discount(self.adjusted_today + days) ) Settings().evaluation_date = self.adjusted_today + 30 calculated = [] for days in [10, 30, 60, 120, 360, 720]: calculated.append( term_structure.discount(self.adjusted_today+ 30 + days) ) for i, val in enumerate(expected): self.assertAlmostEqual(val, calculated[i])
def test_relinkable_structures(self): discounting_term_structure = YieldTermStructure() settlement_days = 3 flat_term_structure = FlatForward(settlement_days=settlement_days, forward=0.044, calendar=NullCalendar(), daycounter=Actual360()) discounting_term_structure.link_to(flat_term_structure) evaluation_date = Settings().evaluation_date +100 self.assertEqual( flat_term_structure.discount(evaluation_date), discounting_term_structure.discount(evaluation_date) ) another_flat_term_structure = FlatForward(settlement_days=10, forward=0.067, calendar=NullCalendar(), daycounter=Actual365Fixed()) discounting_term_structure.link_to(another_flat_term_structure) self.assertEqual( another_flat_term_structure.discount(evaluation_date), discounting_term_structure.discount(evaluation_date) ) self.assertNotEqual( flat_term_structure.discount(evaluation_date), discounting_term_structure.discount(evaluation_date) )
def test_forward_spreaded_ts(self): m = libor_market('USD(NY)') eval_date = Date(20, 9, 2004) quotes = [('DEP', '1W', SimpleQuote(0.0382)), ('DEP', '1M', SimpleQuote(0.0372)), ('DEP', '3M', SimpleQuote(0.0363)), ('DEP', '6M', SimpleQuote(0.0353)), ('DEP', '9M', SimpleQuote(0.0348)), ('DEP', '1Y', SimpleQuote(0.0345))] m.set_quotes(eval_date, quotes) ts = m.bootstrap_term_structure() discount_ts = m._discount_term_structure forecast_ts = m._forecast_term_structure discount_spd = 0.05 forecast_spd = 0.08 fwd_spd_dts = ForwardSpreadedTermStructure(discount_ts, SimpleQuote(discount_spd)) fwd_spd_fts = ForwardSpreadedTermStructure(forecast_ts, SimpleQuote(forecast_spd)) df_rate = round(float(discount_ts.forward_rate(Date(1, 1, 2005), Date(30, 1, 2005), Actual360(), Simple).rate), 2) dz_rate = round(float(discount_ts.zero_rate(Date(1, 1, 2005), Actual360(), Simple).rate), 2) fdf_rate = round(float(fwd_spd_dts.forward_rate(Date(1 ,1 , 2005), Date(30 ,1 ,2005), Actual360(), Simple).rate), 2) fdz_rate = round(float(fwd_spd_dts.zero_rate(Date(1, 1, 2005), Actual360(), Simple).rate), 2) ff_rate = round(float(forecast_ts.forward_rate(Date(1, 1, 2005), Date(30, 1, 2005), Actual360(), Simple).rate), 2) fz_rate = round(float(forecast_ts.zero_rate(Date(1, 1, 2005), Actual360(), Simple).rate), 2) ffc_rate= round(float(fwd_spd_fts.forward_rate(Date(1, 1, 2005), Date(30, 1, 2005), Actual360(), Simple).rate), 2) ffz_rate= round(float(fwd_spd_fts.zero_rate(Date(1, 1, 2005), Actual360() ,Simple).rate), 2) df_diff= fdf_rate - df_rate dz_diff= fdz_rate - dz_rate ff_diff = ffc_rate - ff_rate fz_diff = ffz_rate - fz_rate self.assertAlmostEqual(df_diff, discount_spd) self.assertAlmostEqual(dz_diff, discount_spd) self.assertAlmostEqual(ff_diff, forecast_spd) self.assertAlmostEqual(fz_diff, forecast_spd)
def test_excel_example_with_floating_rate_bond(self): todays_date = Date(25, August, 2011) settings = Settings() settings.evaluation_date = todays_date calendar = TARGET() effective_date = Date(10, Jul, 2006) termination_date = calendar.advance(effective_date, 10, Years, convention=Unadjusted) settlement_date = calendar.adjust(Date(28, January, 2011)) settlement_days = 3 #1 face_amount = 13749769.27 #2 coupon_rate = 0.05 redemption = 100.0 float_bond_schedule = Schedule.from_rule(effective_date, termination_date, Period(Annual), calendar, ModifiedFollowing, ModifiedFollowing, Backward) #3 flat_discounting_term_structure = YieldTermStructure() forecastTermStructure = YieldTermStructure() dc = Actual360() ibor_index = Euribor6M(forecastTermStructure) #5 fixing_days = 2 #6 gearings = [1, 0.0] #7 spreads = [1, 0.05] #8 caps = [] #9 floors = [] #10 pmt_conv = ModifiedFollowing #11 issue_date = effective_date float_bond = FloatingRateBond(settlement_days, face_amount, float_bond_schedule, ibor_index, dc, fixing_days, gearings, spreads, caps, floors, pmt_conv, True, redemption, issue_date) flat_term_structure = FlatForward(settlement_days=1, forward=0.055, calendar=NullCalendar(), daycounter=Actual365Fixed(), compounding=Continuous, frequency=Annual) flat_discounting_term_structure.link_to(flat_term_structure) forecastTermStructure.link_to(flat_term_structure) engine = DiscountingBondEngine(flat_discounting_term_structure) float_bond.set_pricing_engine(engine) cons_option_vol = ConstantOptionletVolatility(settlement_days, UnitedStates(Settlement), pmt_conv, 0.95, Actual365Fixed()) coupon_pricer = BlackIborCouponPricer(cons_option_vol) set_coupon_pricer(float_bond, coupon_pricer) self.assertEqual(Date(10, Jul, 2016), termination_date) self.assertEqual(calendar.advance(todays_date, 3, Days), float_bond.settlement_date()) self.assertEqual(Date(11, Jul, 2016), float_bond.maturity_date) self.assertAlmostEqual( 0.6944, float_bond.accrued_amount(float_bond.settlement_date()), 4) self.assertAlmostEqual(98.2485, float_bond.dirty_price, 4) self.assertAlmostEqual(13500805.2469, float_bond.npv, 4)
def test_daycounter_name(self): day_counter = Actual360() self.assertEqual('Actual/360', day_counter.name) self.assertEqual('Actual/360', str(day_counter))
def test_create_day_counter(self): day_counter = Actual360() self.assertTrue(day_counter is not None) self.assertIsInstance(day_counter, DayCounter)