def test_curves():
    base_date = date(2018, 7, 13)
    libor_dates = [date(2018, 10, 15), date(2019, 1, 15), date(2019, 7, 15)]
    libor_dfs = [0.9950, 0.9880, 0.9750]
    libor_curve = InterestRateCurve(base_date, libor_dates, libor_dfs)
    ois_dates = [date(2018, 7, 15)] + libor_dates
    ois_dfs = [0.9999, 0.9945, 0.9900, 0.9800]
    ois_curve = InterestRateCurve(base_date, ois_dates, ois_dfs)
    return libor_curve, ois_curve
 def test_basic(self):
     notional = 1e6
     start_date = date(2018, 7, 9)
     tenor_in_months = 3
     rate = 0.05
     libor_deposit = LiborDeposit(notional, start_date, tenor_in_months, rate)
     end_date = date(2018, 10, 9)
     known_df = 1.0 / (1.0 + rate * actual_360.yf(start_date, end_date))
     libor_curve = InterestRateCurve(start_date, [end_date], [known_df])
     ois_curve = InterestRateCurve(start_date, [end_date], [1.0])
     assert(abs(libor_deposit.value(libor_curve, ois_curve)) < 1e-6)
def test_forward():
    base_date = date(2018, 7, 13)
    dates = [date(2018, 10, 1), date(2019, 1, 1)]
    dfs = [0.97, 0.95]
    curve = InterestRateCurve(base_date, dates, dfs)

    start_date = date(2018, 8, 15)
    end_date = date(2018, 10, 15)
    start_df = curve.df(start_date)
    end_df = curve.df(end_date)
    forward = curve.forward(start_date, end_date, actual_360)
    yf = actual_360.yf(start_date, end_date)
    assert(abs(start_df / (1.0 + forward * yf) - end_df) < 1e-9)
    def test_basic(self):
        year = 2019
        month = 6
        edf = EurodollarFuture(year, month)

        base_date = date(2018, 7, 13)
        start_date = date(2019, 6, 19)
        end_date = date(2019, 9, 19)
        start_df = 0.90
        rate = 0.0150
        end_df = start_df / (1.0 + rate * 92.0 / 360.0)
        libor_curve = InterestRateCurve(base_date, [start_date, end_date],
                                        [start_df, end_df])
        assert(abs(edf.price(libor_curve) - 98.5) < 1e-9)
    def test_fixed_leg(self, test_curves):
        notional = 1e6
        start_date = date(2018, 7, 31)
        tenor_in_months = 12
        fixed_rate = 0.05
        swap = InterestRateSwap(-notional, start_date, tenor_in_months, fixed_rate)  # Receive fixed
        libor_curve, ois_curve = test_curves
        zero_curve = InterestRateCurve(date(2018, 7, 13), [date(2019, 7, 13)], [1.0])

        # Note that no date adjustment, so the year-fractions are 0.5.

        actual_value = swap.value(zero_curve, libor_curve)
        expected_value = notional * fixed_rate * 0.5 * (libor_curve.df(date(2019, 1, 31))
                                                        + libor_curve.df(date(2019, 7, 31)))
        assert(abs(actual_value - expected_value) < 1e-9)

        actual_value = swap.value(zero_curve, ois_curve)
        expected_value = notional * fixed_rate * 0.5 * (ois_curve.df(date(2019, 1, 31))
                                                        + ois_curve.df(date(2019, 7, 31)))
        assert(abs(actual_value - expected_value) < 1e-9)
Beispiel #6
0
 def make_curve(dfs):
     return InterestRateCurve(base_date, dates, dfs)
def test_basic():
    base_date = date(2018, 7, 9)
    three_months = date(2018, 10, 9)
    one_year = date(2019, 7, 9)
    dates = [three_months, one_year]
    dfs = [0.98, 0.90]
    curve = InterestRateCurve(base_date, dates, dfs)
    with pytest.raises(ValueError):
        curve.df(base_date + timedelta(days=-1))
    assert(curve.df(base_date) == 1.0)
    assert(curve.df(three_months) == 0.98)
    assert(curve.df(one_year) == 0.90)

    # Two periods within the same PWC period must have the same rate.
    date1 = date(2018, 7, 15)
    date2 = date(2018, 8, 15)
    date3 = date(2018, 8, 30)
    rate1 = -log(curve.df(date2) / curve.df(date1)) / actual_365.yf(date1, date2)
    rate2 = -log(curve.df(date3) / curve.df(date2)) / actual_365.yf(date2, date3)
    assert(abs(rate1 - rate2) < 1e-6)

    # And the same over the last period, which goes from
    # the *second-last* date onwards.
    date1 = date(2019, 3, 9)
    date2 = one_year
    date3 = date(2019, 12, 9)
    rate1 = -log(curve.df(date2) / curve.df(date1)) / actual_365.yf(date1, date2)
    rate2 = -log(curve.df(date3) / curve.df(date2)) / actual_365.yf(date2, date3)
    assert(abs(rate1 - rate2) < 1e-6)