def sample_933(): """ 9.3.3 GridSearch寻找最优参数 :return: """ from abupy import GridSearch read_cash = 1000000 choice_symbols = ['usNOAH', 'usSFUN', 'usBIDU', 'usAAPL', 'usGOOG', 'usTSLA', 'usWUBA', 'usVIPS'] sell_factors_product, buy_factors_product = sample_932(show=False) grid_search = GridSearch(read_cash, choice_symbols, buy_factors_product=buy_factors_product, sell_factors_product=sell_factors_product) from abupy import ABuFileUtil """ 注意下面的运行耗时大约1小时多,如果所有cpu都用上的话,也可以设置n_jobs为 < cpu进程数,一边做其它的一边跑 """ # 运行GridSearch n_jobs=-1启动cpu个数的进程数 scores, score_tuple_array = grid_search.fit(n_jobs=-1) """ 针对运行完成输出的score_tuple_array可以使用dump_pickle保存在本地,以方便修改其它验证效果。 """ ABuFileUtil.dump_pickle(score_tuple_array, '../gen/score_tuple_array') print('组合因子参数数量{}'.format(len(buy_factors_product) * len(sell_factors_product))) print('最终评分结果数量{}'.format(len(scores))) best_score_tuple_grid = grid_search.best_score_tuple_grid AbuMetricsBase.show_general(best_score_tuple_grid.orders_pd, best_score_tuple_grid.action_pd, best_score_tuple_grid.capital, best_score_tuple_grid.benchmark)
def sample_933(): """ 9.3.3 GridSearch寻找最优参数 :return: """ from abupy import GridSearch read_cash = 1000000 choice_symbols = ['usNOAH', 'usSFUN', 'usBIDU', 'usAAPL', 'usGOOG', 'usTSLA', 'usWUBA', 'usVIPS'] sell_factors_product, buy_factors_product = sample_932(show=False) grid_search = GridSearch(read_cash, choice_symbols, buy_factors_product=buy_factors_product, sell_factors_product=sell_factors_product) from abupy import ABuFileUtil """ 注意下面的运行耗时大约1小时多,如果所有cpu都用上的话,也可以设置n_jobs为 < cpu进程数,一边做其它的一边跑 """ # 运行GridSearch n_jobs=-1启动cpu个数的进程数 scores, score_tuple_array = grid_search.fit(n_jobs=-1) """ 针对运行完成输出的score_tuple_array可以使用dump_pickle保存在本地,以方便修改其它验证效果。 """ ABuFileUtil.dump_pickle(score_tuple_array, '../gen/score_tuple_array') print('组合因子参数数量{}'.format(len(buy_factors_product) * len(sell_factors_product))) print('最终评分结果数量{}'.format(len(scores))) best_score_tuple_grid = grid_search.best_score_tuple_grid AbuMetricsBase.show_general(best_score_tuple_grid.orders_pd, best_score_tuple_grid.action_pd, best_score_tuple_grid.capital, best_score_tuple_grid.benchmark)
def run_grid_search(): global scores, score_tuple_array # 运行GridSearch n_jobs=-1启动cpu个数的进程数 scores, score_tuple_array = grid_search.fit(n_jobs=-1) # 运行完成输出的score_tuple_array可以使用dump_pickle保存在本地,以方便之后使用 ABuFileUtil.dump_pickle(score_tuple_array, '../gen/score_tuple_array')