예제 #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
예제 #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
예제 #3
0
파일: qjjy.py 프로젝트: longzhaoai/autoxd
    def buy(self,price):
	s = u"%s, 当前价%.2f, 上一个交易价%.2f, 第一次买入价%.2f"%(self.code,price, self.pre_price, self.first_buy_price)
	self.account.log(s)
	#第一次买
	if self.pre_price == 0 and price <= self.first_buy_price:
	    if self._Buy(self.code, self.first_buy_num, price):
		self.first_buy_price = price
		self.pre_price = price
		self._genQjPrice()
		self.serial()
	    return
	if price-self.pre_price <= -self.qj:
	    is_buy = True
	    #fire_qj_price = Qjjy_accout._findMatchPrice(price, self.qj_prices, is_buy)
	    fire_qj_price = price
	    if fire_qj_price > 0 and self.prices_traded.Add(fire_qj_price):
		num = stock.Account().ShouShu(self.first_buy_num*self.qj_num_bilv)
		if self._Buy(self.code, num, price):
		    print "_buy"
		    self.pre_price = price
		    self.serial()
예제 #4
0
파일: qjjy.py 프로젝트: longzhaoai/autoxd
    def sell(self,price):
	#全部卖出
	if price > self.end_sell_price :
	    if self._Sell(self.code, -1, price):
		self.pre_price = 0
		if os.path.isfile(self.fpath):
		    os.remove(self.fpath)
	    return
	#self.log("sell 0 "+str(self.qj) + " "+str(price-self.pre_price))
	if price-self.pre_price >= self.qj :
	    is_buy = False
	    #一定要匹配到锚点价格
	    #fire_qj_price = Qjjy_accout._findMatchPrice(price, self.qj_prices, is_buy)
	    fire_qj_price = price
	    if fire_qj_price > 0 :
		self.log("sell 2")
		num = stock.Account().ShouShu(self.first_buy_num*self.qj_num_bilv)
		if self._Sell(self.code, num, price):
		    self.log( "_sell")
		    self.prices_traded.Del(price)
		    self.pre_price = price
		    self.serial()