def fun(stocks): # print(os.getpid(), stocks) kline = 'usa_kline_day' pixel = 64 length = pixel * 2 interval = KlineInfo.get_interval(kline=kline) off = KlineInfo.get_off(kline=kline) table_name = 'MACD_and_MA_' + kline print(table_name) for sc in stocks: print(os.getpid(), sc) end_time = dt.datetime(2018, 6, 20) start_time = dt.datetime(2015, 1, 1) 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) <= (off - 20): continue data = calculate.calculate_data(data, interval) # data = data.sort_values(by=['date'], ascending=True) data = data.dropna() # data = data[0:len(data) - interval] while end_time > dt.datetime(2016, 1, 5): # print(sc,dt.datetime.now()) data0 = data.tail(length) data0 = data0.reset_index(drop=True) profit = data0['profit'] date = data0['date'] data0 = calculate.data_normalization(data=data0, pixel=pixel, length=length) # print(sc, dt.datetime.now()) data0['date'] = date data0['profit'] = profit if len(data0) < length: break data0 = data0.reset_index(drop=True) profit = data0.profit.iloc[length - 1] date = data0.date.iloc[length - 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: 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 # print(sc, dt.datetime.now()) try: visualization.draw_macd_and_ma(data=data0, profits=profit, date=date, code=sc, table_name=table_name, pixel=pixel, length=length) pass 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