当前位置: 首页>>代码示例>>Python>>正文


Python api.YieldTermStructure类代码示例

本文整理汇总了Python中quantlib.termstructures.yields.api.YieldTermStructure的典型用法代码示例。如果您正苦于以下问题:Python YieldTermStructure类的具体用法?Python YieldTermStructure怎么用?Python YieldTermStructure使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了YieldTermStructure类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_libor_index

    def test_create_libor_index(self):

        settings = Settings.instance()

        # Market information
        calendar = TARGET()

        # must be a business day
        eval_date = calendar.adjust(today())
        settings.evaluation_date = eval_date

        settlement_days = 2
        settlement_date = calendar.advance(eval_date, settlement_days, Days)
        # must be a business day
        settlement_date = calendar.adjust(settlement_date)

        term_structure = YieldTermStructure(relinkable=True)
        term_structure.link_to(FlatForward(settlement_date, 0.05,
                                           Actual365Fixed()))

        index = Libor('USD Libor', Period(6, Months), settlement_days,
                      USDCurrency(), calendar, Actual360(),
                      term_structure)

        t = index.tenor
        self.assertEqual(t.length, 6)
        self.assertEqual(t.units, 2)
        self.assertEqual('USD Libor6M Actual/360', index.name)
开发者ID:phenaff,项目名称:pyql,代码行数:28,代码来源:test_indexes.py

示例2: test_create_libor_index

    def test_create_libor_index(self):

        settings = Settings.instance()

        # Market information
        calendar = UnitedStates(LiborImpact)

        # must be a business day
        eval_date = calendar.adjust(today())
        settings.evaluation_date = eval_date

        settlement_days = 2
        settlement_date = calendar.advance(eval_date, settlement_days, Days)
        # must be a business day
        settlement_date = calendar.adjust(settlement_date)

        term_structure = YieldTermStructure(relinkable=True)
        term_structure.link_to(FlatForward(settlement_date, 0.05,
                                           Actual365Fixed()))

        index = Libor('USDLibor', Period(6, Months), settlement_days,
                      USDCurrency(), calendar, Actual360(),
                      term_structure)
        default_libor = USDLibor(Period(6, Months))
        for attribute in ["business_day_convention", "end_of_month",
                          "fixing_calendar", "joint_calendar", "tenor",
                          "fixing_days", "day_counter", "family_name", "name"]:
            self.assertEqual(getattr(index, attribute),
                             getattr(default_libor, attribute))
开发者ID:enthought,项目名称:pyql,代码行数:29,代码来源:test_indexes.py

示例3: test_create_swap_index

    def test_create_swap_index(self):

        settings = Settings.instance()

        # Market information
        calendar = TARGET()

        # must be a business day
        eval_date = calendar.adjust(today())
        settings.evaluation_date = eval_date

        settlement_days = 2
        settlement_date = calendar.advance(eval_date, settlement_days, Days)
        # must be a business day
        settlement_date = calendar.adjust(settlement_date)
        term_structure = YieldTermStructure(relinkable=True)
        term_structure.link_to(FlatForward(settlement_date, 0.05,
                                          Actual365Fixed()))

        ibor_index = Libor('USD Libor', Period(6, Months), settlement_days,
                        USDCurrency(), calendar, Actual360(),
                           term_structure)

        index = SwapIndex(
            'family name', Period(3, Months), 10, USDCurrency(), TARGET(),
            Period(12, Months), Following, Actual360(), ibor_index)

        self.assertIsNotNone(index)
开发者ID:GuidoE,项目名称:pyql,代码行数:28,代码来源:test_indexes.py

示例4: test_excel_example_with_zero_coupon_bond

    def test_excel_example_with_zero_coupon_bond(self):


        todays_date = Date(25, August, 2011)

        settlement_days = 3
        face_amount = 100
        calendar = TARGET()
        maturity_date = Date(26, February, 2024)

        bond = ZeroCouponBond(
            settlement_days, calendar, face_amount, maturity_date, Following,
            100., todays_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)

        bond.set_pricing_engine(discounting_term_structure)

        self.assertEquals(
            calendar.advance(todays_date, 3, Days), bond.settlement_date()
        )
        self.assertEquals(0., bond.accrued_amount(bond.settlement_date()))
        self.assertAlmostEquals(57.6915, bond.clean_price, 4)
