예제 #1
0
import time

# European option price
k_s = np.array([70, 80.0, 90.0, 100.0, 110.0, 120.0, 130.0])
f0 = 100
x0 = np.log(f0)
T = 1

# VG parameters
r = 0.1
sigma = 0.18
theta = -0.13
beta = 0.25

# Upper and lower bound for cos integral
a = -8 * np.sqrt(T)
b = 8 * np.sqrt(T)

cf_VG = partial(JumpDiffusionCharesticFunction.get_VG_cf,
                t=T,
                x=x0,
                r=r,
                sigma=sigma,
                beta=beta,
                theta=theta)
start_time = time.time()
cos_price = np.exp(-r * T) * COSRepresentation.get_european_option_price(
    TypeEuropeanOption.CALL, a, b, 2**14, k_s, cf_VG)
end_time = time.time()
diff_time = end_time - start_time
# Upper and lower bound for cos integral
a = -10.0
b = 10.0

# maturities
T = [0.2, 0.4, 0.6, 1.0]
markers = ['.', '+', '*', '^']
no_maturities = len(T)


for i in range(0, no_maturities):
    cf_merton = partial(JumpDiffusionCharesticFunction.get_merton_cf, t=T[i], x=x0, sigma=sigma, jumpmean=jumpmean,
                        jumpstd=jumpstd, lambda_t=lambda_t)

    # check martingale
    aux = cf_merton(np.asfortranarray(3.0))

    cos_price_merton = COSRepresentation.get_european_option_price(TypeEuropeanOption.CALL, a, b, 256, k_s, cf_merton)

    iv_smile_merton = []
    for k in range(0, no_strikes):
        iv_smile_merton.append(implied_volatility(cos_price_merton[k], f0, f0, T[i], 0.0, 0.0, 'c'))

    plt.plot(k_s, iv_smile_merton, label='T=%s' % T[i], linestyle='--', color='black', marker=markers[i])


# plt.ylim([0.0, 1.0])
plt.xlabel('K')
plt.legend()
plt.show()
예제 #3
0
cf_bates = partial(JumpDiffusionCharesticFunction.get_bates_cf,
                   t=T,
                   r_t=r,
                   x=x0,
                   v=v0,
                   theta=theta,
                   rho=rho,
                   k=k,
                   epsilon=epsilon,
                   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,
예제 #4
0
no_maturities = len(T)

for i in range(0, no_maturities):
    cf_heston = partial(HestonCharesticFunction.get_trap_cf,
                        t=T[i],
                        r_t=0.0,
                        x=x0,
                        v=v0,
                        theta=theta,
                        rho=rho,
                        k=k,
                        epsilon=epsilon,
                        b=b2,
                        u=u2)

    cos_price_heston = COSRepresentation.get_european_option_price(
        TypeEuropeanOption.CALL, a, b, 128, k_s, cf_heston)

    iv_smile_heston = []
    for j in range(0, no_strikes):
        iv_smile_heston.append(
            implied_volatility(cos_price_heston[j], f0, f0, T[i], 0.0, 0.0,
                               'c'))

    plt.plot(k_s,
             iv_smile_heston,
             label='T=%s' % T[i],
             linestyle='--',
             color='black',
             marker=markers[i])

plt.ylim([0.0, 2.0])