Skip to content

3.03 Robot "Shaver"

Dave Cliff edited this page Oct 17, 2022 · 2 revisions

ZIC makes some money, but it doesn’t use any information in the LOB. Our third type of robot, called Shaver, always tries to have the best bid or offer on the LOB, and does so by shaving a penny off the best price (so long as it can do so without violating the customer’s limit price). Here is the code for Shaver:

# Trader subclass Shaver
# shaves a penny off the best price
# if there is no best price, creates “stub quote” at system max/min
class Trader_Shaver(Trader):
    
    def getorder(self, time, countdown, lob):
            if len(self.orders) < 1:
                    order = None
            else:
                    limitprice = self.orders[0].price
                    otype = self.orders[0].otype
                    if otype == 'Bid':
                            if lob['bids']['n'] > 0:
                                    quoteprice = lob['bids']['best'] + 1
                                    if quoteprice > limitprice :
                                            quoteprice = limitprice
                            else:
                                    quoteprice = lob['bids']['worst']
                    else:
                            if lob['asks']['n'] > 0:
                                    quoteprice = lob['asks']['best'] - 1
                                    if quoteprice < limitprice:
                                            quoteprice = limitprice
                            else:
                                    quoteprice = lob['asks']['worst']
                    self.lastquote = quoteprice
                    order = Order(self.tid, otype, quoteprice, 
                                  self.orders[0].qty, time)
                    
            return order

If we run a market session with a market populated entirely by Shavers, the kind of transaction histories and profit sequence are as illustrated in Figures 3.3.1 and 3.3.2.

FIGURE 3.3.2

Figure 3.3.1: Transaction history for market populated by 62 Shaver traders, over 180s of trading. Initially, there are no trades for the first c.25 seconds while each of the shaver robots repeatedly makes a minimal improvement on the best bid or offer. The best bid rises from $0.01 to c.$1.90 and then holds at that level, set by the highest limit price on a buy order. Meanwhile the best offer is gradually being reduced but takes longer to fall from the system maximum (an arbitrarily high value: here it was $10.00) down to $1.90. At that point, transactions start to occur, initially at $1.90 but then at lower prices as the higher-priced limit orders are executed. Thereafter, the spread between best bid and best offer is always very small, and centered on the equilibrium price of $1.00.

. FIGURE 3.3.2

Figure 3.3.2: Average profit per Shaver trader over 180s of trading