execution_record = account.dict_holding[ order.id_instrument].execute_order( order, slippage=0, execute_type=c.ExecuteType.EXECUTE_ALL_UNITS) account.add_record(execution_record, account.dict_holding[order.id_instrument]) account.daily_accounting(optionset.eval_date) print(optionset.eval_date, ' close out ') print(optionset.eval_date, hedging.eval_date, account.account.loc[optionset.eval_date, c.Util.PORTFOLIO_NPV], int(account.cash)) break if not empty_position: moneyness_put = optionset.get_option_moneyness(atm_put) moneyness_call = optionset.get_option_moneyness(atm_call) if close_signal(optionset.eval_date, maturity1, df_iv_stats): for option in account.dict_holding.values(): order = account.create_close_order(option) record = option.execute_order(order, slippage=slippage) account.add_record(record, option) 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(
list_atm_call, list_atm_put = optionset.get_options_list_by_moneyness_mthd1( moneyness, maturity1) if list_atm_put is None: # list_atm_call, list_atm_put = optionset.get_options_list_by_moneyness_mthd1(0, maturity1) list_atm_put = optionset.get_deepest_otm_put_list( maturity1) atm_put = optionset.select_higher_volume(list_atm_put) underlying_value = unit_underlying * underlying.mktprice_close( ) * underlying.multiplier() unit = get_option_unit(atm_put, underlying_value, target_delta) order = account.create_trade_order(atm_put, c.LongShort.LONG, unit) record = atm_put.execute_order(order, slippage=slippage) account.add_record(record, atm_put) else: option_moneyness = optionset.get_option_moneyness(atm_put) if abs(option_moneyness - moneyness) > 1: # shift strike order = account.create_close_order(atm_put) execution_record = account.dict_holding[ order.id_instrument].execute_order( order, slippage=slippage, execute_type=c.ExecuteType.EXECUTE_ALL_UNITS) account.add_record( execution_record, account.dict_holding[order.id_instrument]) list_atm_call, list_atm_put = optionset.get_options_list_by_moneyness_mthd1( moneyness, maturity1) if list_atm_put is None: # list_atm_call, list_atm_put = optionset.get_options_list_by_moneyness_mthd1(0, maturity1) list_atm_put = optionset.get_deepest_otm_put_list(