def generateOrder(self, market): time = market.time # calculate the information of order order = Orders.Order('low' + str(self.traderId), 0, 0, 0) # latency 判断是否参与交易,latency作为影响参与频率的因素,用于确定概率 pro = random.random() if pro > self.latencyFactor: # 此次不参与 # print('\n',self.traderId, "doesn't submit the deal this round! ") return if self.suspendTime != 20: # 市场中已经有订单,此次不会产生新的交易 return # order suspend time order.suspendTime = self.suspendTime order.traderType = self.traderType # order direction if self.traderType == 'c': alphac = 0.04 direction = alphac * (market.RecordList[ time - 1][0] - market.RecordList[time - 2][0]) + self.epsilon else: alphaf = 0.05 Ft = market.RecordList[time - 1][1] * (1 + 0.0001) * (1 + self.epsilon) direction = alphaf * ( Ft - market.RecordList[time - 1][0]) + self.epsilon # 0表示买入,1表示卖出 if direction > 0: order.direction = 0 else: order.direction = 1 # order price order.price = round( market.RecordList[time - 1][0] * (1 + 0.0001) * (1 + self.priceEps), 2) # order quantity order.quantity = abs(direction) order.quantity = max(round(order.quantity, 2), 0.01) # 与财富相关的判断,卖出的股票数不能多于现在持有的股票数,买入花费的现金数不能超过现有的现金 if order.direction == 1 and order.quantity > self.stock: # 卖出 order.quantity = self.stock elif order.direction == 0: # 买入 if order.quantity * order.price > self.cash: order.quantity = round(self.cash / order.price, 2) if order.quantity < 0.01: return # order time order.time = round(market.time + random.uniform(0, 1), 2) # print(order.traderId,order.traderType,order.time,order.direction,order.price,order.quantity,order.suspendTime) self.ownOrders.append(order) self.suspendTime -= 1 if self.suspendTime <= 0: self.suspendTime = 20 return order
def generateOrder(self, market): time = market.time # order judge temp = (market.RecordList[time - 1][0] - market.RecordList[time - 2][0] ) / market.RecordList[time - 2][0] #print(temp,self.threshold) if temp <= self.threshold: #print("This round this HFT doesn't join the market!") return # don't join the market order = Orders.Order('high' + str(self.traderId), 0, 0, 0) order.traderType = 'h' # order direction direction = random.random() # print('The direction of this trader is :',direction) if direction > 0.5: order.direction = 0 #0表示买入,搜索的是对向的截个列表 best = market.AskList.sort_values(['price', 'time'], ascending=False)[0:1]['price'] else: order.direction = 1 best = market.BidList.sort_values(['price', 'time'])[0:1]['price'] # order suspend time,高频的这个值为1,因此只要当前没有匹配成功,就会撤单并在下一轮重新参与,高频参与者每轮都会参与 order.suspendTime = self.suspendTime #order.suspendTime = 1 # order price order.price = round(float(best) * (1 + self.priceDis), 2) # !order quantity meanParamater = 0.625 marketQuantity = market.mes(order.direction) order.quantity = marketQuantity * meanParamater * random.random() #order.quantity = marketQuantity * meanParamater order.quantity = max(round(order.quantity, 2), 0.01) # 持仓限制 if order.quantity + self.stock > marketQuantity / 4: order.quantity = marketQuantity / 4 #print(order.traderId,order.traderType,order.direction,order.price,order.quantity,order.suspendTime) # 与财富相关的判断,卖出的股票数不能多于现在持有的股票数,买入花费的现金数不能超过现有的现金 if order.direction == 1 and order.quantity > self.stock: # 卖出 #print('库存股票不足,无法卖出') order.quantity = self.stock elif order.direction == 0: # 买入 if order.quantity * order.price > self.cash: #print('库存现金不足,无法足量买入') order.quantity = self.cash / order.price if order.quantity < 0.001: #print("No order!\n") return #高频的订单的提交时间 order.time = round(market.time + random.uniform(0, 1), 2) return order
def __init__(self, user): self.wn = tk.ThemedTk() self.wn.configure(bg="#6262ED") self.wn.title("Rent a car") self.wn.geometry("650x450+200+50") self.item_index = "" self.my_index = 1 self.user = user self.wn.get_themes() self.wn.set_theme('plastik') self.item = Admn.Admin() self.order = Orders.Order() #==========================Frame1==============================# self.frame1 = Frame(self.wn) self.frame1.place(x=10, y=10) self.frame1.configure(bg="#6262ED") self.lbl_add = Label(self.frame1, font=("Calibri", 14, "bold"), text="Address:", bg="#6262ED") self.lbl_add.grid(row=0, column=0) self.combo_tbl1 = ttk.Combobox(self.frame1, state='readonly', width=20) self.combo_tbl1.grid(row=0, column=1, padx=5) self.combo_tbl1['values'] = self.order.all_address() self.btn1 = Button(self.frame1, text='Search', font=('Calibri', 11, "bold"), fg="white", background='#6262ED', width=12, bd=1, command=self.search) self.btn1.grid(row=0, column=2, padx=10) #==========================Frame2==============================# self.frame2 = Frame(self.wn, bg="#6262ED") self.frame2.place(x=10, y=50) self.cars_tree = ttk.Treeview(self.frame2, columns=('Brand', 'Model', 'Price', 'Address')) self.cars_tree.grid(row=0, column=0) self.cars_tree['show'] = 'headings' self.cars_tree.column('Brand', width=150, anchor='center') self.cars_tree.column('Model', width=150, anchor='center') self.cars_tree.column('Price', width=150, anchor='center') self.cars_tree.column('Address', width=155, anchor='center') self.cars_tree.heading('Brand', text="Brand") self.cars_tree.heading('Model', text="Model") self.cars_tree.heading('Price', text="Price") self.cars_tree.heading('Address', text="Address") self.cars_tree.bind("<Double-1>", self.select_item) self.vsb = ttk.Scrollbar(self.frame2, orient="vertical", command=self.cars_tree.yview) self.vsb.place(x=591, y=2, height=225) self.cars_tree.configure(yscrollcommand=self.vsb.set) #==========================Frame3==============================# self.frame3 = Frame(self.wn, bg="#6262ED") self.frame3.place(x=10, y=300) self.lbl_brand = Label(self.frame3, font=("Calibri", 14, "bold"), text="Brand:", bg="#6262ED") self.lbl_brand.grid(row=0, column=0) self.lbl_model = Label(self.frame3, font=("Calibri", 14, "bold"), text="Model:", bg="#6262ED") self.lbl_model.grid(row=1, column=0) self.ent_cbrand = ttk.Entry(self.frame3, font=("Verdana", 12), state="readonly") self.ent_cbrand.grid(row=0, column=1, padx=10) self.ent_cmodel = ttk.Entry(self.frame3, font=("Verdana", 12), state="readonly") self.ent_cmodel.grid(row=1, column=1, padx=10) self.lbl_price = Label(self.frame3, font=("Calibri", 14, "bold"), text="Price:", bg="#6262ED") self.lbl_price.grid(row=2, column=0) self.ent_cprice = ttk.Entry(self.frame3, font=("Verdana", 12), state="readonly") self.ent_cprice.grid(row=2, column=1, padx=10) self.lbl_date = Label(self.frame3, font=("Calibri", 14, "bold"), text="Pick up Date:", bg="#6262ED") self.lbl_date.grid(row=0, column=3) self.cal = DateEntry(self.frame3, width=12, background='darkblue', foreground='white', borderwidth=2, state="readonly") self.cal.grid(row=0, column=4) self.lbl_days = Label(self.frame3, font=("Calibri", 14, "bold"), text="Days:", bg="#6262ED") self.lbl_days.grid(row=1, column=3) self.combo_tbl2 = ttk.Combobox(self.frame3, state='readonly', width=11) self.combo_tbl2.grid(row=1, column=4, padx=5) self.combo_tbl2['values'] = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15' ] self.btn1 = Button(self.wn, text="Order", font=('Calibri', 11, "bold"), fg="white", background='#6262ED', borderwidth=0.5, width=15, command=self.submitOrder) self.btn1.place(x=260, y=400) self.show_menu() self.wn.mainloop()