Beispiel #1
0
def example03():
    print("example 3:\n")
    todays_date = Date(13, 6, 2011)
    Settings.instance().evaluation_date = todays_date
    quotes = [0.00445, 0.00949, 0.01234, 0.01776, 0.01935, 0.02084]
    tenors = [1, 2, 3, 6, 9, 12]
    calendar = WeekendsOnly()
    deps = [
        DepositRateHelper(q, Period(t, Months), 2, calendar, ModifiedFollowing,
                          False, Actual360()) for q, t in zip(quotes, tenors)
    ]
    quotes = [
        0.01652, 0.02018, 0.02303, 0.02525, 0.0285, 0.02931, 0.03017, 0.03092,
        0.03160, 0.03231, 0.03367, 0.03419, 0.03411, 0.03411, 0.03412
    ]
    tenors = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 20, 25, 30]
    swaps = [
        SwapRateHelper.from_tenor(q, Period(t, Years), calendar, Annual,
                                  ModifiedFollowing, Thirty360(), Euribor6M(),
                                  SimpleQuote(0))
        for q, t in zip(quotes, tenors)
    ]
    yield_helpers = deps + swaps
    isda_yts = PiecewiseYieldCurve(BootstrapTrait.Discount,
                                   Interpolator.LogLinear, 0, WeekendsOnly(),
                                   yield_helpers, Actual365Fixed())

    spreads = [0.007927, 0.012239, 0.016979, 0.019271, 0.020860]
    tenors = [1, 3, 5, 7, 10]
    spread_helpers = [SpreadCdsHelper(0.007927, Period(6, Months), 1,
                                      WeekendsOnly(), Quarterly, Following, Rule.CDS2015,
                                      Actual360(), 0.4, isda_yts, True, True,
                                      Date(), Actual360(True), True, PricingModel.ISDA)] + \
    [SpreadCdsHelper(s, Period(t, Years), 1, WeekendsOnly(), Quarterly, Following, Rule.CDS2015,
                     Actual360(), 0.4, isda_yts, True, True, Date(), Actual360(True), True,
                     PricingModel.ISDA)
     for s, t in zip(spreads, tenors)]
    isda_cts = PiecewiseDefaultCurve(ProbabilityTrait.SurvivalProbability,
                                     Interpolator.LogLinear, 0, WeekendsOnly(),
                                     spread_helpers, Actual365Fixed())
    isda_pricer = IsdaCdsEngine(isda_cts, 0.4, isda_yts)
    print("Isda yield curve:")
    for h in yield_helpers:
        d = h.latest_date
        t = isda_yts.time_from_reference(d)
        print(d, t, isda_yts.zero_rate(d, Actual365Fixed()).rate)

    print()
    print("Isda credit curve:")
    for h in spread_helpers:
        d = h.latest_date
        t = isda_cts.time_from_reference(d)
        print(d, t, isda_cts.survival_probability(d))
Beispiel #2
0
    def test_piecewise_methods(self):

        for trait in ['HazardRate', 'DefaultDensity', 'SurvivalProbability']:
            for interpolator in ['Linear', 'LogLinear', 'BackwardFlat']:
                curve = PiecewiseDefaultCurve(
                    trait,
                    interpolator,
                    reference_date=self.todays_date,
                    helpers=[self.helper],
                    daycounter=Actual365Fixed()
                )

                if interpolator == "LogLinear" and trait in ["HazardRate",
                                                             "DefaultDensity"]:
                    with self.assertRaisesRegexp(RuntimeError,
                                                 'LogInterpolation primitive not implemented'):
                        curve.survival_probability(self.d)
                else:
                    self.assertEqual(curve.survival_probability(self.d),
                                     curve.survival_probability(curve.time_from_reference(self.d)))
                    self.assertEqual(curve.hazard_rate(self.d),
                                     curve.hazard_rate(curve.time_from_reference(self.d)))
