#没有记满,就继续记 if not g.security_win_queue[security].full(): #亏损的比例在持股初期不录入保证未突破止损线之前不卖出 if win_percentage > 0: g.security_win_queue[security].put(win_percentage) print(security,win_percentage,'qsize:',g.security_win_queue[security].qsize()) #满了则进行盈利比较 else: #取N日最小值盈利 tmp_win_list = [] <!-- more --> queue_size = g.security_win_queue[security].qsize() for w inrange(queue_size): tmp_win_list.append(g.security_win_queue[security].get())
#排序盈利并取最小 sorted_tmp_win_list = sorted(tmp_win_list) #排除最小值后把队列恢复。 minimum = sorted_tmp_win_list[0] #排除最小值[0] for w inrange(1,queue_size): g.security_win_queue[security].put(sorted_tmp_win_list[w]) if win_percentage < minimum: #返回true则需要卖出否则返回false继续持有 returnTrue else: #将新的盈利推入队列 g.security_win_queue[security].put(win_percentage) returnFalse