开发者ID:bondgeek,项目名称:pyql,代码行数:32,代码来源:test_bonds.py

示例5: bootstrap_term_structure

    def bootstrap_term_structure(self, interpolator=Interpolator.LogLinear):
        tolerance = 1.0e-15
        settings = Settings()
        calendar = JointCalendar(UnitedStates(), UnitedKingdom())
        # must be a business day
        eval_date = self._eval_date
        settings.evaluation_date = eval_date
        settlement_days = self._params.settlement_days
        settlement_date = calendar.advance(eval_date, settlement_days, Days)
        # must be a business day
        settlement_date = calendar.adjust(settlement_date)
        ts = PiecewiseYieldCurve.from_reference_date(
            BootstrapTrait.Discount,
            interpolator,
            settlement_date,
            self._rate_helpers,
            DayCounter.from_name(self._termstructure_daycount),
            tolerance,
        )
        self._term_structure = ts
        self._discount_term_structure = YieldTermStructure()
        self._discount_term_structure.link_to(ts)

        self._forecast_term_structure = YieldTermStructure()
        self._forecast_term_structure.link_to(ts)

        return ts
开发者ID:student-t,项目名称:pyql,代码行数:27,代码来源:market.py

示例6: test_creation

    def test_creation(self):

        settlement_date = Date(1, January, 2014)
        term_structure = YieldTermStructure()
        term_structure.link_to(FlatForward(settlement_date, 0.05,
                                           Actual365Fixed()))
        index = USDLibor(Period(3, Months), term_structure)

        self.assertEqual(index.name, 'USDLibor3M Actual/360')
开发者ID:enthought,项目名称:pyql,代码行数:9,代码来源:test_indexes.py

示例7: test_excel_example_with_fixed_rate_bond

    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)
开发者ID:phista,项目名称:pyql,代码行数:54,代码来源:test_bonds.py

示例8: test_relinkable_structures

    def test_relinkable_structures(self):

        discounting_term_structure = YieldTermStructure(relinkable=True)

        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)
        )
开发者ID:ChinaQuants,项目名称:pyql,代码行数:31,代码来源:test_termstructures.py

示例9: test_create_swap_index

    def test_create_swap_index(self):

        term_structure = YieldTermStructure()
        term_structure.link_to(FlatForward(forward=0.05,
                                           daycounter=Actual365Fixed(),
                                           settlement_days=2,
                                           calendar=UnitedStates()))

        ibor_index = USDLibor(Period(3, Months), term_structure)

        index = SwapIndex(
            'UsdLiborSwapIsdaFixAm', Period(10, Years), 2, USDCurrency(),
            UnitedStates(GovernmentBond),
            Period(6, Months), ModifiedFollowing,
            Thirty360(), ibor_index)
        index2 = UsdLiborSwapIsdaFixAm(Period(10, Years), term_structure)
        for attr in ['name', 'family_name', 'fixing_calendar', 'tenor',
                     'day_counter', 'currency']:
            self.assertEqual(getattr(index, attr), getattr(index2, attr))
开发者ID:enthought,项目名称:pyql,代码行数:19,代码来源:test_indexes.py

示例10: bootstrap_term_structure

    def bootstrap_term_structure(self):
        tolerance = 1.0e-15
        settings = Settings()
        calendar = JointCalendar(UnitedStates(), UnitedKingdom())
        # must be a business day
        eval_date = self._eval_date
        settings.evaluation_date = eval_date
        settlement_days = self._params.settlement_days
        settlement_date = calendar.advance(eval_date, settlement_days, Days)
        # must be a business day
        settlement_date = calendar.adjust(settlement_date)
        ts = term_structure_factory(
            'discount', 'loglinear',
            settlement_date, self._rate_helpers,
            DayCounter.from_name(self._termstructure_daycount),
            tolerance)
        self._term_structure = ts
        self._discount_term_structure = YieldTermStructure(relinkable=True)
        self._discount_term_structure.link_to(ts)

        self._forecasting_term_structure = YieldTermStructure(relinkable=True)
        self._forecasting_term_structure.link_to(ts)

        return 0
开发者ID:JohnnyBurst,项目名称:pyql,代码行数:24,代码来源:market.py

