def serial(self): """把上一次交易的价格放到已交易价格的最后, 形成一个ndarray""" n = self.prices_traded.prices n = agl.array_insert(n, len(n), self.pre_price) n = agl.array_insert(n, len(n), self.first_buy_price) #agl.SerialMgr.serial(n, self.fpath) np.savetxt(self.fpath, n, delimiter=',', fmt='%.3f')
def Add(self, price): if not self.find(price): self.prices = agl.array_insert(self.prices, len(self.prices), price) return True return False
def ExePolicy(self, code): code = agl.unicode_to_utf8(code) live_data = LiveData() df_hisdat = live_data.getHisdat(code) df_fenshi = live_data.getFenshi(code) df_five_hisdat = live_data.getFiveMinHisdat(code) if agl.IsNone(df_five_hisdat): #print code ,'没有5分钟' return if len(df_fenshi) == 0: return if len(df_five_hisdat) < 30: return price = float(agl.FloatToStr(float(df_fenshi.tail(1)['p']))) yclose = df_hisdat.ix[df_hisdat.index[-1]]['c'] zhangfu = stock.ZhangFu(price, yclose) rsi = stock.RSI(df_five_hisdat['c']) #ui.DrawClosesAndVolumes(pl, df_five_hisdat['c'], rsi) upper, middle, lower = stock.TDX_BOLL(df_five_hisdat['c']) #ui.DrawTs(pl, df_five_hisdat['c'],mid=middle, high=upper, low=lower) highs, lows, closes = df_five_hisdat['h'], df_five_hisdat[ 'l'], df_five_hisdat['c'] #atr = stock.ATR(highs, lows, closes) adx = stock.TDX_ADX(highs, lows, closes) closes = np.array(df_hisdat['c']) if help.MyDate(agl.datetime_to_date(df_hisdat.index[-1])).d < \ help.MyDate(agl.CurDay()).d: closes = agl.array_insert(closes, len(closes), price) four = stock.FOUR(closes) #print code, four[-1] self._dict_four[code] = four[-1] #return #ui.DrawClosesAndVolumes(pl, df_five_hisdat['c'], adx) boll_up = (price - upper[-1]) / upper[-1] boll_mid = (price - middle[-1]) / middle[-1] boll_down = (lower[-1] - price) / lower[-1] boll_width = upper[-1] - lower[-1] if abs(zhangfu) > 0.098 or boll_width < 0.01: return if code == '300033': codename = stock.GetCodeName(code) s = 'rsi = %d %s %s' % (rsi[-1], codename, str(price)) print s if (rsi[-1] > 65 or rsi[-1] < 35) and adx[-1] > 60: codename = stock.GetCodeName(code) s = '%s %s' % (codename, str(price)) sign = False #if code in ['300033','510050']: #sign = True #if adx[-1] > 55: #s += ' ADX=%d'%(adx[-1]) #sign = True if boll_up > -0.003: s += ' 越过布林上轨' #sign = True if abs(boll_mid) < 0.003: s += ' 布林中轨' #sign = True if boll_down > -0.003: s += ' 越过布林下轨' sign = True if four[-1] > 0.1: sign = False #sign = False if sign: #ui.DrawTs(pl, df_five_hisdat['c'],mid=middle, high=upper, low=lower) sInfo = self.calcInfo(code, price, zhangfu) help.myprint(s, sInfo) help.myprint( '[%s,%s] %.3f,%.3f,%.3f,%.2f, four=%.2f, adx=%.2f' % (code, stock.GetCodeName(code), boll_up, boll_mid, boll_down, boll_width, four[-1], adx[-1])) self.NotifyAutoxdShow(code) self.Speak(s)