예제 #1
0
    def test_create_libor_index(self):

        settings = Settings(calendar = TARGET()).instance()
        calendar = settings.calendar
        
        eval_date = qldate_from_pydate(settings.today())
        
        settlement_days = 2
        settlement_date = calendar.advance(eval_date, settlement_days, Days)
        # must be a business day
        settlement_date = calendar.adjust(settlement_date);

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

        self.assertEquals('USD Libor6M Actual/360', index.name)
예제 #2
0
    def test_deposit_swap(self):

        # Market information
        settings = Settings(calendar=TARGET())
        calendar = settings.calendar

        # must be a business day
        eval_date = qldate_from_pydate(settings.today())

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

        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())

        spread = SimpleQuote(0)
        fwdStart = Period(0, Days)

        for m, period, rate in swapData:
            rate = SimpleQuote(rate / 100)

            helper = SwapRateHelper(rate, Period(m, Years), calendar, Annual,
                                    Unadjusted, Thirty360(), liborIndex,
                                    spread, fwdStart)

            rate_helpers.append(helper)

        ts_day_counter = ActualActual(ISDA)
        tolerance = 1.0e-15

        ts = term_structure_factory('discount', 'loglinear', settlement_date,
                                    rate_helpers, ts_day_counter, tolerance)

        # this is not a real test ...
        self.assertAlmostEquals(
            0.9103, ts.discount(calendar.advance(today(), 2, Years)), 3)
        self.assertAlmostEquals(
            0.7836, ts.discount(calendar.advance(today(), 5, Years)), 3)
        self.assertAlmostEquals(
            0.5827, ts.discount(calendar.advance(today(), 10, Years)), 3)
        self.assertAlmostEquals(
            0.4223, ts.discount(calendar.advance(today(), 15, Years)), 3)
예제 #3
0
    def test_deposit_swap(self):

        # Market information
        settings = Settings(calendar = TARGET())
        calendar = settings.calendar 

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

        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())

        spread = SimpleQuote(0)
        fwdStart = Period(0, Days)

        for m, period, rate in swapData:
            rate = SimpleQuote(rate/100)

            helper = SwapRateHelper(rate, Period(m, Years),
                calendar, Annual,
                Unadjusted, Thirty360(),
                liborIndex, spread, fwdStart)

            rate_helpers.append(helper)

        ts_day_counter = ActualActual(ISDA)
        tolerance = 1.0e-15

        ts = term_structure_factory(
            'discount', 'loglinear', settlement_date, rate_helpers,
            ts_day_counter, tolerance)

        # this is not a real test ...
        self.assertAlmostEquals(0.9103,
             ts.discount(calendar.advance(today(), 2, Years)),3)
        self.assertAlmostEquals(0.7836,
             ts.discount(calendar.advance(today(), 5, Years)),3)
        self.assertAlmostEquals(0.5827,
             ts.discount(calendar.advance(today(), 10, Years)),3)
        self.assertAlmostEquals(0.4223,
             ts.discount(calendar.advance(today(), 15, Years)),3)