def sample_821_2(): """ 8.2.1_2 ABuPickStockExecute :return: """ stock_pickers = [{ 'class': AbuPickRegressAngMinMax, 'threshold_ang_min': 0.0, 'threshold_ang_max': 10.0, 'reversed': False }] choice_symbols = [ 'usNOAH', 'usSFUN', 'usBIDU', 'usAAPL', 'usGOOG', 'usTSLA', 'usWUBA', 'usVIPS' ] benchmark = AbuBenchmark() capital = AbuCapital(1000000, benchmark) kl_pd_manager = AbuKLManager(benchmark, capital) print( 'ABuPickStockExecute.do_pick_stock_work:\n', ABuPickStockExecute.do_pick_stock_work(choice_symbols, benchmark, capital, stock_pickers)) kl_pd_sfun = kl_pd_manager.get_pick_stock_kl_pd('usSFUN') print('sfun 选股周期内角度={}'.format( round(ABuRegUtil.calc_regress_deg(kl_pd_sfun.close), 3)))
def sample_822(): """ 8.2.2 多个选股因子并行执行 :return: """ # 选股list使用两个不同的选股因子组合,并行同时生效 stock_pickers = [{ 'class': AbuPickRegressAngMinMax, 'threshold_ang_min': 0.0, 'reversed': False }, { 'class': AbuPickStockPriceMinMax, 'threshold_price_min': 50.0, 'reversed': False }] choice_symbols = [ 'usNOAH', 'usSFUN', 'usBIDU', 'usAAPL', 'usGOOG', 'usTSLA', 'usWUBA', 'usVIPS' ] benchmark = AbuBenchmark() capital = AbuCapital(1000000, benchmark) print( 'ABuPickStockExecute.do_pick_stock_work:\n', ABuPickStockExecute.do_pick_stock_work(choice_symbols, benchmark, capital, stock_pickers))
def sample_821_2(): """ 8.2.1_2 ABuPickStockExecute :return: """ stock_pickers = [{ 'class': AbuPickRegressAngMinMax, 'threshold_ang_min': 0.0, 'threshold_ang_max': 10.0, 'reversed': False }] choice_symbols = [ '601398', '601988', '601939', '603993', '600999', '300059', '600900', '601328', '601288', '600887', '600029', '000002' ] benchmark = AbuBenchmark() capital = AbuCapital(1000000, benchmark) kl_pd_manager = AbuKLManager(benchmark, capital) print( 'ABuPickStockExecute.do_pick_stock_work:\n', ABuPickStockExecute.do_pick_stock_work(choice_symbols, benchmark, capital, stock_pickers)) kl_pd_sfun = kl_pd_manager.get_pick_stock_kl_pd('601398') print('sfun 选股周期内角度={}'.format( round(ABuRegUtil.calc_regress_deg(kl_pd_sfun.close), 3)))
def batchpick(): start = '20190101' end = '2020-11-06' # 策略 选取符合基本财务业绩指标,且短期与相关系数为负的,思路,庄股,跟大盘反着来的。这种策略适合在大盘下跌时买入 stock_pickers = [{ 'class': KPickStockValue, 'first_choice': True, 'start': start, 'end': end.replace('-', ''), 'roe_dt_2': 13, 'grossprofit_margin': 20, 'ocf_to_opincome': 0.7 }, { 'class': KPickStockStrongShake, 'first_choice': True, 'start': start, 'end': end.replace('-', ''), 'short_relation': -0.25, 'short_range': 30, 'long_range': 300, 'short_scope': 1.15, 'long_scope': 1.7, 'short_range_deg': 5 }] # 策略 选取符合基本财务业绩指标,最近1,2,3周成交量较大盘放大的,思路,选取资金涌入个股,改进(根据涌入个股分析所属板块,再延申选取相应板块优秀个股),自上而下的顺势根据当前资金涌入板块选择标的冲浪 stock_pickers = [{ 'class': KPickStockValue, 'first_choice': True, 'start': start, 'end': end.replace('-', ''), 'roe_dt_2': 8, 'grossprofit_margin': 18, 'ocf_to_opincome': 0.5 }, { 'class': KPickStockVolume, 'first_choice': True, 'start': '20200801', 'end': end.replace('-', '') }] fin_manager = KFinManager() choice_symbols = fin_manager.get_stock_basic().ts_code #choice_symbols = ['688179.SH'] benchmark = AbuBenchmark(start='2018-01-01', end=end) capital = AbuCapital(1000000, benchmark) print( 'ABuPickStockExecute.do_pick_stock_work:\n', ABuPickStockExecute.do_pick_stock_work(choice_symbols, benchmark, capital, stock_pickers))
def sample_821_3(): """ 8.2.1_3 reversed :return: """ # 和上面的代码唯一的区别就是reversed=True stock_pickers = [{'class': AbuPickRegressAngMinMax, 'threshold_ang_min': 0.0, 'threshold_ang_max': 10.0, 'reversed': True}] choice_symbols = ['usNOAH', 'usSFUN', 'usBIDU', 'usAAPL', 'usGOOG', 'usTSLA', 'usWUBA', 'usVIPS'] benchmark = AbuBenchmark() capital = AbuCapital(1000000, benchmark) print('ABuPickStockExecute.do_pick_stock_work:\n', ABuPickStockExecute.do_pick_stock_work(choice_symbols, benchmark, capital, stock_pickers))
def sample_822(): """ 8.2.2 多个选股因子并行执行 :return: """ # 选股list使用两个不同的选股因子组合,并行同时生效 stock_pickers = [{'class': AbuPickRegressAngMinMax, 'threshold_ang_min': 0.0, 'reversed': False}, {'class': AbuPickStockPriceMinMax, 'threshold_price_min': 50.0, 'reversed': False}] choice_symbols = ['usNOAH', 'usSFUN', 'usBIDU', 'usAAPL', 'usGOOG', 'usTSLA', 'usWUBA', 'usVIPS'] benchmark = AbuBenchmark() capital = AbuCapital(1000000, benchmark) print('ABuPickStockExecute.do_pick_stock_work:\n', ABuPickStockExecute.do_pick_stock_work(choice_symbols, benchmark, capital, stock_pickers))
def sample_821_2(): """ 8.2.1_2 ABuPickStockExecute :return: """ stock_pickers = [{'class': AbuPickRegressAngMinMax, 'threshold_ang_min': 0.0, 'threshold_ang_max': 10.0, 'reversed': False}] choice_symbols = ['usNOAH', 'usSFUN', 'usBIDU', 'usAAPL', 'usGOOG', 'usTSLA', 'usWUBA', 'usVIPS'] benchmark = AbuBenchmark() capital = AbuCapital(1000000, benchmark) kl_pd_manager = AbuKLManager(benchmark, capital) print('ABuPickStockExecute.do_pick_stock_work:\n', ABuPickStockExecute.do_pick_stock_work(choice_symbols, benchmark, capital, stock_pickers)) kl_pd_sfun = kl_pd_manager.get_pick_stock_kl_pd('usSFUN') print('sfun 选股周期内角度={}'.format(round(ABuRegUtil.calc_regress_deg(kl_pd_sfun.close), 3)))
def sample_821_3(): """ 8.2.1_2 ABuPickStockExecute :return: """ stock_pickers = [{ 'class': abupy.FuWeekVolumeBoll, 'threshold_ang_min': 0.0, 'threshold_ang_max': 10.0, 'reversed': False }] choice_symbols = [ '601398', '601988', '601939', '603993', '600999', '300059', '600900', '601328', '601288', '600887', '600029', '000002' ] choice_symbols = [ 'sz000983', 'sh600338', 'sh600511', 'sh600196', 'sh600423', 'sz399136', 'sz002044', 'sh601800', 'sz300132', 'sz300133', 'sh000821', 'sz300003', 'sz300009', 'sz200045', 'sh600998', 'sz300313', 'sh601607', 'sz002644', 'sh600697', 'sz000627', 'sh000003', 'sz399302', 'sh600984', 'sz399301', 'sz000916', 'sz000911', 'sz000912', 'sz000688', 'sh600079', 'sh601101', 'sz000861', 'sz000736', 'sz002053', 'sz000048', 'sh600703', 'sh000814', 'sz300015', 'sh000818', 'sz399352', 'sz399356', 'sh900911', 'sh600395', 'sh000075', 'sz002323', 'sh000101', 'sh600285', 'sh600882', 'sz000789', 'sh601398', 'sz000898', 'sh601390', 'sh601009', 'sh601001', 'sz000525', 'sh600713', 'sh601628', 'sz399299', 'sz399298', 'sh600800', 'sh000808', 'sh900909', 'sh900908', 'sh000061', 'sh000068', 'sh000116', 'sz000617', 'sh600535', 'sz000792', 'sz000889', 'sz000065', 'sh601015', 'sz000089', 'sh600871', 'sz002412', 'sz399400', 'sz399402', 'sz399404', 'sh000057', 'sh900930', 'sh900936', 'sh900934', 'sh900935', 'sh600267', 'sz000650', 'sz399978', 'sh600485', 'sh601021', 'sh601601', 'sh600208', 'sh601288', 'sh600062', 'sh600015', 'sh600016', 'sz300197', 'sz300199', 'sz399413', 'sz399411', 'sz399416', 'sh000134', 'sh000136', 'sh000139', 'sz002007', 'sh600258', 'sh600123', 'sz000511', 'sh601618', 'sh600745', 'sz399170', 'sh000923', 'sz399319', 'sz399554', 'sz399555', 'sz002530', 'sh000145', 'sz002070', 'sh000149', 'sz399220', 'sh601998', 'sh600111', 'sh600023', 'sz000560', 'sh601699', 'sz399305', 'sz399431', 'sz000766', 'sz399436', 'sz399230', 'sz399237', 'sz002661', 'sz002599', 'sh000155', 'sh000152', 'sh000151', 'sh600806', 'sh601988', 'sh600693', 'sh600699', 'sh600582', 'sz000995', 'sh600566', 'sh601318', 'sz399150', 'sz399441', 'sz399200', 'sh000841', 'sh600917', 'sz002128', 'sh600176', 'sz000968', 'sh600771', 'sh600579', 'sh600578', 'sh600572', 'sh600681', 'sh600680', 'sz399140', 'sz000540', 'sz000545', 'sz200022', 'sz200026', 'sz200025', 'sz399210', 'sz200029', 'sz002601', 'sz002656', 'sz002204', 'sz002737', 'sz000748', 'sh600965', 'sz002135', 'sh000934', 'sh601169', 'sh601899', 'sh601898', 'sh600549', 'sh600546', 'sh600545', 'sz000778', 'sh600141', 'sh600145', 'sh601231', 'sz399139', 'sz000630', 'sz000613', 'sz399137', 'sz399130', 'sz399131', 'sz399132', 'sz399133', 'sz200019', 'sz300146', 'sz300144', 'sz399661', 'sz002701', 'sh600971', 'sz002382', 'sz002385', 'sh600085', 'sh603158', 'sz002602', 'sh601939', 'sh600007', 'sz399645', 'sh600000', 'sh601339', 'sh601336', 'sh000125', 'sz399674', 'sh000974', 'sz399160', 'sz002653', 'sz002717', 'sz200726', 'sz399647', 'sz300294', 'sh000100', 'sz300347', 'sh600348', 'sh000933', 'sh600401', 'sh000109', 'sz000034', 'sh600623', 'sz000581', 'sz000672', 'sz300028', 'sh603368', 'sh000023', 'sh000021', 'sz002198', 'sh600432', 'sh603989', 'sz000937', 'sh600508', 'sh600500', 'sh000159', 'sz000732', 'sh600188', 'sz000598', 'sz000029', 'sz000028', 'sz399394', 'sh000832', 'sz300036', 'sz200053', 'sz300326', 'sz002742', 'sz300253', 'sh000013', 'sh000011' ] # choice_symbols = ['002656', '000903'] benchmark = AbuBenchmark(n_folds=15) capital = AbuCapital(1000000, benchmark) kl_pd_manager = AbuKLManager(benchmark, capital) stock_pickers = ABuPickStockExecute.do_pick_stock_work( None, benchmark, # stock_pickers = ABuPickStockExecute.do_pick_stock_work(choice_symbols, benchmark, capital, stock_pickers) print('ABuPickvStockExecute.do_pick_stock_work:\n', stock_pickers) for stock_symbol in stock_pickers: if ~fetch_stock_base_info(stock_symbol): continue draw_candle(stock_symbol, 15)
print(stock_pick.choice_symbols) # 绘图 kl_pd_SFUN = kl_pd_manager.get_pick_stock_kl_pd('usNOAH') deg = ABuRegUtil.calc_regress_deg(kl_pd_SFUN.close) print(deg) # 上面使用worker的操作太麻烦,下面可以直接使用executer stock_pickers = [{ 'class': AbuPickRegressAngMinMax, 'threshold_ang_min': 0.0, 'threshold_ang_max': 10.0, 'reversed': False }] result = ABuPickStockExecute.do_pick_stock_work(choice_symbols, benchmark, capital, stock_pickers) print(result) ''' 2) 同样,上面是采用了一种选股因子,那么,当我采用多种选股因子时会怎样呢? 1. 这里注意,选股和择时是不一样的。 2. 对于择时而言,当我有多因子时,任意时刻,只要满足择时中的一个条件,就可以进行买入或者卖出操作 3. 而对于选股,只有当股票的趋势满足所有因子时,我们才选择该股票 ''' stock_pickers = [{ 'class': AbuPickRegressAngMinMax, 'threshold_ang_min': 0.0, 'reversed': False }, { 'class': AbuPickStockPriceMinMax, 'threshold_price_min': 50.0,
benchmark = AbuBenchmark() capital = AbuCapital(1000000, benchmark) # assign money kl_pd_manager = AbuKLManager(benchmark, capital) ''' # tedious way from abupy import AbuPickStockWorker; stock_pick = AbuPickStockWorker(capital, benchmark, kl_pd_manager, choice_symbols = list(symbols.keys()), stock_pickers = stock_pickers); stock_pick.fit(); print('candidates:', list(symbols.keys())); print('picked:', stock_pick.choice_symbols); ''' # simple way from abupy import ABuPickStockExecute from abupy import ABuRegUtil picked_stocks = ABuPickStockExecute.do_pick_stock_work( list(symbols.keys()), benchmark, capital, stock_pickers) print('candidates:', list(symbols.keys())) for stock in picked_stocks: kl = kl_pd_manager.get_pick_stock_kl_pd(stock) print('stock name: ' + stock + ' degree: {}'.format( round(ABuRegUtil.calc_regress_deg(kl.close), 3))) # 2) pick stocks with multiple processes from abupy import AbuPickStockMaster picked_stocks = AbuPickStockMaster.do_pick_stock_with_process( capital, benchmark, stock_pickers, list(symbols.keys())) print(picked_stocks) # 3) pick stocks with multiple processes and threads picked_stocks = AbuPickStockMaster.do_pick_stock_with_process_mix_thread( capital, benchmark, stock_pickers,