Ejemplo n.º 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))
Ejemplo n.º 2
0
    def test_create_piecewise(self):

        todays_date, helper = create_helper()

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

                self.assertIsNotNone(curve)
Ejemplo n.º 3
0
    tenors = [Period(i, Months) for i in [3, 6, 12, 24]]
    maturities = [
        calendar.adjust(todays_date + tenors[i], Following) for i in range(4)
    ]
    instruments = []
    for i in range(4):
        helper = SpreadCdsHelper(
            quoted_spreads[i], tenors[i], 0, calendar, Quarterly,
            Following, TwentiethIMM, Actual365Fixed(), recovery_rate, ts_curve
        )

        instruments.append(helper)

    # Bootstrap hazard rates
    hazard_rate_structure = PiecewiseDefaultCurve(
        'HazardRate', 'BackwardFlat', todays_date, instruments, 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: ")