コード例 #1
0
ファイル: test_bonds.py プロジェクト: stan2133/pyql
    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)
コード例 #2
0
ファイル: test_bonds.py プロジェクト: GuidoE/pyql
    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)