support.Ticker
Class RefMarketMaker

java.lang.Object
  |
  +--support.Ticker.RefMarketMaker
Direct Known Subclasses:
MarketMaker

public class RefMarketMaker
extends java.lang.Object

This class implements the actions of a market maker who handles all the trades for a certain stock.

Buy orders and sell orders sent to the market maker specify the number of share (size) and the price. The market maker assigns a unique ID to each order, which can be later used to cancel the order.

The market maker maintains a priority queue of open buy orders and a priority queue of open sell orders, such that the best bid (highest price of a buy-order) is strictly less than the best ask (lowest price of a sell-order).

Whenever a new order arrives, the market maker tries to match it with open orders of the opposite type. A maximal series of trades are then executed crossing matching orders. Spreads between the prices of matching orders give a profit to the market maker.

The market disseminates the transactions performed by means of the following events:

Each event has an ID, size, and price. Spread events have ID=0.


Field Summary
protected  PriorityQueue BuyOrders
          priority queue storing open buy orders
protected  IDManager IDTable
          table that asociates order locators with order IDs
protected  PriorityQueue SellOrders
          priority queue storing open sell orders
 
Constructor Summary
RefMarketMaker()
          instantiate priority queues for the open buy and sell orders and the ID manager
 
Method Summary
 java.util.Enumeration buyOrder(int size, int price)
          process a buy order
 java.util.Enumeration cancel(int id)
          cancel an order given its ID
protected  void crossOrders(Sequence events)
          execute a maximal series of trades by matching open buy and sell orders, and profit from spreads
protected  int id(Locator loc)
          adaptor
 java.util.Enumeration openOrders()
          list open orders
protected  int price(Locator loc)
          adaptor
 java.util.Enumeration sellOrder(int size, int price)
          process a sell order
protected  void setID(Locator loc, int id)
          adaptor
protected  void setSize(Locator loc, int size)
          adaptor
protected  int size(Locator loc)
          adaptor
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

BuyOrders

protected PriorityQueue BuyOrders
priority queue storing open buy orders

SellOrders

protected PriorityQueue SellOrders
priority queue storing open sell orders

IDTable

protected IDManager IDTable
table that asociates order locators with order IDs
Constructor Detail

RefMarketMaker

public RefMarketMaker()
instantiate priority queues for the open buy and sell orders and the ID manager
Method Detail

buyOrder

public java.util.Enumeration buyOrder(int size,
                                      int price)
process a buy order
Returns:
events triggered by the order

sellOrder

public java.util.Enumeration sellOrder(int size,
                                       int price)
process a sell order
Returns:
events triggered by the order

cancel

public java.util.Enumeration cancel(int id)
cancel an order given its ID
Returns:
an enumeration that contains a cancellation event if the ID is valid, and is empty otherwise

openOrders

public java.util.Enumeration openOrders()
list open orders
Returns:
events associated with open orders

crossOrders

protected void crossOrders(Sequence events)
execute a maximal series of trades by matching open buy and sell orders, and profit from spreads

price

protected int price(Locator loc)
adaptor

size

protected int size(Locator loc)
adaptor

setSize

protected void setSize(Locator loc,
                       int size)
adaptor

id

protected int id(Locator loc)
adaptor

setID

protected void setID(Locator loc,
                     int id)
adaptor