Ejemplo n.º 1
0
 def test_cms_swap(self):
     swap_lengths = [1, 5, 6, 10]
     spread = 0.
     cms_list = [MakeCms(Period(t, Years),
                         self.swap_index,
                         self.swap_index.ibor_index,
                         spread,
                         Period(10, Days))() for t in swap_lengths]
     for model in YieldCurveModel:
         num_pricer = NumericHaganPricer(self.atm_vol, model, SimpleQuote(0.))
         analytic_pricer = AnalyticHaganPricer(self.atm_vol, model, SimpleQuote(0.))
         if model == YieldCurveModel.NonParallelShifts:
             lineartsr_pricer = LinearTsrPricer(self.atm_vol, SimpleQuote(0.))
         for cms in cms_list:
             set_coupon_pricer(cms[0], num_pricer)
             price_num = cms.npv
             set_coupon_pricer(cms[0], analytic_pricer)
             price_analytic = cms.npv
             self.assertAlmostEqual(price_num, price_analytic, 3)
             if model == YieldCurveModel.NonParallelShifts:
                 set_coupon_pricer(cms[0], lineartsr_pricer)
                 self.assertAlmostEqual(cms.npv, price_analytic, 3)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)