Exemple #1
0
 def test_heston(self):
     N = 100
     L = 10
     S0 = 100
     t = 0.5
     k = 2
     r = 0.03
     q = 0
     sigma = 0.5
     theta = 0.04
     V0 = 0.04
     rho = -0.7
     strike = 90
     c1, c2, c4 = cumulants_from_mgf(general_log_moneyness_mgf,
                                     strike,
                                     Heston(V0, theta, k, sigma,
                                            rho).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 = 13.2023
     res = cosin_vanilla_call(
         N, strike, intv_a, intv_b, t, r, q, S0,
         Heston(V0, theta, k, sigma, rho).set_type('chf'))
     self.assertAlmostEqual(exp_res, res, 3)
Exemple #2
0
    def test_carr_madan_fft_heston(self):
        N = 2 ** 15
        d_u = 0.01
        alpha = 1

        S0 = 100
        t = 0.5
        k = 2
        r = 0.03
        q = 0
        sigma = 0.5
        theta = 0.04
        V0 = 0.04
        rho = -0.7
        strike, call_prices = carr_madan_fft_call_pricer(N, d_u, alpha, r, t, S0, q, Heston(V0, theta, k, sigma, rho).set_type('chf'))
        ffn_pricer = spline_fitting(strike, call_prices, 2)
        exp_res = 13.2023
        res = ffn_pricer(90)
        self.assertAlmostEqual(exp_res, res, 4)