예제 #1
0
파일: test_bonds.py 프로젝트: phista/pyql
    def test_excel_example_with_fixed_rate_bond(self):
        """Port the QuantLib Excel adding bond example to Python. """

        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_days = 3
        face_amount = 100.0
        coupon_rate = 0.05
        redemption = 100.0

        fixed_bond_schedule = Schedule(
            effective_date, termination_date, Period(Annual), calendar, ModifiedFollowing, ModifiedFollowing, Backward
        )

        issue_date = effective_date
        bond = FixedRateBond(
            settlement_days,
            face_amount,
            fixed_bond_schedule,
            [coupon_rate],
            ActualActual(ISMA),
            Following,
            redemption,
            issue_date,
        )

        discounting_term_structure = YieldTermStructure(relinkable=True)
        flat_term_structure = FlatForward(
            settlement_days=1,
            forward=0.044,
            calendar=NullCalendar(),
            daycounter=Actual365Fixed(),
            compounding=Continuous,
            frequency=Annual,
        )

        discounting_term_structure.link_to(flat_term_structure)

        engine = DiscountingBondEngine(discounting_term_structure)

        bond.set_pricing_engine(engine)

        self.assertEquals(Date(10, Jul, 2016), termination_date)
        self.assertEquals(calendar.advance(todays_date, 3, Days), bond.settlement_date())
        self.assertEquals(Date(11, Jul, 2016), bond.maturity_date)
        self.assertAlmostEqual(0.6849, bond.accrued_amount(bond.settlement_date()), 4)
        self.assertAlmostEqual(102.1154, bond.clean_price, 4)
예제 #2
0
    def test_excel_example_with_fixed_rate_bond(self):
        '''Port the QuantLib Excel adding bond example to Python. '''

        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_days = 3
        face_amount = 100.0
        coupon_rate = 0.05
        redemption = 100.0

        fixed_bond_schedule = Schedule.from_rule(effective_date,
                                                 termination_date,
                                                 Period(Annual), calendar,
                                                 ModifiedFollowing,
                                                 ModifiedFollowing, Backward)

        issue_date = effective_date
        bond = FixedRateBond(settlement_days, face_amount,
                             fixed_bond_schedule, [coupon_rate],
                             ActualActual(ISMA), Following, redemption,
                             issue_date)

        discounting_term_structure = YieldTermStructure()
        flat_term_structure = FlatForward(settlement_days=1,
                                          forward=0.044,
                                          calendar=NullCalendar(),
                                          daycounter=Actual365Fixed(),
                                          compounding=Continuous,
                                          frequency=Annual)

        discounting_term_structure.link_to(flat_term_structure)

        engine = DiscountingBondEngine(discounting_term_structure)

        bond.set_pricing_engine(engine)

        self.assertEqual(Date(10, Jul, 2016), termination_date)
        self.assertEqual(calendar.advance(todays_date, 3, Days),
                         bond.settlement_date())
        self.assertEqual(Date(11, Jul, 2016), bond.maturity_date)
        self.assertAlmostEqual(0.6849,
                               bond.accrued_amount(bond.settlement_date()), 4)
        self.assertAlmostEqual(102.1154, bond.clean_price, 4)
