Ejemplo n.º 1
0
    def test_replication_bull_spread(self):
        data = util.get_real(1)
        min_put_range = 1e-10
        init_swap_rate = data[0]
        max_call_range = 10.0

        data = util.get_real(2)
        option_maturity = data[0]
        swap_rate_vol = data[1]

        data = sorted(util.get_real(2, min_put_range, max_call_range))
        lower_strike = data[0]
        upper_strike = data[1]

        pricer_helper = analytic_formula.BlackSwaptionPricerHelper()
        call_pricer = pricer_helper.make_payers_swaption_wrt_strike(
            init_swap_rate, 1.0, option_maturity, swap_rate_vol)
        put_pricer = pricer_helper.make_receivers_swaption_wrt_strike(
            init_swap_rate, 1.0, option_maturity, swap_rate_vol)

        def analytic_func(init_swap_rate):
            inner_payoff = max(init_swap_rate - lower_strike, 0.0)
            return min(inner_payoff, upper_strike)

        def analytic_lower_from_put_term_delta(init_swap_rate):
            return put_pricer(lower_strike)

        def analytic_upper_from_put_term_delta(init_swap_rate):
            return put_pricer(upper_strike)

        def analytic_lower_from_call_term_delta(init_swap_rate):
            return call_pricer(lower_strike)

        def analytic_upper_from_call_term_delta(init_swap_rate):
            return call_pricer(upper_strike)

        analytic_funcs = [analytic_func]
        if min_put_range <= lower_strike <= init_swap_rate:
            analytic_funcs.append(analytic_lower_from_put_term_delta)
        if min_put_range <= upper_strike <= init_swap_rate:
            analytic_funcs.append(analytic_upper_from_put_term_delta)
        if init_swap_rate <= lower_strike <= max_call_range:
            analytic_funcs.append(analytic_lower_from_call_term_delta)
        if init_swap_rate <= upper_strike <= max_call_range:
            analytic_funcs.append(analytic_upper_from_call_term_delta)

        put_integrands = []
        call_integrands = []
        self.target = target.AnalyticReplication(call_pricer, put_pricer,
                                                 analytic_funcs,
                                                 call_integrands,
                                                 put_integrands)
        actual = self.target.eval(init_swap_rate, min_put_range,
                                  max_call_range)
        expect = call_pricer(lower_strike) - call_pricer(upper_strike)
        assert expect == approx(actual)
Ejemplo n.º 2
0
 def setup(self):
     self.target = target.BlackSwaptionPricerHelper()
     pass
Ejemplo n.º 3
0
def linear_annuity_bull_spread_pricer(init_swap_rate, swap_annuity,
                                      vol_swap_rate, swap_fixing_date,
                                      vol_forward_fx, corr_forward_fx,
                                      cms_lower_strike, cms_upper_strike,
                                      cms_gearing, alpha0, alpha1):

    payoff_params = {
        "lower_strike": cms_lower_strike,
        "upper_strike": cms_upper_strike,
        "gearing": cms_gearing,
    }
    swap_rate_cdf = pricer_quanto_cms.make_cdf_black_swaption(
        init_swap_rate=init_swap_rate,
        swap_annuity=swap_annuity,
        option_maturity=swap_fixing_date,
        vol=vol_swap_rate)
    swap_rate_pdf = pricer_quanto_cms.make_pdf_black_swaption(
        init_swap_rate=init_swap_rate,
        swap_annuity=swap_annuity,
        option_maturity=swap_fixing_date,
        vol=vol_swap_rate)
    swap_rate_pdf_fprime = pricer_quanto_cms.make_pdf_fprime_black_swaption(
        init_swap_rate=init_swap_rate,
        swap_annuity=swap_annuity,
        option_maturity=swap_fixing_date,
        vol=vol_swap_rate)
    annuity_mapping_params = {"alpha0": alpha0, "alpha1": alpha1}
    forward_fx_diffusion_params = {
        "time": swap_fixing_date,
        "vol": vol_forward_fx,
        "corr": corr_forward_fx,
        "swap_rate_cdf": swap_rate_cdf,
        "swap_rate_pdf": swap_rate_pdf,
        "swap_rate_pdf_fprime": swap_rate_pdf_fprime,
        "is_inverse": True
    }
    payer_pricer_params = {
        "init_swap_rate": init_swap_rate,
        "swap_annuity": swap_annuity,
        "option_maturity": swap_fixing_date,
        "vol": vol_swap_rate,
    }
    bs_pricer = analytic_formula.BlackSwaptionPricerHelper()
    payer_pricer = bs_pricer.make_payers_swaption_wrt_strike(
        **payer_pricer_params)
    receiver_pricer_params = {
        "init_swap_rate": init_swap_rate,
        "swap_annuity": swap_annuity,
        "option_maturity": swap_fixing_date,
        "vol": vol_swap_rate
    }
    receiver_pricer = bs_pricer.make_receivers_swaption_wrt_strike(
        **receiver_pricer_params)
    discount_factor = 1.0
    price = pricer_quanto_cms.replicate(init_swap_rate,
                                        discount_factor,
                                        payer_pricer,
                                        receiver_pricer,
                                        "bull_spread",
                                        payoff_params,
                                        forward_fx_diffusion_params,
                                        "linear",
                                        annuity_mapping_params,
                                        min_put_range=1e-16,
                                        max_call_range=0.040)
    return price