Exemplo n.º 1
0
    def Travl(self, start_day='', end_day=''):
        """根据日期来遍历全部股票"""
        if 0: start_day = end_day = datetime
        if start_day == '':
            start_day = help.StrToDate("2011-10-11")
        if end_day == '':
            #今天
            end_day = datetime.date.today()
            
        gupiaos = ISimulator.getGupiaos(self.flag)
	
	account = stock.Account()
            
	#为了减少数据库操作, 还是先取出数据再判断日期
	guiders = []
        start_day = help.MyDate(start_day)
	for gupiao in gupiaos:
	    if not self.p.filter(gupiao):
		guider = stock.Guider(gupiao, start_day.ToStr())
		help.myprint("时间策略遍历", guider.code)
		guiders.append(guider)

	#start_day.Add(60)
        while start_day.Next() < end_day:
            day = start_day.ToStr()
            help.myprint(day)

	    for guider in guiders:
		#看当前日期是否存在
		if guider.DateToIndex(start_day.d) == -1:
		    continue
		
		new_guider = copy.deepcopy(guider)
		if 0: new_guider = stock.Guider
		new_guider.resize(start_day.d)
		
		fenshi = stock.Fenshi(guider.code, day)
		fenshi.mean()
		for order in fenshi.orders:
		    if 0: order = stock.Order
		    new_fenshi = copy.deepcopy(fenshi)
		    new_fenshi.resize(order.date)
		    #help.myprint(order.date, order.price)
		    self.p.OnTick(new_guider, new_fenshi, account)

	    
        account.myprint()
	return account
Exemplo n.º 2
0
    def Process(self, code, start_day='', end_day=''):
        """"""
        help.myprint(self.p.__class__, code)
        guider = stock.Guider(code, start_day, end_day)
        account = stock.Account()

        for i in range(0, guider.getSize()):
            if 0: hisdat = stock.Hisdat
            hisdat = guider.getData(i)
            #new_guider = stock.Guider(code, end_day=str(hisdat.date))
            new_guider = copy.deepcopy(guider)
            if 0: new_guider = stock.Guider
            new_guider.hisdats = new_guider.hisdats[:i]
            #help.myprint("当前天为 ", str(hisdat.date))
            self.p.OnTick(new_guider, None, account)

        account.myprint()
        return account
Exemplo n.º 3
0
    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)