Beispiel #3
0
def example03():
    print("example 3:\n")
    todays_date = Date(13, 6, 2011)
    Settings.instance().evaluation_date = todays_date
    quotes = [0.00445, 0.00949, 0.01234, 0.01776, 0.01935, 0.02084]
    tenors = [1, 2, 3, 6, 9, 12]
    calendar = WeekendsOnly()
    deps = [DepositRateHelper(q, Period(t, Months), 2, calendar, ModifiedFollowing, False, Actual360())
            for q, t in zip(quotes, tenors)]
    quotes = [0.01652, 0.02018, 0.02303, 0.02525, 0.0285, 0.02931, 0.03017, 0.03092, 0.03160, 0.03231,
              0.03367, 0.03419, 0.03411, 0.03411, 0.03412]
    tenors = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 20, 25, 30]
    swaps =  [SwapRateHelper.from_tenor(q, Period(t, Years),
                                        calendar, Annual, ModifiedFollowing,
                                        Thirty360(), Euribor6M(), SimpleQuote(0)) for q, t
              in zip(quotes, tenors)]
    yield_helpers = deps + swaps
    isda_yts = PiecewiseYieldCurve(BootstrapTrait.Discount, Interpolator.LogLinear, 0,
                                   WeekendsOnly(), yield_helpers, Actual365Fixed())

    spreads = [0.007927, 0.012239, 0.016979, 0.019271, 0.020860]
    tenors = [1, 3, 5, 7, 10]
    spread_helpers = [SpreadCdsHelper(0.007927, Period(6, Months), 1,
                                      WeekendsOnly(), Quarterly, Following, Rule.CDS2015,
                                      Actual360(), 0.4, isda_yts, True, True,
                                      Date(), Actual360(True), True, PricingModel.ISDA)] + \
    [SpreadCdsHelper(s, Period(t, Years), 1, WeekendsOnly(), Quarterly, Following, Rule.CDS2015,
                     Actual360(), 0.4, isda_yts, True, True, Date(), Actual360(True), True,
                     PricingModel.ISDA)
     for s, t in zip(spreads, tenors)]
    isda_cts = PiecewiseDefaultCurve(ProbabilityTrait.SurvivalProbability,
                                     Interpolator.LogLinear, 0, WeekendsOnly(), spread_helpers,
                                     Actual365Fixed())
    isda_pricer = IsdaCdsEngine(isda_cts, 0.4, isda_yts)
    print("Isda yield curve:")
    for h in yield_helpers:
        d = h.latest_date
        t = isda_yts.time_from_reference(d)
        print(d, t, isda_yts.zero_rate(d, Actual365Fixed()).rate)

    print()
    print("Isda credit curve:")
    for h in spread_helpers:
        d = h.latest_date
        t = isda_cts.time_from_reference(d)
        print(d, t, isda_cts.survival_probability(d))
Beispiel #4
0
    #vector<pair<Date, Real> > hr_curve_data = hazardRateStructure->nodes();

    #cout << "Calibrated hazard rate values: " << endl ;
    #for (Size i=0; i<hr_curve_data.size(); i++) {
    #    cout << "hazard rate on " << hr_curve_data[i].first << " is "
    #         << hr_curve_data[i].second << endl;
    #}
    #cout << endl;


    target = todays_date + Period(1, Years)
    print target
    print "Some survival probability values: "
    print "1Y survival probability: {:%}".format(
            hazard_rate_structure.survival_probability(target)
    )
    print "               expected: {:%}".format(0.9704)

    print "2Y survival probability: {:%}".format(
        hazard_rate_structure.survival_probability(todays_date + 2*Years)
    )
    print "               expected: {:%}".format(0.9418)

    # reprice instruments
    nominal = 1000000.0;
    #Handle<DefaultProbabilityTermStructure> probability(hazardRateStructure);
    engine = MidPointCdsEngine(hazard_rate_structure, recovery_rate, ts_curve)

    cds_schedule = Schedule(
        todays_date, maturities[0], Period(Quarterly), calendar,
Beispiel #5
0
    #vector<pair<Date, Real> > hr_curve_data = hazardRateStructure->nodes();

    #cout << "Calibrated hazard rate values: " << endl ;
    #for (Size i=0; i<hr_curve_data.size(); i++) {
    #    cout << "hazard rate on " << hr_curve_data[i].first << " is "
    #         << hr_curve_data[i].second << endl;
    #}
    #cout << endl;


    target = todays_date + Period(1, Years)
    print(target)
    print("Some survival probability values: ")
    print("1Y survival probability: {:%}".format(
            hazard_rate_structure.survival_probability(target)
    ))
    print("               expected: {:%}".format(0.9704))

    print("2Y survival probability: {:%}".format(
        hazard_rate_structure.survival_probability(todays_date + Period(2, Years))
    ))
    print("               expected: {:%}".format(0.9418))

    # reprice instruments
    nominal = 1000000.0;
    #Handle<DefaultProbabilityTermStructure> probability(hazardRateStructure);
    engine = MidPointCdsEngine(hazard_rate_structure, recovery_rate, ts_curve)

    cds_schedule = Schedule(
        todays_date, maturities[0], Period(Quarterly), calendar,
Beispiel #6
0
                                                  Actual365Fixed())

    #vector<pair<Date, Real> > hr_curve_data = hazardRateStructure->nodes();

    #cout << "Calibrated hazard rate values: " << endl ;
    #for (Size i=0; i<hr_curve_data.size(); i++) {
    #    cout << "hazard rate on " << hr_curve_data[i].first << " is "
    #         << hr_curve_data[i].second << endl;
    #}
    #cout << endl;

    target = todays_date + Period(1, Years)
    print target
    print "Some survival probability values: "
    print "1Y survival probability: {:%}".format(
        hazard_rate_structure.survival_probability(target))
    print "               expected: {:%}".format(0.9704)

    print "2Y survival probability: {:%}".format(
        hazard_rate_structure.survival_probability(todays_date + 2 * Years))
    print "               expected: {:%}".format(0.9418)

    # reprice instruments
    nominal = 1000000.0
    #Handle<DefaultProbabilityTermStructure> probability(hazardRateStructure);
    engine = MidPointCdsEngine(hazard_rate_structure, recovery_rate, ts_curve)

    cds_schedule = Schedule(todays_date,
                            maturities[0],
                            Period(Quarterly),
                            calendar,