Exemplo n.º 1
0
def iv_at_the_money(dt_date, dt_last, name_code):
    dict_iv_call = {}
    dict_iv_put = {}
    df_metrics = get_data.get_comoption_mktdata(dt_last, dt_date, name_code)
    optionset = BaseOptionSet(df_metrics, rf=0.0)
    optionset.init()
    dt_maturity = optionset.select_maturity_date(0, 0)
    call_list, put_list = optionset.get_options_list_by_moneyness_mthd1(
        0, dt_maturity)
    atm_call = optionset.select_higher_volume(call_list)
    atm_put = optionset.select_higher_volume(put_list)
    iv_call = atm_call.get_implied_vol() * 100
    iv_put = atm_put.get_implied_vol() * 100
    dict_iv_call.update({dt_last: iv_call})
    dict_iv_put.update({dt_last: iv_put})
    optionset.go_to(dt_date)
    dt_maturity = optionset.select_maturity_date(0, 0)
    call_list, put_list = optionset.get_options_list_by_moneyness_mthd1(
        0, dt_maturity)
    atm_call = optionset.select_higher_volume(call_list)
    atm_put = optionset.select_higher_volume(put_list)
    iv_call = atm_call.get_implied_vol() * 100
    iv_put = atm_put.get_implied_vol() * 100
    dict_iv_call.update({dt_date: iv_call})
    dict_iv_put.update({dt_date: iv_put})
    return dict_iv_call, dict_iv_put
Exemplo n.º 2
0
def iv_volume_weighted(dt_date, dt_last, name_code):
    dict_iv = {}
    df_metrics = get_data.get_comoption_mktdata(dt_last, dt_date, name_code)
    optionset = BaseOptionSet(df_metrics)
    optionset.init()
    dt_maturity = optionset.select_maturity_date(0, 0)
    iv_volume_weighted = optionset.get_volume_weighted_iv(dt_maturity) * 100
    dict_iv.update({dt_last: iv_volume_weighted})
    optionset.go_to(dt_date)
    dt_maturity = optionset.select_maturity_date(0, 0)
    iv_volume_weighted = optionset.get_volume_weighted_iv(dt_maturity) * 100
    dict_iv.update({dt_date: iv_volume_weighted})
    return dict_iv
Exemplo n.º 3
0
def iv_htbr(dt_date, dt_last, name_code):
    dict_iv = {}
    df_metrics = get_data.get_comoption_mktdata(dt_last, dt_date, name_code)
    optionset = BaseOptionSet(df_metrics, rf=0)
    optionset.init()
    dt_maturity = optionset.select_maturity_date(0, 0)
    iv_curve_htbr = optionset.get_implied_vol_curves_htbr(dt_maturity)
    call_list, put_list = optionset.get_options_list_by_moneyness_mthd1(
        0, dt_maturity)
    atm_k = call_list[0].applicable_strike()
    iv = iv_curve_htbr[iv_curve_htbr[c.Util.AMT_APPLICABLE_STRIKE] == atm_k][
        c.Util.PCT_IV_PUT_BY_HTBR].values[0] * 100
    dict_iv.update({dt_last: iv})
    optionset.go_to(dt_date)
    dt_maturity = optionset.select_maturity_date(0, 0)
    iv_curve_htbr = optionset.get_implied_vol_curves_htbr(dt_maturity)
    call_list, put_list = optionset.get_options_list_by_moneyness_mthd1(
        0, dt_maturity)
    atm_k = call_list[0].applicable_strike()
    iv = iv_curve_htbr[iv_curve_htbr[c.Util.AMT_APPLICABLE_STRIKE] == atm_k][
        c.Util.PCT_IV_PUT_BY_HTBR].values[0] * 100
    dict_iv.update({dt_date: iv})
    return dict_iv
Exemplo n.º 4
0
import back_test.model.constant as c
import datetime
""""""
name_code = c.Util.STR_M
core_id = 'm_1901'
end_date = datetime.date(2018, 9, 7)
last_week = datetime.date(2018, 8, 31)
start_date = last_week
dt_histvol = start_date - datetime.timedelta(days=200)
min_holding = 5

df_metrics = get_data.get_comoption_mktdata(start_date, end_date, name_code)
""" T-quote IV """
optionset = BaseOptionSet(df_metrics, rf=0)
optionset.init()
optionset.go_to(end_date)
dt_maturity = optionset.select_maturity_date(0, min_holding)
call_list, put_list = optionset.get_options_list_by_moneyness_mthd1(
    0, dt_maturity)
atm_call = optionset.select_higher_volume(call_list)
atm_put = optionset.select_higher_volume(put_list)
print('atm call iv: ', atm_call.get_implied_vol())
print('atm put iv: ', atm_put.get_implied_vol())
print('atm strike: ', atm_put.strike())

t_quote = optionset.get_T_quotes(dt_maturity)
ivs_c1 = optionset.get_call_implied_vol_curve(dt_maturity)
ivs_p1 = optionset.get_put_implied_vol_curve(dt_maturity)
ivs_c2 = optionset.get_call_implied_vol_curve_htbr(dt_maturity)
ivs_p2 = optionset.get_put_implied_vol_curve_htbr(dt_maturity)