def fun(stocks): # print(os.getpid(), stocks) kline = 'hk_kline_day' table_name='MA_'+kline pixel=64 interval = KlineInfo.get_interval(kline) for sc in stocks: end_time = dt.datetime(2018, 6, 25) start_time = dt.datetime(2016, 1, 1) data = KlineData.read_data(code=sc, start_date=Calendar.calc(start_time, -203)['date'], end_date=end_time, kline=kline, timemerge=True) if len(data) <= 200: continue data = CalMa.cal_ma(data, interval) data = data.dropna() print(sc) while end_time > dt.datetime(2016, 1, 1): data0 = data.tail(pixel) data0 = data0.reset_index(drop=True) profit = data0['profit'] date = data0['date'] price=data0.close.iloc[0] data0 = CalMa.data_normalization(data0,pixel=pixel) data0['date'] = date data0['profit'] = profit if len(data0) < pixel or price<2: break date = data0.date.iloc[len(data0) - 1] profit = data0.profit.iloc[len(data0) - 1] if 'min' in kline: if abs(profit) > 0.11: data = data[data.date < dt.datetime(date.year, date.month, date.day)] continue else: if abs(profit) > 0.1*interval: data = data[data.date < dt.datetime(date.year, date.month, date.day)] continue data0 = data0.reset_index(drop=True) try: visualization.draw_ma_line(data=data0, profits=profit, date=date, code=sc, table_name=table_name,pixel=pixel) except Exception as e: print(e) pass data = data[data.date<dt.datetime(date.year,date.month,date.day)] end_time = date return 1
def fun(data): stocks=data['stocks'] kline=data['kline'] # print(os.getpid(), stocks) table_name='MA_A_'+kline interval = KlineInfo.get_interval(kline) detal=KlineInfo.get_detal(kline) off=KlineInfo.get_off(kline=kline) day_interval=KlineInfo.get_day_interval(kline) pixel=64 for sc in stocks: end_time = Calendar.today() start_time = Calendar.calc(end_time,-day_interval)['date'] # end_time = dt.datetime(2018,8,1) # start_time=dt.datetime(2018,6,20) data = KlineData.read_data(code=sc, start_date=Calendar.calc(start_time, -off)['date'], end_date=end_time, kline=kline, timemerge=True) if len(data) <= 200: continue data = CalMa.cal_ma(data, interval,detal) data = data.dropna() print(sc) while end_time > start_time: data0 = data.tail(pixel) data0 = data0.reset_index(drop=True) profit = data0['profit'] profitself = data0['profit_self'] date = data0['date'] data0 = CalMa.data_normalization(data0,pixel) data0['date'] = date data0['profit'] = profit data0['profitself'] = profitself if len(data0) < pixel: break data0 = data0.reset_index(drop=True) profit = data0.profit.iloc[len(data0)-1] profitself = data0.profitself.iloc[len(data0)-1] date = data0.date.iloc[len(data0)-1] if 'min' in kline: if 'A' in table_name: if date.hour != 15: data = data[data.date < dt.datetime(date.year, date.month, date.day)] break if abs(profit) > 0.11 or abs(profitself) > 0.097: data = data[data.date < dt.datetime(date.year, date.month, date.day)] continue else: if abs(profit) > 0.1 * interval: data = data[data.date < dt.datetime(date.year, date.month, date.day)] continue if 'A' in table_name: if abs(profitself) > 0.097: data = data[data.date < dt.datetime(date.year, date.month, date.day)] continue try: visualization.draw_ma_line(data=data0, profits=profit, date=date, code=sc, table_name=table_name,pixel=pixel) except Exception as e: print(e) pass data = data[data.date < dt.datetime(date.year, date.month, date.day)] end_time = date return 1
def fun(stocks): # print(os.getpid(), stocks) kline = 'index_min5' pixel=64 length=5 count=12 interval =48 hour=9 minute=50 detal=KlineInfo.get_detal(kline=kline) # wave=0.02 # amount_data=50000000 table_name='A_MA_Stub_'+kline+'_version6' print(table_name) for sc in stocks: print(sc) end_time = dt.datetime(2018, 9, 10) start_time = dt.datetime(2016, 1, 1) data = KlineData.read_data(code=sc, start_date=Calendar.calc(start_time, -8)['date'], end_date=end_time, kline=kline, timemerge=True) if len(data) <= 200: continue # data = CalMacd.cal_macd(data=data, interval=interval, detal=detal) data=CalMa.cal_ma_stub(data=data,interval=interval,detal=detal) data = data.dropna() d = data.date.iloc[-1] data = data[data.date <= dt.datetime(d.year, d.month, d.day, hour, minute)] while end_time > start_time: # print(sc,dt.datetime.now()) data0 = data.tail(length) data0 = data0.reset_index(drop=True) profit = data0['profit'] profit_self = data0['profit_self'] date = data0['date'] # amin, amax = data0.low.min(), data0.high.max() if len(data0) < length: break date1 = date.iloc[length - 1] date2 = date.iloc[length - 10] # data0 = CalMacd.data_normalization(data0,pixel=pixel) data0=CalMa.data_normalization(data0,pixel=pixel) profit = profit.iloc[length - 1] profitself = profit_self.iloc[length - 1] profit_relative = 0 if 'min' in kline: if 'A' in table_name: if date1.hour != hour and date1.minute!=minute: # data = data[data.date < dt.datetime(date2.year, date2.month, date2.day)] break if abs(profit) > 0.11 or abs(profitself)>0.097: data = data[data.date <= dt.datetime(date2.year, date2.month, date2.day, hour, minute)] continue else: if abs(profit) > 0.1 * interval: data = data[data.date <= dt.datetime(date2.year, date2.month, date2.day, hour, minute)] continue if 'A' in table_name: if abs(profitself) > 0.097: data = data[data.date <= dt.datetime(date2.year, date2.month, date2.day, hour, minute)] print(sc, str(profitself) + '_' + str(date1)) continue try: visualization.draw_ma_stub_line(data=data0, profits=profit, date=date1, code=sc, table_name=table_name, pixel=pixel, length=length, profit_relative=profit_relative, count=count) pass except Exception as e: print(e) pass data = data[data.date <= dt.datetime(date2.year, date2.month, date2.day,hour,minute)] end_time = date2 # break return 1