示例11: test_display

    def test_display(self):

        settings = Settings()

        # Date setup
        calendar = TARGET()

        # Settlement date
        settlement_date = calendar.adjust(Date(28, January, 2011))

        # Evaluation date
        fixing_days = 1
        settlement_days = 1

        todays_date = calendar.advance(
            settlement_date, -fixing_days, Days
        )

        settings.evaluation_date = todays_date

        # Bound attributes
        face_amount = 100.0
        redemption = 100.0
        issue_date = Date(27, January, 2011)
        maturity_date = Date(31, August, 2020)
        coupon_rate = 0.03625
        bond_yield = 0.034921

        flat_discounting_term_structure = YieldTermStructure(relinkable=True)
        flat_term_structure = FlatForward(
            reference_date = settlement_date,
            forward        = bond_yield,
            daycounter     = Actual365Fixed(), #actual_actual.ActualActual(actual_actual.Bond),
            compounding    = Compounded,
            frequency      = Semiannual)
        # have a look at the FixedRateBondHelper to simplify this
        # construction
        flat_discounting_term_structure.link_to(flat_term_structure)


	#Rate
        fixed_bond_schedule = Schedule(
            issue_date,
            maturity_date,
            Period(Semiannual),
            UnitedStates(market=GOVERNMENTBOND),
            Unadjusted,
            Unadjusted,
            Backward,
            False);


        bond = FixedRateBond(
            settlement_days,
		    face_amount,
		    fixed_bond_schedule,
		    [coupon_rate],
            ActualActual(Bond),
		    Unadjusted,
            redemption,
            issue_date
        )

        bfs=bf.BondFunctions()
        d=bfs.startDate(bond)
        bfs.display()
        zspd=bfs.zSpread(bond,100.0,flat_term_structure,Actual365Fixed(),
        Compounded,Semiannual,settlement_date,1e-6,100,0.5)
        
        
              
        #Also need a test case for a PiecewiseTermStructure...                
        depositData = [[ 1, Months, 4.581 ],
                       [ 2, Months, 4.573 ],
                       [ 3, Months, 4.557 ],
                       [ 6, Months, 4.496 ],
                       [ 9, Months, 4.490 ]]

        swapData = [[ 1, Years, 4.54 ],
                    [ 5, Years, 4.99 ],
                    [ 10, Years, 5.47 ],
                    [ 20, Years, 5.89 ],
                    [ 30, Years, 5.96 ]]

        rate_helpers = []

        end_of_month = True
        for m, period, rate in depositData:
            tenor = Period(m, Months)

            helper = DepositRateHelper(rate/100, tenor, settlement_days,
                     calendar, ModifiedFollowing, end_of_month,
                     Actual360())

            rate_helpers.append(helper)

        liborIndex = Libor('USD Libor', Period(6, Months), settlement_days,
                           USDCurrency(), calendar, Actual360(),
                           YieldTermStructure(relinkable=False))

#.........这里部分代码省略.........
开发者ID:tnicolas,项目名称:pyql,代码行数:101,代码来源:test_bondfunctions.py

示例12: test_swap_QL

    def test_swap_QL(self):
        """
        Test that a swap with fixed coupon = fair rate has an NPV=0
        Create from QL objects
        """

        nominal = 100.0
        fixedConvention = Unadjusted
        floatingConvention = ModifiedFollowing
        fixedFrequency = Annual
        floatingFrequency = Semiannual
        fixedDayCount = Thirty360()
        floatDayCount = Thirty360()
        calendar = TARGET()
        settlement_days = 2

        eval_date = Date(2, January, 2014)
        settings = Settings()
        settings.evaluation_date = eval_date

        settlement_date = calendar.advance(eval_date, settlement_days, Days)
        # must be a business day
        settlement_date = calendar.adjust(settlement_date)

        termStructure = YieldTermStructure(relinkable=True)
        termStructure.link_to(FlatForward(settlement_date, 0.05,
                                          Actual365Fixed()))

        index = Libor('USD Libor', Period(6, Months), settlement_days,
                      USDCurrency(), calendar, Actual360(),
                      termStructure)

        length = 5
        fixedRate = .05
        floatingSpread = 0.0

        maturity = calendar.advance(settlement_date, length, Years,
                                    convention=floatingConvention)

        fixedSchedule = Schedule(settlement_date, maturity,
                                 Period(fixedFrequency),
                                 calendar, fixedConvention, fixedConvention,
                                 Rule.Forward, False)

        floatSchedule = Schedule(settlement_date, maturity,
                                 Period(floatingFrequency),
                                 calendar, floatingConvention,
                                 floatingConvention,
                                 Rule.Forward, False)
        engine = DiscountingSwapEngine(termStructure,
                                       False,
                                       settlement_date, settlement_date)
        for swap_type in [Payer, Receiver]:
            swap = VanillaSwap(swap_type, nominal, fixedSchedule, fixedRate,
                    fixedDayCount,
                    floatSchedule, index, floatingSpread,
                    floatDayCount, fixedConvention)
            swap.set_pricing_engine(engine)
            fixed_leg = swap.fixed_leg
            floating_leg = swap.floating_leg

            f = swap.fair_rate
            print('fair rate: %f' % f)
            p = swap.net_present_value
            print('NPV: %f' % p)

            swap = VanillaSwap(swap_type, nominal, fixedSchedule, f,
                               fixedDayCount,
                               floatSchedule, index, floatingSpread,
                               floatDayCount, fixedConvention)
            swap.set_pricing_engine(engine)

            p = swap.net_present_value
            print('NPV: %f' % p)
            self.assertAlmostEqual(p, 0)
