def calculate_weight(underlying, mtr, ATM_vol, K, K1, K2, K3): b_s = BlackScholes(underlying, 0, 0, mtr) vega_K = b_s.BS_vega(K, ATM_vol) vega_K_1 = b_s.BS_vega(K1, ATM_vol) vega_K_2 = b_s.BS_vega(K2, ATM_vol) vega_K_3 = b_s.BS_vega(K3, ATM_vol) weight_1 = (vega_K * np.log(K2 / K) * np.log(K3 / K)) / (vega_K_1 * np.log(K2 / K1) * np.log(K3 / K1)) weight_2 = (vega_K * np.log(K / K1) * np.log(K3 / K)) / (vega_K_2 * np.log(K2 / K1) * np.log(K3 / K2)) weight_3 = (vega_K * np.log(K / K1) * np.log(K / K2)) / (vega_K_3 * np.log(K3 / K1) * np.log(K3 / K2)) return [weight_1, weight_2, weight_3]
def SABR_vega(f, t, k, alpha, beta, rho, volvol): b_s = BlackScholes(f, 0, 0, t) atm_vol = ATM_vol(f, t, alpha, beta, rho, volvol) strike_vol = 100 * lognormal_vol(k, f, t, alpha, beta, rho, volvol) bs_vega = b_s.BS_vega(k, strike_vol) vega = bs_vega * strike_vol / atm_vol return vega
def SABR_delta_2(f, t, k, CallPut, alpha, beta, rho, volvol): f2 = f * 1.01 b_s = BlackScholes(f, 0, 0, t) SABR_vol = lognormal_vol(k, f, t, alpha, beta, rho, volvol) * 100 SABR_vol_shift = lognormal_vol(k, f2, t, alpha, beta, rho, volvol) * 100 bs_delta = b_s.BS_delta(k, SABR_vol, CallPut) bs_vega = b_s.BS_vega(k, SABR_vol) delta = bs_delta + bs_vega * (SABR_vol_shift - SABR_vol) / (f2 - f) return delta
def SABR_delta_3(f, t, k, CallPut, alpha, beta, rho, volvol): f2 = f * 1.01 b_s = BlackScholes(f, 0, 0, t) SABR_vol = lognormal_vol(k, f, t, alpha, beta, rho, volvol) * 100 SABR_vol_shift = lognormal_vol(k, f2, t, alpha, beta, rho, volvol) * 100 bs_delta = b_s.BS_delta(k, SABR_vol, CallPut) bs_vega = b_s.BS_vega(k, SABR_vol) SABR_vol_alpha_shift = lognormal_vol(k, f, t, alpha * 1.01, beta, rho, volvol) * 100 alpha_deri = (SABR_vol - SABR_vol_alpha_shift) / (alpha - 1.01 * alpha) delta = bs_delta + bs_vega * ((SABR_vol_shift - SABR_vol) / (f2 - f) + alpha_deri * (rho * volvol / (f**beta))) return delta
def get_greeks(row, greek): b_s = BlackScholes(row['underlying_price'], 0, 0, row['mtr']) if greek == 'gamma': result = b_s.BS_gamma(row['Strike'], row['m_mid_vol']) elif greek == 'theta': result = b_s.BS_theta(row['Strike'], row['m_mid_vol'], row['CallPut']) elif greek == 'vega': result = b_s.BS_vega(row['Strike'], row['m_mid_vol']) elif greek == 'delta': result = b_s.BS_delta(row['Strike'], row['m_mid_vol'], row['CallPut']) elif greek == 'vanna': result = b_s.BS_vanna(row['Strike'], row['m_mid_vol']) elif greek == 'volga': result = b_s.BS_volga(row['Strike'], row['m_mid_vol']) elif greek == 'gamma_deri': result = b_s.BS_gamma_deri(row['Strike'], row['m_mid_vol']) return result