Пример #1
0
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)
    var_swap_apprx_price.append(analytic_price)


plt.plot(dt, mc_option_price, label='mc price')
plt.plot(dt, var_swap_apprx_price, label='variance swap approximation')

plt.legend()
plt.title('ATM option price')
plt.show()
Пример #2
0
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],
                                                      map_output[Types.SABR_OUTPUT.DELTA_MALLIAVIN_WEIGHTS_PATHS_TERMINAL])

malliavin_gamma = european_option.get_malliavin_gamma(map_output[Types.SABR_OUTPUT.PATHS],
                                                      map_output[Types.SABR_OUTPUT.GAMMA_MALLIAVIN_WEIGHTS_PATHS_TERMINAL])

end_time_malliavin = time()
diff_time_malliavin = (end_time_malliavin - start_time_malliavin)

# Compute delta and gamma by bumping in SABR model
delta_shift = 0.001
f0_right_shift = f0 * (1.0 + delta_shift)
# 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()