开发者ID:enthought,项目名称:pyql,代码行数:75,代码来源:test_swap.py

示例13: test_default_constructor

    def test_default_constructor(self):

        term_structure = YieldTermStructure()

        with self.assertRaises(ValueError):
            term_structure.discount(Settings().evaluation_date)
开发者ID:ChinaQuants,项目名称:pyql,代码行数:6,代码来源:test_termstructures.py

示例14: test_display

    def test_display(self):

        settings = Settings()

        # Date setup
        calendar = TARGET()

        # Settlement date
        settlement_date = calendar.adjust(Date(28, January, 2011))

        # Evaluation date
        fixing_days = 1
        settlement_days = 1

        todays_date = calendar.advance(
            settlement_date, -fixing_days, Days
        )

        settings.evaluation_date = todays_date

        # Bound attributes
        face_amount = 100.0
        redemption = 100.0
        issue_date = Date(27, January, 2011)
        maturity_date = Date(31, August, 2020)
        coupon_rate = 0.03625
        bond_yield = 0.034921

        flat_discounting_term_structure = YieldTermStructure()
        flat_term_structure = FlatForward(
            reference_date = settlement_date,
            forward        = bond_yield,
            daycounter     = Actual365Fixed(), #actual_actual.ActualActual(actual_actual.Bond),
            compounding    = Compounded,
            frequency      = Semiannual)
        # have a look at the FixedRateBondHelper to simplify this
        # construction
        flat_discounting_term_structure.link_to(flat_term_structure)


	#Rate
        fixed_bond_schedule = Schedule(
            issue_date,
            maturity_date,
            Period(Semiannual),
            UnitedStates(market=GOVERNMENTBOND),
            Unadjusted,
            Unadjusted,
            Backward,
            False);


        bond = FixedRateBond(
            settlement_days,
		    face_amount,
		    fixed_bond_schedule,
		    [coupon_rate],
            ActualActual(Bond),
		    Unadjusted,
            redemption,
            issue_date
        )



        d=bf.startDate(bond)

        zspd=bf.zSpread(bond, 100.0, flat_term_structure, Actual365Fixed(),
        Compounded, Semiannual, settlement_date, 1e-6, 100, 0.5)


        #Also need a test case for a PiecewiseTermStructure...
        depositData = [[ 1, Months, 4.581 ],
                       [ 2, Months, 4.573 ],
                       [ 3, Months, 4.557 ],
                       [ 6, Months, 4.496 ],
                       [ 9, Months, 4.490 ]]

        swapData = [[ 1, Years, 4.54 ],
                    [ 5, Years, 4.99 ],
                    [ 10, Years, 5.47 ],
                    [ 20, Years, 5.89 ],
                    [ 30, Years, 5.96 ]]

        rate_helpers = []

        end_of_month = True
        for m, period, rate in depositData:
            tenor = Period(m, Months)

            helper = DepositRateHelper(SimpleQuote(rate/100), tenor, settlement_days,
                     calendar, ModifiedFollowing, end_of_month,
                     Actual360())

            rate_helpers.append(helper)

        liborIndex = Libor('USD Libor', Period(6, Months), settlement_days,
                           USDCurrency(), calendar, Actual360(),
                           YieldTermStructure(relinkable=False))