예제 #3
0
    def test_bond_schedule_anotherday(self):
        '''Test date calculations and role of settings when evaluation date
        set to arbitrary date.

        This test is known to fail with boost 1.42.

        '''

        todays_date = Date(30, 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_days = 3
        face_amount = 100.0
        coupon_rate = 0.05
        redemption = 100.0

        fixed_bond_schedule = Schedule.from_rule(
            effective_date,
            termination_date,
            Period(Annual),
            calendar,
            ModifiedFollowing,
            ModifiedFollowing,
            Rule.Backward
        )

        issue_date = effective_date

        bond = FixedRateBond(
            settlement_days,
		    face_amount,
		    fixed_bond_schedule,
		    [coupon_rate],
            ActualActual(ISMA),
		    Following,
            redemption,
            issue_date
        )

        self.assertEqual(
            calendar.advance(todays_date, 3, Days), bond.settlement_date())
예제 #4
0
    def test_bond_schedule_anotherday(self):
        '''Test date calculations and role of settings when evaluation date
        set to arbitrary date.

        This test is known to fail with boost 1.42.

        '''

        todays_date = Date(30, 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_days = 3
        face_amount = 100.0
        coupon_rate = 0.05
        redemption = 100.0

        fixed_bond_schedule = Schedule.from_rule(
            effective_date,
            termination_date,
            Period(Annual),
            calendar,
            ModifiedFollowing,
            ModifiedFollowing,
            Rule.Backward
        )

        issue_date = effective_date

        bond = FixedRateBond(
            settlement_days,
		    face_amount,
		    fixed_bond_schedule,
		    [coupon_rate],
            ActualActual(ISMA),
		    Following,
            redemption,
            issue_date
        )

        self.assertEqual(
            calendar.advance(todays_date, 3, Days), bond.settlement_date())
예제 #5
0
    def test_bond_schedule_today(self):
        '''Test date calculations and role of settings when evaluation date 
        set to current date. 

        
        '''
        
        todays_date = today()

        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_days = 3
        face_amount = 100.0
        coupon_rate = 0.05
        redemption = 100.0
        
        fixed_bond_schedule = Schedule(
            effective_date,
            termination_date,
            Period(Annual),
            calendar,
            ModifiedFollowing,
            ModifiedFollowing,
            Backward
        )

        issue_date = effective_date

        bond = FixedRateBond(
            settlement_days,
		    face_amount,
		    fixed_bond_schedule,
		    [coupon_rate],
            ActualActual(ISMA), 
		    Following,
            redemption,
            issue_date
        )

        self.assertEquals(
            calendar.advance(todays_date, 3, Days), bond.settlement_date())
예제 #6
0
    def test_bond_schedule_today(self):
        '''Test date calculations and role of settings when evaluation date 
        set to current date. 

        
        '''

        todays_date = today()

        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_days = 3
        face_amount = 100.0
        coupon_rate = 0.05
        redemption = 100.0

        fixed_bond_schedule = Schedule(effective_date, termination_date,
                                       Period(Annual), calendar,
                                       ModifiedFollowing, ModifiedFollowing,
                                       Backward)

        issue_date = effective_date

        bond = FixedRateBond(settlement_days, face_amount,
                             fixed_bond_schedule, [coupon_rate],
                             ActualActual(ISMA), Following, redemption,
                             issue_date)

        self.assertEquals(calendar.advance(todays_date, 3, Days),
                          bond.settlement_date())
예제 #7
0
파일: bonds.py 프로젝트: stan2133/pyql
settlement_days = 3
face_amount = 100.0
coupon_rate = 0.05
redemption = 100.0

fixed_bond_schedule = Schedule(effective_date, termination_date,
                               Period(Annual), calendar, ModifiedFollowing,
                               ModifiedFollowing, Backward)

issue_date = effective_date
bond = FixedRateBond(settlement_days,
                     face_amount, fixed_bond_schedule, [coupon_rate],
                     ActualActual(ISMA), Following, redemption, issue_date)

discounting_term_structure = YieldTermStructure(relinkable=True)
flat_term_structure = FlatForward(settlement_days=1,
                                  forward=0.044,
                                  calendar=NullCalendar(),
                                  daycounter=Actual365Fixed(),
                                  compounding=Continuous,
                                  frequency=Annual)
discounting_term_structure.link_to(flat_term_structure)
pricing_engine = DiscountingBondEngine(discounting_term_structure)
bond.set_pricing_engine(pricing_engine)

print('Settlement date: ', bond.settlement_date())
print('Maturity date:', bond.maturity_date)
print('Accrued amount: ', bond.accrued_amount(bond.settlement_date()))
print('Clean price:', bond.clean_price)
예제 #8
0
파일: bonds.py 프로젝트: enthought/pyql
bond = FixedRateBond(
    settlement_days,
    face_amount,
    fixed_bond_schedule,
    [coupon_rate],
    ActualActual(ISMA),
    Following,
    redemption,
    issue_date
)

discounting_term_structure = YieldTermStructure(relinkable=True)
flat_term_structure = FlatForward(
    settlement_days = 1,
    forward         = 0.044,
    calendar        = NullCalendar(),
    daycounter      = Actual365Fixed(),
    compounding     = Continuous,
    frequency       = Annual)
discounting_term_structure.link_to(flat_term_structure)
pricing_engine = DiscountingBondEngine(discounting_term_structure)
bond.set_pricing_engine(pricing_engine)


print('Settlement date: ', bond.settlement_date())
print('Maturity date:', bond.maturity_date)
print('Accrued amount: ', bond.accrued_amount(bond.settlement_date()))
print('Clean price:', bond.clean_price)