Ejemplo n.º 1
0
    def test_black_shole_3(self):
        N = 16
        L = 10
        S0 = 100
        t = 0.1
        r = 0.1
        q = 0
        sigma = 0.25

        strike = 120
        c1, c2, c4 = cumulants_from_mgf(general_log_moneyness_mgf,
                                        strike,
                                        BlackScholes(sigma).set_type('mgf'),
                                        t=t,
                                        r=r,
                                        q=q,
                                        S0=S0)
        intv_a, intv_b = interval_a_and_b(c1, c2, c4, L)
        print(intv_a, intv_b)
        exp_res = 0.044
        res = cosin_vanilla_call(N, strike, intv_a, intv_b, t, r, q, S0,
                                 BlackScholes(sigma).set_type('chf'))
        self.assertAlmostEqual(exp_res, res, 3)
        N = 64
        res = cosin_vanilla_call(N, strike, intv_a, intv_b, t, r, q, S0,
                                 BlackScholes(sigma).set_type('chf'))
        exp_res = 0.045
        self.assertAlmostEqual(exp_res, res, 3)
Ejemplo n.º 2
0
 def test_carr_madan_fft_call_pricer_black_shole(self):
     N = 2 ** 15
     d_u = 0.01
     alpha = 1
     S0 = 100
     t = 1
     r = 0.05
     q = 0
     sigma = 0.3
     strike, call_prices = carr_madan_fft_call_pricer(N, d_u, alpha, r, t, S0, q, BlackScholes(sigma).set_type('chf'))
     ffn_pricer = spline_fitting(strike, call_prices, 2)
     exp_res = 19.6974
     res = ffn_pricer(90)
     self.assertAlmostEqual(exp_res, res, 4)
Ejemplo n.º 3
0
    def test_cal_price_cosine(self):
        cosine_pricer = FourierPricer(self.vanilla_option)
        strike_arr = np.array([5, 10, 30, 36, 50, 60, 100])
        put_call_arr = np.array(['call', 'call', 'put', 'call', 'call', 'put', 'call'])
        exp = np.array([3.09958567e+01, 2.60163625e+01, 8.25753140e-05, 8.12953226e-01,
                        8.97449491e-11, 2.37785797e+01, 2.19293560e-85, ]
                       )

        volatility = 0.20
        N = 150

        cosine_pricer.set_log_st_process(BlackScholes(volatility))
        cosine_pricer.set_pricing_engine(CosineEngine(N, L=30))
        res = cosine_pricer.calc_price(strike_arr, put_call_arr, put_label='put')
        npt.assert_array_almost_equal(res, exp, 6)
Ejemplo n.º 4
0
 def test_cal_price_fractional_fft(self):
     fft_pricer = FourierPricer(self.vanilla_option)
     strike_arr = np.array([5, 10, 30, 36, 50, 60, 100])
     put_call_arr = np.array(['call', 'call', 'put', 'call', 'call', 'put', 'call'])
     exp = np.array(
         [3.09958567e+01, 2.60163625e+01, 8.25753140e-05, 8.12953226e-01,
          8.97449491e-11, 2.37785797e+01, 2.19293560e-85, ]
     )
     volatility = 0.20
     N = 2 ** 14
     d_u = 0.01
     d_k = 0.01
     alpha = 1
     fft_pricer.set_log_st_process(BlackScholes(volatility))
     fft_pricer.set_pricing_engine(FractionFFTEngine(N, d_u, d_k, alpha, spline_order=3))
     res = fft_pricer.calc_price(strike_arr, put_call_arr, put_label='put')
     npt.assert_array_almost_equal(res, exp, 6)