|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--support.Ticker.RefMarketMaker
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 |
|
| Field Detail |
protected PriorityQueue BuyOrders
protected PriorityQueue SellOrders
protected IDManager IDTable
| Constructor Detail |
public RefMarketMaker()
| Method Detail |
public java.util.Enumeration buyOrder(int size,
int price)
public java.util.Enumeration sellOrder(int size,
int price)
public java.util.Enumeration cancel(int id)
public java.util.Enumeration openOrders()
protected void crossOrders(Sequence events)
protected int price(Locator loc)
protected int size(Locator loc)
protected void setSize(Locator loc,
int size)
protected int id(Locator loc)
protected void setID(Locator loc,
int id)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||