def test_create_ibor_index(self): euribor6m = IborIndex("Euribor", Period(6, Months), 2, EURCurrency(), TARGET(), ModifiedFollowing, True, Actual360()) default_euribor6m = Euribor6M() for attribute in ["business_day_convention", "end_of_month", "fixing_calendar", "tenor", "fixing_days", "day_counter", "family_name", "name"]: self.assertEqual(getattr(euribor6m, attribute), getattr(default_euribor6m, attribute))
def test_creation(self): settlement_date = Date(1, January, 2014) term_structure = YieldTermStructure(relinkable=True) term_structure.link_to( FlatForward(settlement_date, 0.05, Actual365Fixed())) # Makes sure the constructor does not segfault anymore ;-) index = Euribor6M(term_structure) self.assertEquals(index.name, 'Euribor6M Actual/360')
def test_hull_white_calibration(self): """ Adapted from ShortRateModelTest::testCachedHullWhite() """ today = Date(15, February, 2002) settlement = Date(19, February, 2002) self.settings.evaluation_date = today yield_ts = FlatForward(settlement, forward=0.04875825, settlement_days=0, calendar=NullCalendar(), daycounter=Actual365Fixed()) model = HullWhite(yield_ts, a=0.05, sigma=.005) data = [[1, 5, 0.1148 ], [2, 4, 0.1108 ], [3, 3, 0.1070 ], [4, 2, 0.1021 ], [5, 1, 0.1000 ]] index = Euribor6M(yield_ts) engine = JamshidianSwaptionEngine(model) swaptions = [] for start, length, volatility in data: vol = SimpleQuote(volatility) helper = SwaptionHelper(Period(start, Years), Period(length, Years), vol, index, Period(1, Years), Thirty360(), Actual360(), yield_ts) helper.set_pricing_engine(engine) swaptions.append(helper) # Set up the optimization problem om = LevenbergMarquardt(1.0e-8, 1.0e-8, 1.0e-8) endCriteria = EndCriteria(10000, 100, 1e-6, 1e-8, 1e-8) model.calibrate(swaptions, om, endCriteria) print('Hull White calibrated parameters:\na: %f sigma: %f' % (model.a, model.sigma)) cached_a = 0.0464041 cached_sigma = 0.00579912 tolerance = 1.0e-5 self.assertAlmostEqual(cached_a, model.a, delta=tolerance) self.assertAlmostEqual(cached_sigma, model.sigma, delta=tolerance)
def test_empty_constructor(self): euribor_6m_index = Euribor6M() self.assertEquals(euribor_6m_index.name, 'Euribor6M Actual/360')
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(effective_date, termination_date, Period(Annual), calendar, ModifiedFollowing, ModifiedFollowing, Backward) #3 flat_discounting_term_structure = YieldTermStructure(relinkable=True) forecastTermStructure = YieldTermStructure(relinkable=True) 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, 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.assertEquals(Date(10, Jul, 2016), termination_date) self.assertEquals(calendar.advance(todays_date, 3, Days), float_bond.settlement_date()) self.assertEquals(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_creation(self): # Makes sure the constructor does not segfault anymore ;-) index = Euribor6M() self.assertEquals(index.name, 'Euribor6M Actual/360')
day_counter) for d in futures.keys() ] settlementDays = 2 fixedLegFrequency = Annual fixedLegTenor = Period(1, Years) fixedLegAdjustment = Unadjusted fixedLegDayCounter = Thirty360() floatingLegFrequency = Semiannual floatingLegTenor = Period(6, Months) floatingLegAdjustment = ModifiedFollowing swapHelpers = [ SwapRateHelper.from_tenor(swaps[(n, unit)], Period(n, unit), calendar, fixedLegFrequency, fixedLegAdjustment, fixedLegDayCounter, Euribor6M()) for n, unit in swaps.keys() ] ### Curve building ts_daycounter = ActualActual(ISDA) # term-structure construction helpers = depositHelpers + swapHelpers depoSwapCurve = PiecewiseYieldCurve('discount', 'loglinear', settlementDate, helpers, ts_daycounter) helpers = depositHelpers[:2] + futuresHelpers + swapHelpers[1:] depoFuturesSwapCurve = PiecewiseYieldCurve('discount', 'loglinear', settlementDate, helpers, ts_daycounter)
calendar, ModifiedFollowing, True, dayCounter) for d in futures.keys() ] settlementDays = 2 fixedLegFrequency = Annual fixedLegTenor = Period(1,Years) fixedLegAdjustment = Unadjusted fixedLegDayCounter = Thirty360() floatingLegFrequency = Semiannual floatingLegTenor = Period(6,Months) floatingLegAdjustment = ModifiedFollowing swapHelpers = [ SwapRateHelper.from_tenor(swaps[(n,unit)], Period(n,unit), calendar, fixedLegFrequency, fixedLegAdjustment, fixedLegDayCounter, Euribor6M()) for n, unit in swaps.keys() ] ### Curve building ts_daycounter = ActualActual(ISDA) # term-structure construction helpers = depositHelpers + swapHelpers depoSwapCurve = PiecewiseYieldCurve( 'discount', 'loglinear', settlementDate, helpers, ts_daycounter ) helpers = depositHelpers[:2] + futuresHelpers + swapHelpers[1:] depoFuturesSwapCurve = PiecewiseYieldCurve( 'discount', 'loglinear',settlementDate, helpers, ts_daycounter