hedging.synthetic_unit = 0 empty_position = True if empty_position and open_signal(optionset.eval_date, df_iv_stats): buy_write = c.BuyWrite.WRITE long_short = c.LongShort.SHORT maturity1 = optionset.select_maturity_date(nbr_maturity=0, min_holding=15) list_atm_call, list_atm_put = optionset.get_options_list_by_moneyness_mthd1( 0, maturity1) atm_call = optionset.select_higher_volume(list_atm_call) atm_put = optionset.select_higher_volume(list_atm_put) atm_strike = atm_call.strike() spot = atm_call.underlying_close() # if abs(atm_strike-spot) < 0.5: # 存在平值期权 hedging.amt_option = 1 / 1000 # 50ETF与IH点数之比 unit_c = np.floor( np.floor(account.portfolio_total_value / atm_call.strike()) / atm_call.multiplier()) * m unit_p = np.floor( np.floor(account.portfolio_total_value / atm_put.strike()) / atm_put.multiplier()) * m order_c = account.create_trade_order(atm_call, long_short, unit_c) order_p = account.create_trade_order(atm_put, long_short, unit_p) record_call = atm_call.execute_order(order_c, slippage=slippage) record_put = atm_put.execute_order(order_p, slippage=slippage) account.add_record(record_call, atm_call) account.add_record(record_put, atm_put) empty_position = False if not empty_position: # Delta hedge
empty_position = True if empty_position and open_signal(optionset.eval_date, df_iv_stats): buy_write = c.BuyWrite.WRITE long_short = c.LongShort.SHORT maturity1 = optionset.select_maturity_date(nbr_maturity=0, min_holding=15) list_atm_call, list_atm_put = optionset.get_options_list_by_moneyness_mthd1( 0, maturity1) atm_call = optionset.select_higher_volume(list_atm_call) atm_put = optionset.select_higher_volume(list_atm_put) atm_strike = atm_call.strike() spot = atm_call.underlying_close() # if abs(atm_strike-spot) < 0.5: # 存在平值期权 # hedging.amt_option = 1 / 1000 # 50ETF与IH点数之比 hedging.amt_option = 1 # 商品期权标的即为期货 unit_c = np.floor( np.floor(account.portfolio_total_value / atm_call.strike()) / atm_call.multiplier()) * m unit_p = np.floor( np.floor(account.portfolio_total_value / atm_put.strike()) / atm_put.multiplier()) * m order_c = account.create_trade_order(atm_call, long_short, unit_c) order_p = account.create_trade_order(atm_put, long_short, unit_p) record_call = atm_call.execute_order(order_c, slippage=slippage) record_put = atm_put.execute_order(order_p, slippage=slippage) account.add_record(record_call, atm_call) account.add_record(record_put, atm_put) empty_position = False if not empty_position: # Delta hedge