Пример #1
0
def get_iv(row, bidorask):
    b_s = BlackScholes(row['underlying_price'], interest_rate, dividend, ttm)
    if bidorask == 'bid':
        iv = b_s.BS_impliedVol(row['Strike'],
                               row['m_bid'] * row['underlying_price'],
                               row['CallPut'])
    elif bidorask == 'ask':
        iv = b_s.BS_impliedVol(row['Strike'],
                               row['m_ask'] * row['underlying_price'],
                               row['CallPut'])
    else:
        iv = b_s.BS_impliedVol(row['Strike'],
                               row['m_mid'] * row['underlying_price'],
                               row['CallPut'])
    return iv
Пример #2
0
    strike_list = list(asset_call_df['Strike'])

    vv_vol_list = []
    for K in strike_list:
        t = np.mean(asset_call_df['mtr'])
        f = np.mean(asset_call_df['underlying_price'])
        ATM_vol = delta25_call_df.loc[1, 'm_mid_vol']
        K1, K2, K3 = delta25_call_df.loc[0, 'Strike'], delta25_call_df.loc[1, 'Strike'], delta25_call_df.loc[2, 'Strike']
        mkt_price_K1 = delta25_call_df.loc[0, 'm_mid'] * delta25_call_df.loc[0, 'underlying_price']
        mkt_price_K3 = delta25_call_df.loc[2, 'm_mid'] * delta25_call_df.loc[0, 'underlying_price']
        weight_list = calculate_weight(f, t, ATM_vol, K, K1, K2, K3)
        price = calculate_price(f,t, ATM_vol, K, K1, K2, K3, mkt_price_K1, mkt_price_K3)
        delta = vanna_volga_delta(f, t, ATM_vol, K, K1, K2, K3, mkt_price_K1, mkt_price_K3)

        b_s = BlackScholes(f,0,0,t)
        vv_vol = b_s.BS_impliedVol(K, price, 'C')
        vv_vol_list.append(vv_vol)
    asset_call_df['VV_vol'] = vv_vol_list
    result_df = result_df.append(asset_call_df)
result_df.to_csv('D:\\SABR model/vol_data/SABR_VV_model_param.csv')





vol_fit = [SABR.lognormal_vol(k_, f, t, param[0], 1, param[1], param[2]) * 100 for k_ in strike_list]
#vol_surface_df.loc[t, strike_list] = vol_fit
plt.figure(figsize=(6, 6))
fig = plt.figure(1)
ax1 = plt.subplot(111)
ax1.plot(strike_list, vol_fit, label = 'SABR')