def get_conditional_moment_order_one(alpha_t, alpha, nu, t):
    no_paths = len(alpha_t)
    mean_z = np.empty(no_paths)
    nu_t = nu * np.sqrt(t)
    mult = 0.5 * alpha * alpha * np.sqrt(t) / nu

    for i in range(0, no_paths):
        x_z = np.log(alpha_t[i] / alpha[i]) / nu_t
        d_right = x_z + nu_t
        d_left = x_z - nu_t

        mean_z[i] = mult[i] * (ndtr(d_right) - ndtr(d_left)) / normal_pdf(
            0.0, 1.0, d_right)

    return mean_z
def get_conditional_moment_order_two(alpha_t, alpha, nu, t):
    no_paths = len(alpha_t)
    moment_z = np.empty(no_paths)
    nu_t = nu * np.sqrt(t)
    mult = 0.25 * np.power(alpha, 4.0) * np.sqrt(t) / np.power(nu, 3.0)

    for i in range(0, no_paths):
        shift = (1.0 + np.power(alpha_t[i] / alpha[i], 2.0))
        x_z = np.log(alpha_t[i] / alpha[i]) / nu_t
        d_right = x_z + nu_t
        d_left = x_z - nu_t
        term_1 = mult[i] * shift * (ndtr(d_right) - ndtr(d_left)) / normal_pdf(
            0.0, 1.0, d_right)
        term_2 = mult[i] * (ndtr(d_right + nu_t) -
                            ndtr(d_left - nu_t)) / normal_pdf(
                                0.0, 1.0, d_right + nu_t)
        moment_z[i] = -term_1 + term_2

    return moment_z
示例#3
0
def black_scholes(f0: float, k: float, sigma: float, t: float, is_call: int):
    sqtr_t = np.sqrt(t)
    d_1 = (np.log(f0 / k) / (sigma * sqtr_t)) + 0.5 * sigma * sqtr_t
    d_2 = d_1 - sigma * sqtr_t
    return f0 * ndtr(d_1) - k * ndtr(d_2)
示例#4
0
def test_ndtr():
    assert_almost_equal(ndtr(0.3), 0.617911422189)
    assert_almost_equal(erf(1.3), 0.9340079449406524)
    assert_almost_equal(erfc(0.3), 0.671373240541)