Example #1
0
alpha = 0.4
nu = 1.1
rho = -0.8
parameters = [alpha, nu, rho]
f0 = 100
seed = 123456789
no_paths = 100000
T = 2.0

delta = 1.0 / 32.0
no_time_steps = int(T / delta)

strike = 150.0
notional = 1.0

european_option = EuropeanOption(strike, notional, TypeSellBuy.BUY, TypeEuropeanOption.CALL, f0, T)

rnd_generator = RNG.RndGenerator(seed)

# Compute price, delta and gamma by MC and Malliavin in SABR model
start_time_malliavin = time()
map_output = SABR_Engine.get_path_multi_step(0.0, T, parameters, f0, no_paths, no_time_steps,
                                             Types.TYPE_STANDARD_NORMAL_SAMPLING.ANTITHETIC,
                                             rnd_generator)


result = european_option.get_price(map_output[Types.SABR_OUTPUT.PATHS])

price = result[0]
wide_ci = result[1]
malliavin_delta = european_option.get_malliavin_delta(map_output[Types.SABR_OUTPUT.PATHS],
Example #2
0
seed = 123456789
no_paths = 10000000
delta_time = 1.0 / 365.0

# random number generator
rnd_generator = RNG.RndGenerator(seed)

# option information
f0 = 100.0
options = []
options_shift_right = []
options_shift_left = []
shift_spot = 0.0001
for d_i in dt:
    options.append(
        EuropeanOption(f0, 1.0, TypeSellBuy.BUY, TypeEuropeanOption.CALL, f0,
                       d_i))
    options_shift_right.append(
        EuropeanOption(f0 * (1.0 + shift_spot), 1.0, TypeSellBuy.BUY,
                       TypeEuropeanOption.CALL, f0, d_i))
    options_shift_left.append(
        EuropeanOption(f0 * (1.0 - shift_spot), 1.0, TypeSellBuy.BUY,
                       TypeEuropeanOption.CALL, f0, d_i))

# outputs
implied_vol_atm = []

smile_atm_mc = []

for i in range(0, no_dt_s):
    rnd_generator.set_seed(seed)
    map_output = SABR_Engine.get_path_multi_step(
Example #3
0
k = 0.1
v0 = 0.05
theta = 0.1
rho = -0.75

# options
strikes = np.arange(60.0, 140.0, 5.0)
t_s = np.arange(0.25, 20, 0.5)
f0 = 100
T = 0.1
notional = 1.0
options_strike = []
options_time = []
for k_i in strikes:
    options_strike.append(
        EuropeanOption(k_i, notional, TypeSellBuy.BUY, TypeEuropeanOption.CALL,
                       f0, T))

for t_i in t_s:
    options_time.append(
        EuropeanOption(f0, notional, TypeSellBuy.BUY, TypeEuropeanOption.CALL,
                       f0, t_i))

# v0 effect in time dimension
# v0_s = [0.05, 0.1, 1.0, 2.0]
# style_markers = ['*', '.', 'x', '^']
# out_v0_s = get_smile_for_differents_v0(rho, epsilon, k, v0_s, theta, options_time)
#
# no_outputs = len(out_v0_s)
# for i in range(0, no_outputs):
#     plt.plot(t_s, out_v0_s[i][1], label="v0="+str(v0_s[i]), linestyle='dashed', color='black',
#              marker=style_markers[i])
rnd_generator = RNG.RndGenerator(seed)

# option information
f0 = 100.0

for i in range(0, no_maturities):
    options = []
    iv_smile = []
    rnd_generator.set_seed(seed)
    no_time_steps = np.maximum(int(T[i] * 365.0), 5)
    map_output = RBergomi_Engine.get_path_multi_step(
        0.0, T[i], parameters, f0, sigma_0, no_paths, no_time_steps,
        Types.TYPE_STANDARD_NORMAL_SAMPLING.ANTITHETIC, rnd_generator)
    for k_i in strikes:
        options.append(
            EuropeanOption(k_i, 1.0, TypeSellBuy.BUY, TypeEuropeanOption.CALL,
                           f0, T[i]))
        mc_option_price = options[-1].get_price_control_variate(
            map_output[Types.RBERGOMI_OUTPUT.PATHS][:, -1],
            map_output[Types.RBERGOMI_OUTPUT.INTEGRAL_VARIANCE_PATHS])

        iv_smile.append(
            implied_volatility(mc_option_price[0], f0, k_i, T[i], 0.0, 0.0,
                               'c'))

    plt.plot(strikes,
             iv_smile,
             label=labels[i],
             color='black',
             marker=markers[i],
             linestyle="--")
    path_to_keep = os.path.join(
Example #5
0
no_paths = 100000
delta_time = 1.0 / 365.0

# random number generator
rnd_generator = RNG.RndGenerator(seed)

# ouputs container
mc_option_price = []
var_swap_apprx_price = []

no_dt = len(dt)

for i in range(0, no_dt):
    no_time_steps = int(dt[i] / delta_time)
    rnd_generator.set_seed(seed)
    european_option = EuropeanOption(f0, 1, TypeSellBuy.BUY, TypeEuropeanOption.CALL, f0, dt[i])

    map_output = Heston_Engine.get_path_multi_step(0.0, dt[i], parameters, f0, v0, no_paths,
                                                   no_time_steps, Types.TYPE_STANDARD_NORMAL_SAMPLING.ANTITHETIC,
                                                   rnd_generator)

    characteristic_function_price = european_option.get_analytic_value(0.0, theta, rho, k, epsilon, v0, 0.0,
                                                                       model_type=Types.ANALYTIC_MODEL.HESTON_MODEL_REGULAR,
                                                                       compute_greek=False)

    results = european_option.get_price(map_output[Types.HESTON_OUTPUT.PATHS])
    mc_option_price.append(results[0])

    # price the option with var swap approximation
    analytic_price = EuropeanOptionExpansion.get_var_swap_apprx_price(f0, 1.0, TypeSellBuy.BUY, TypeEuropeanOption.CALL,
                                                                      f0, dt[i], parameters, Types.TypeModel.HESTON)
Example #6
0
d_t_forward = 0.9
T = 1.0

# random number generator
rnd_generator = RNG.RndGenerator(seed)

# option information
f0 = 100.0
options = []
normal_options = []
no_strikes = 30
strikes = np.linspace(0.7, 1.3, no_strikes)

for k_i in strikes:
    normal_options.append(
        EuropeanOption(k_i * f0, 1.0, Types.TypeSellBuy.BUY,
                       Types.TypeEuropeanOption.CALL, f0, T))
    options.append(
        ForwardStartEuropeanOption(k_i, 1.0, Types.TypeSellBuy.BUY,
                                   Types.TypeEuropeanOption.CALL, f0,
                                   d_t_forward, T))

# outputs
implied_vol_forward = []
implied_vol_spot = []

rnd_generator.set_seed(seed)
map_output = SABR_Engine.get_path_multi_step(
    0.0,
    T,
    parameters,
    f0,
seed = 123456789
no_paths = 500000
# delta_time = 1.0 / 365.0
no_time_steps = 100

# random number generator
rnd_generator = RNG.RndGenerator(seed)

# option information
f0 = 100.0
options = []
implied_vol_atm = []
for d_i in dt:
    options.append(
        EuropeanOption(f0, 1.0, TypeSellBuy.BUY, TypeEuropeanOption.CALL, f0,
                       d_i))

# outputs
vol_swap_approximation = []
vol_swap_mc = []
implied_vol_atm = []
implied_vol_approx = []
output = []

for i in range(0, no_dt_s):
    # expansion info
    lv_f0 = LocalVolFunctionals.cev_diffusion(dt[i], np.asfortranarray(f0),
                                              beta - 1.0, sigma)[0]
    fd_lv_f0 = LocalVolFunctionals.first_derive_cev_diffusion(
        dt[i], np.asfortranarray(f0), beta - 1.0, sigma)[0]
    sd_lv_f0 = LocalVolFunctionals.second_derive_cev_diffusion(
Example #8
0
                   jump_mean=muJ,
                   jump_std=sigmaJ,
                   jump_intensity=lambdaJ,
                   b=b2,
                   u=u2)
start_time = time.time()
cos_price = COSRepresentation.get_european_option_price(
    TypeEuropeanOption.CALL, a, b, 256, k_s, cf_bates)
end_time = time.time()
diff_time = end_time - start_time
print(diff_time)

start_time = time.time()
price_cf_integration = []
for i in range(0, no_strikes):
    european_option = EuropeanOption(k_s[i], 1.0, TypeSellBuy.BUY,
                                     TypeEuropeanOption.CALL, f0, T)
    price_cf_integration.append(
        european_option.get_analytic_value(
            r,
            theta,
            rho,
            k,
            epsilon,
            v0,
            muJ,
            sigmaJ,
            lambdaJ,
            model_type=Types.ANALYTIC_MODEL.BATES_MODEL_LEWIS,
            compute_greek=False))

end_time = time.time()
# bins = np.linspace(a, b, 200)
#
# plt.hist(approx_I_t, bins, label='approximation')
# plt.hist(sampling_I_t, bins, label='empirical')
#
# plt.legend()
# plt.show()

# option price comparison
no_strikes = 40
strikes = np.linspace(50.0, 160.0, no_strikes)
prices_multistep = []
prices_onestep = []

for i in range(0, no_strikes):
    option = EuropeanOption(strikes[i], 1.0, TypeSellBuy.BUY,
                            TypeEuropeanOption.CALL, f0, t)
    prices_multistep.append(
        option.get_price_control_variate(
            output[SABR_OUTPUT.PATHS][:, -1],
            output[SABR_OUTPUT.INTEGRAL_VARIANCE_PATHS])[0])
    prices_onestep.append(option.get_price(paths_one_step[:])[0])

plt.plot(strikes, prices_onestep, label='sabr one step')
plt.plot(strikes, prices_multistep, label='sabr multi step')
plt.title("T= %s" % t)
plt.xlabel("K")

plt.legend()
plt.show()
Example #10
0
d_t_forward = 0.9
T = 1.0

# random number generator
rnd_generator = RNG.RndGenerator(seed)

# option information
f0 = 10.0
options = []
normal_options = []
no_strikes = 30
strikes = np.linspace(0.9, 1.1, no_strikes)
# strikes = [1.0]

for k_i in strikes:
    normal_options.append(EuropeanOption(k_i * f0, 1.0, Types.TypeSellBuy.BUY, Types.TypeEuropeanOption.CALL, f0, T))
    options.append(ForwardStartEuropeanOption(k_i, 1.0, Types.TypeSellBuy.BUY, Types.TypeEuropeanOption.CALL,
                                              f0, d_t_forward, T))

# outputs
implied_vol_forward = []
# implied_vol_hagan = []
implied_vol_spot = []

rnd_generator.set_seed(seed)
map_output = LocalVolEngine.get_path_multi_step(0.0, T, f0, no_paths, no_time_steps,
                                                Types.TYPE_STANDARD_NORMAL_SAMPLING.ANTITHETIC, local_vol_mc,
                                                rnd_generator, extra_sampling_points=[d_t_forward])

# expansion_hagan = ExpansionLocVol.hagan_loc_vol(lambda t: sigma,
#                                                 lambda x: np.power(x, beta),
Example #11
0
# random number generator
rnd_generator = RNG.RndGenerator(seed)

# option information
f0 = 100.0
T_s = [0.1, 0.2, 0.4, 0.6, 1.0]
markers = ['.', '+', '*', '^', 'v']
no_strikes = 22
k_s = np.linspace(80.0, 120.0, no_strikes)

no_k_s = len(k_s)
no_T_s = len(T_s)

options = []
for t_i in T_s:
    options.append(EuropeanOption(f0, 1.0, TypeSellBuy.BUY, TypeEuropeanOption.CALL, f0, t_i))

for i in range(0, no_T_s):

    rnd_generator.set_seed(seed)

    map_output = RBergomi_Engine.get_path_multi_step(0.0, T_s[i], parameters, f0, v0, no_paths,
                                                     no_time_steps, Types.TYPE_STANDARD_NORMAL_SAMPLING.ANTITHETIC,
                                                     rnd_generator)

    options = []
    for k_i in k_s:
        options.append(EuropeanOption(k_i, 1.0, TypeSellBuy.BUY, TypeEuropeanOption.CALL, f0, T_s[i]))

    implied_vol = []
    for j in range(0, no_k_s):
no_paths = 10000000
delta_time = 1.0 / 365.0

# random number generator
rnd_generator = RNG.RndGenerator(seed)

# option information
# options
strikes = np.linspace(70.0, 130.0, 30)
no_strikes = len(strikes)
f0 = 100
T = 0.1
notional = 1.0
options = []
for k_i in strikes:
    options.append(EuropeanOption(k_i, notional, TypeSellBuy.BUY, TypeEuropeanOption.CALL, f0, T))


map_output = SABR_Engine.get_path_multi_step(0.0, T, parameters, f0, no_paths, no_time_steps,
                                             Types.TYPE_STANDARD_NORMAL_SAMPLING.REGULAR_WAY, rnd_generator)

iv_vol = []
for i in range(0, no_strikes):
    rnd_generator.set_seed(seed)
    mc_option_price = options[i].get_price_control_variate(map_output[Types.SABR_OUTPUT.PATHS][:, -1],
                                                           map_output[Types.SABR_OUTPUT.INTEGRAL_VARIANCE_PATHS])
    
    iv_vol.append(implied_volatility(mc_option_price[0], f0, strikes[i], T, 0.0, 0.0, 'c'))


plt.plot(strikes, iv_vol, label="rho=%s" % rho, marker=".", linestyle="--", color="black")
a = -2.0
b = 2.0

cf_heston = partial(HestonCharesticFunction.get_trap_cf, t=T, r_t=0.0, x=x0, v=v0, theta=theta, rho=rho, k=k, epsilon=epsilon, b=b2, u=u2)
start_time = time.time()
cos_price = COSRepresentation.get_european_option_price(TypeEuropeanOption.CALL, a, b, 64, k_s, cf_heston)
end_time = time.time()
diff_time = end_time - start_time

# Integration HestonĀ“s charestic function
price_cf_integration = []
no_strikes = len(k_s)

start_time = time.time()
for i in range(0, no_strikes):
    european_option = EuropeanOption(k_s[i], 1.0, TypeSellBuy.BUY, TypeEuropeanOption.CALL, f0, T)
    price_cf_integration.append(european_option.get_analytic_value(0.0, theta, rho, k, epsilon, v0, 0.0,
                                                                   model_type=Types.ANALYTIC_MODEL.HESTON_MODEL_LEWIS,
                                                                   compute_greek=False))
end_time = time.time()
diff_time_cf = end_time - start_time

print(diff_time)
print(diff_time_cf)

plt.plot(k_s, cos_price, label="cos method")
plt.plot(k_s, price_cf_integration, label="integration cf")

plt.legend()
plt.show()