#.........这里部分代码省略.........
开发者ID:student-t,项目名称:pyql,代码行数:101,代码来源:test_bondfunctions.py

示例15: IborMarket


#.........这里部分代码省略.........
    @property
    def max_date(self):
        return 0

    def __str__(self):
        output = \
            "Ibor Market %s\n" % self._name + \
            "Number of settlement days: %d\n" % self._params.settlement_days +\
            "Fixed rate frequency: %s\n" % self._params.fixed_rate_frequency +\
            "Fixed rate convention: %s\n" % self._params.fixed_instrument_convention +\
            "Fixed rate daycount: %s\n" % self._params.fixed_instrument_daycounter +\
            "Term structure daycount: %s\n" % self._termstructure_daycount + \
            "Floating rate index: %s\n" % self._floating_rate_index + \
            "Deposit daycount: %s\n" % self._deposit_daycount + \
            "Calendar: %s\n" % self._params.calendar

        return output

    def bootstrap_term_structure(self, interpolator='loglinear'):
        tolerance = 1.0e-15
        settings = Settings()
        calendar = JointCalendar(UnitedStates(), UnitedKingdom())
        # must be a business day
        eval_date = self._eval_date
        settings.evaluation_date = eval_date
        settlement_days = self._params.settlement_days
        settlement_date = calendar.advance(eval_date, settlement_days, Days)
        # must be a business day
        settlement_date = calendar.adjust(settlement_date)
        ts = PiecewiseYieldCurve(
            'discount', interpolator, settlement_date, self._rate_helpers,
            DayCounter.from_name(self._termstructure_daycount),
            tolerance
        )
        self._term_structure = ts
        self._discount_term_structure = YieldTermStructure(relinkable=True)
        self._discount_term_structure.link_to(ts)

        self._forecast_term_structure = YieldTermStructure(relinkable=True)
        self._forecast_term_structure.link_to(ts)

        return ts

    def discount(self, date_maturity, extrapolate=True):
        return self._discount_term_structure.discount(date_maturity)

    def create_fixed_float_swap(self, settlement_date, length, fixed_rate,
                                floating_spread, **kwargs):
        """
        Create a fixed-for-float swap given:
        - settlement date
        - length in years
        - additional arguments to modify market default parameters
        """

        _params = self._params._replace(**kwargs)

        index = IborIndex.from_name(self._market,
                                    self._forecast_term_structure,
                                    **kwargs)

        swap_type = Payer
        nominal = 100.0
        fixed_convention = \
            BusinessDayConvention.from_name(_params.fixed_leg_convention)
        floating_convention = \
            BusinessDayConvention.from_name(_params.floating_leg_convention)
        fixed_frequency = \
            code_to_frequency(_params.fixed_leg_period)
        floating_frequency = code_to_frequency(_params.floating_leg_period)
        fixed_daycount = DayCounter.from_name(_params.fixed_leg_daycount)
        float_daycount = DayCounter.from_name(_params.floating_leg_daycount)
        calendar = calendar_from_name(_params.calendar)

        maturity = calendar.advance(settlement_date, length, Years,
                                    convention=floating_convention)

        fixed_schedule = Schedule(settlement_date, maturity,
                                  Period(fixed_frequency), calendar,
                                  fixed_convention, fixed_convention,
                                  Forward, False)

        float_schedule = Schedule(settlement_date, maturity,
                                  Period(floating_frequency),
                                  calendar, floating_convention,
                                  floating_convention,
                                  Forward, False)

        swap = VanillaSwap(swap_type, nominal, fixed_schedule, fixed_rate,
                           fixed_daycount, float_schedule, index,
                           floating_spread, float_daycount, fixed_convention)

        engine = DiscountingSwapEngine(self._discount_term_structure,
                                       False,
                                       settlementDate=settlement_date,
                                       npvDate=settlement_date)

        swap.set_pricing_engine(engine)

        return swap
开发者ID:GuidoE,项目名称:pyql,代码行数:101,代码来源:market.py


注:本文中的quantlib.termstructures.yields.api.YieldTermStructure类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。