sw = SWImpl() lists = sw.getSW2List() chart = Chart() start = datetime(2014, 5, 1) end = datetime(2020, 8, 17) dict = {} dict[0] = [] dict[1] = [] dict[2] = [] dict[3] = [] dict[4] = [] indictor = macd() for code in lists: if len(sw.getSW2Stocks(code)) < 10: continue bars = sw.getSW2Daily(code, start, end) # print(f"bar.size = {bars.__len__()}") chart.run(bars, indictor) holdbars = indictor.getHoldBars() # maker = HoldBarMaker() # for holdbar in holdbars: # if(HoldBarUtils.isEarnBarList(holdbar.bars)): # barList = holdbar.bars # maker.onHoldStart(barList[0]) # for i in range(1,len(barList)): # maker.onHoldUpdate(barList[i]) # maker.onHoldEnd()
from datetime import datetime from earnmi.data.MarketImpl import MarketImpl from earnmi.data.SWImpl import SWImpl import time sw = SWImpl() swCode = sw.getSW2List()[0] stockslist = sw.getSW2Stocks(swCode) print(f"stockslist:{len(stockslist)}") startDate = datetime(2015, 4, 1) endDate = datetime(2020, 5, 1) market = MarketImpl() market.setToday(endDate) market.addNotice('002852') bars = market.getHistory().getKbars('002852', 300 * 3) for code in stockslist: market.addNotice(code) print(f"getBars:{code}") bars = market.getHistory().getKbars(code, 300 * 3) #time.sleep(2) print(f"getBars size:{len(bars)}")
def computeHoldBarIndictor(indictor:IndicatorItem)->HoldBarData: sw = SWImpl() lists = sw.getSW2List() chart = Chart() total_cost_pcts = []#收益 avg_eran_cost_pcts = []#每个盈利holdbard的平均盈利 total_days = [] total_eran_days = [] total_holdbars = [] total_holdbars_earn = [] max_cost_pcts =[] #最大收益 min_cost_pcts = [] for code in lists: if len(sw.getSW2Stocks(code)) < 10: continue bars = sw.getSW2Daily(code, start, end) #print(f"bar.size = {bars.__len__()}") chart.run(bars, indictor) holdbarList = indictor.getHoldBars() #holdbarList = HoldBarUtils.filterHoldBar(holdbarList) data = HoldBarUtils.computeHoldBarIndictor(holdbarList); if data is None: continue total_cost_pcts.append(data.total_cost_pct) max_cost_pcts.append(data.max_cost_pct) min_cost_pcts.append(data.min_cost_pct) total_days.append(data.total_day) total_holdbars.append(data.total_holdbar) total_holdbars_earn.append(data.total_holdbar_earn) avg_eran_cost_pcts.append(data.avg_eran_cost_pct) total_eran_days.append(data.total_earn_day) ret = HoldBarData() total_cost_pcts = np.array(total_cost_pcts) total_days = np.array(total_days) max_cost_pcts = np.array(max_cost_pcts) min_cost_pcts = np.array(min_cost_pcts) total_holdbars = np.array(total_holdbars) total_holdbars_earn = np.array(total_holdbars_earn) avg_eran_cost_pcts = np.array(avg_eran_cost_pcts) total_eran_days = np.array(total_eran_days) ret.total_min_cost_pct = total_cost_pcts.min() ret.total_max_cost_pct = total_cost_pcts.max() ret.total_cost_pct = total_cost_pcts.mean() ret.total_cost_pct_std = np.std(total_cost_pcts) ret.total_day = total_days.mean() ret.max_cost_pct = max_cost_pcts.mean() ret.min_cost_pct = min_cost_pcts.mean() ret.total_holdbar = total_holdbars.mean() ret.total_holdbar_earn = total_holdbars_earn.mean() ret.avg_eran_cost_pct = avg_eran_cost_pcts.mean() ret.total_earn_day = total_eran_days.mean() return ret