def sample_932(show=True): """ 9.3.2 参数进行排列组合 :return: """ from abupy import ABuGridHelper sell_factors_product = ABuGridHelper.gen_factor_grid( ABuGridHelper.K_GEN_FACTOR_PARAMS_SELL, [sell_atr_nstop_factor_grid, sell_atr_pre_factor_grid, sell_atr_close_factor_grid]) if show: print('卖出因子参数共有{}种组合方式'.format(len(sell_factors_product))) print('卖出因子组合0形式为{}'.format(sell_factors_product[0])) buy_bk_factor_grid1 = { 'class': [AbuFactorBuyBreak], 'xd': [42] } buy_bk_factor_grid2 = { 'class': [AbuFactorBuyBreak], 'xd': [60] } buy_factors_product = ABuGridHelper.gen_factor_grid( ABuGridHelper.K_GEN_FACTOR_PARAMS_BUY, [buy_bk_factor_grid1, buy_bk_factor_grid2]) if show: print('买入因子参数共有{}种组合方式'.format(len(buy_factors_product))) print('买入因子组合形式为{}'.format(buy_factors_product)) return sell_factors_product, buy_factors_product
def sample_932(show=True): """ 9.3.2 参数进行排列组合 :return: """ from abupy import ABuGridHelper sell_factors_product = ABuGridHelper.gen_factor_grid( ABuGridHelper.K_GEN_FACTOR_PARAMS_SELL, [ sell_atr_nstop_factor_grid, sell_atr_pre_factor_grid, sell_atr_close_factor_grid ]) if show: print('卖出因子参数共有{}种组合方式'.format(len(sell_factors_product))) print('卖出因子组合0形式为{}'.format(sell_factors_product[0])) buy_bk_factor_grid1 = {'class': [AbuFactorBuyBreak], 'xd': [42]} buy_bk_factor_grid2 = {'class': [AbuFactorBuyBreak], 'xd': [60]} buy_factors_product = ABuGridHelper.gen_factor_grid( ABuGridHelper.K_GEN_FACTOR_PARAMS_BUY, [buy_bk_factor_grid1, buy_bk_factor_grid2]) if show: print('买入因子参数共有{}种组合方式'.format(len(buy_factors_product))) print('买入因子组合形式为{}'.format(buy_factors_product)) return sell_factors_product, buy_factors_product
targetUpAng = np.arange(200,310,1000) targetDownAng = np.arange(-30,-20,3000) skip_days_value = [0] xd_value_range = np.arange(200,201,1) stopWinSellPriceRate = [0.08] stopLoseSellPriceRate = [-0.08] waveMax = [8] waveMin = [-8] startDate='2019-05-09' endDate='2020-03-06' jiJinWave_grid = {'class': [AbujiJinWave], 'jiJinWaveAble':jiJinWaveAble,'windowBuy':windowBuy,'windowSell':windowSell, 'poly':poly,'xd':xd_value_range,'skip_days_value':skip_days_value,'pears_value':pears_value, 'targetUpAng':targetUpAng,'targetDownAng':targetDownAng, 'stopWinSellPriceRate':stopWinSellPriceRate,'stopLoseSellPriceRate':stopLoseSellPriceRate,'waveMax':waveMax,'waveMin':waveMin} buy_factors_product = ABuGridHelper.gen_factor_grid(ABuGridHelper.K_GEN_FACTOR_PARAMS_BUY,[jiJinWave_grid]) # abupy.slippage.sbm.g_max_down_rate = 0.03 for buy_factors_product_item in buy_factors_product: # buy_factors_product_item[0]['slippage'] = AbuSlippageBuyMinMax #指定买入滑点类 buy_factors_product_item[0]['slippage'] = AbuSlippageBuyOpen #指定买入滑点类 print('买入因子参数共有{}种组合方式'.format(len(buy_factors_product))) #----------------------------卖出因子----------------------------- sell_n_range = windowBuy # sell_n_range = np.arange(1,2,1) # #设定买入后只持有天数,默认1 is_sell_today = True #设定买入n天后,当天还是隔天卖出。默认False。 # sell_atr_nstop_factor_grid = {'class':[AbuFactorSellNDay],'sell_n':sell_n_range} sell_atr_nstop_factor_grid = {'class':[AbuFactorSellJiJinWave]} # sell_atr_nstop_factor_grid = {'class':[AbuFactorSellMinMax]}
close_atr_range = np.arange(1.0, 4.0, 0.5) pre_atr_range = np.arange(1.0, 3.5, 0.5) sell_atr_pre_factor_grid = { 'class': [AbuFactorPreAtrNStop], 'pre_atr_n': pre_atr_range } sell_atr_close_factor_grid = { 'class': [AbuFactorCloseAtrNStop], 'close_atr_n': close_atr_range } sell_factors_product = ABuGridHelper.gen_factor_grid( ABuGridHelper.K_GEN_FACTOR_PARAMS_SELL, [ sell_atr_nstop_factor_grid, sell_atr_pre_factor_grid, sell_atr_close_factor_grid ], need_empty_sell=True) buy_bk_factor_grid1 = {'class': [AbuFactorBuyBreak], 'xd': [42]} buy_bk_factor_grid2 = {'class': [AbuFactorBuyBreak], 'xd': [60]} buy_factors_product = ABuGridHelper.gen_factor_grid( ABuGridHelper.K_GEN_FACTOR_PARAMS_BUY, [buy_bk_factor_grid1, buy_bk_factor_grid2]) read_cash = 100000 choice_symbols = ['usAAPL', 'usTSLA', 'usTQQQ'] grid_search = GridSearch(read_cash, choice_symbols,