|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.jasa.market.FourHeapOrderBook
public class FourHeapOrderBook
This class provides market order-matching services using the 4-Heap algorithm. See:
"Flexible Double Auctions for Electronic Commerce: Theory and Implementation" by Wurman, Walsh and Wellman 1998.
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Field Summary | |
---|---|
protected java.util.PriorityQueue<Order> |
bIn
Matched bids in ascending order |
protected java.util.PriorityQueue<Order> |
bOut
Unmatched bids in descending order |
protected static AscendingOrderComparator |
greaterThan
|
protected static DescendingOrderComparator |
lessThan
|
protected java.util.PriorityQueue<Order> |
sIn
Matched asks in descending order |
protected java.util.PriorityQueue<Order> |
sOut
Unmatched asks in ascending order |
Constructor Summary | |
---|---|
FourHeapOrderBook()
|
Method Summary | |
---|---|
void |
add(Order shout)
|
protected void |
addAsk(Order ask)
|
protected void |
addBid(Order bid)
|
java.util.Iterator<Order> |
askIterator()
Return an iterator that non-destructively iterates over every ask in the market (both matched and unmatched). |
java.util.Iterator<Order> |
bidIterator()
Return an iterator that non-destructively iterates over every bid in the market (both matched and unmatched). |
protected void |
checkBalanced(Order s1,
Order s2,
java.lang.String condition)
|
void |
checkIntegrity()
|
int |
displaceHighestMatchedAsk(Order ask)
|
int |
displaceLowestMatchedBid(Order bid)
|
protected int |
displaceShout(Order shout,
java.util.PriorityQueue<Order> from,
java.util.PriorityQueue<Order> to)
|
int |
getDepth()
|
Order |
getHighestMatchedAsk()
Get the highest matched ask. |
Order |
getHighestUnmatchedBid()
Get the highest unmatched bid. |
Order |
getLowestMatchedBid()
Get the lowest matched bid |
Order |
getLowestUnmatchedAsk()
Get the lowest unmatched ask. |
java.util.List<Order> |
getUnmatchedAsks()
|
java.util.List<Order> |
getUnmatchedBids()
|
protected void |
initialise()
|
void |
insertUnmatchedAsk(Order ask)
Insert an unmatched ask into the appropriate heap. |
void |
insertUnmatchedBid(Order bid)
Insert an unmatched bid into the appropriate heap. |
boolean |
isEmpty()
|
java.util.List<Order> |
matchOrders()
Return a list of matched bids and asks. |
void |
prettyPrint(java.lang.String title,
java.util.PriorityQueue shouts)
|
void |
printState()
Log the current state of the market. |
int |
promoteHighestUnmatchedBid(Order ask)
|
int |
promoteLowestUnmatchedAsk(Order bid)
|
int |
promoteShout(Order shout,
java.util.PriorityQueue<Order> from,
java.util.PriorityQueue<Order> to,
java.util.PriorityQueue<Order> matched)
|
protected void |
reinsert(java.util.PriorityQueue<Order> heap,
int quantity)
Remove, possibly several, shouts from heap such that quantity(heap) is reduced by the supplied quantity and reinsert the shouts using the standard insertion logic. |
void |
remove(Order shout)
|
protected void |
removeAsk(Order shout)
|
protected void |
removeBid(Order shout)
|
void |
reset()
|
int |
size()
Compute the total number of orders in the book. |
java.lang.String |
toString()
|
protected static Order |
unifyShout(Order shout,
java.util.PriorityQueue<Order> heap)
Unify the shout at the top of the heap with the supplied shout, so that quantity(shout) = quantity(top(heap)). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.PriorityQueue<Order> bIn
protected java.util.PriorityQueue<Order> bOut
protected java.util.PriorityQueue<Order> sIn
protected java.util.PriorityQueue<Order> sOut
protected static AscendingOrderComparator greaterThan
protected static DescendingOrderComparator lessThan
Constructor Detail |
---|
public FourHeapOrderBook()
Method Detail |
---|
public void remove(Order shout)
remove
in interface OrderBook
protected void removeAsk(Order shout)
protected void removeBid(Order shout)
public java.lang.String toString()
toString
in class java.lang.Object
public void printState()
printState
in interface OrderBook
public void prettyPrint(java.lang.String title, java.util.PriorityQueue shouts)
public void insertUnmatchedAsk(Order ask) throws DuplicateShoutException
DuplicateShoutException
public void insertUnmatchedBid(Order bid) throws DuplicateShoutException
DuplicateShoutException
public Order getHighestUnmatchedBid()
getHighestUnmatchedBid
in interface OrderBook
public Order getLowestMatchedBid()
getLowestMatchedBid
in interface OrderBook
public Order getLowestUnmatchedAsk()
getLowestUnmatchedAsk
in interface OrderBook
public Order getHighestMatchedAsk()
getHighestMatchedAsk
in interface OrderBook
protected static Order unifyShout(Order shout, java.util.PriorityQueue<Order> heap)
shout
- The shout.heap
- The heap.
protected int displaceShout(Order shout, java.util.PriorityQueue<Order> from, java.util.PriorityQueue<Order> to) throws DuplicateShoutException
DuplicateShoutException
public int promoteShout(Order shout, java.util.PriorityQueue<Order> from, java.util.PriorityQueue<Order> to, java.util.PriorityQueue<Order> matched) throws DuplicateShoutException
DuplicateShoutException
public int displaceHighestMatchedAsk(Order ask) throws DuplicateShoutException
DuplicateShoutException
public int displaceLowestMatchedBid(Order bid) throws DuplicateShoutException
DuplicateShoutException
public int promoteHighestUnmatchedBid(Order ask) throws DuplicateShoutException
DuplicateShoutException
public int promoteLowestUnmatchedAsk(Order bid) throws DuplicateShoutException
DuplicateShoutException
public void add(Order shout) throws DuplicateShoutException
add
in interface OrderBook
DuplicateShoutException
protected void addBid(Order bid) throws DuplicateShoutException
DuplicateShoutException
protected void addAsk(Order ask) throws DuplicateShoutException
DuplicateShoutException
public java.util.Iterator<Order> askIterator()
OrderBook
askIterator
in interface OrderBook
public java.util.Iterator<Order> bidIterator()
OrderBook
bidIterator
in interface OrderBook
public java.util.List<Order> matchOrders()
Return a list of matched bids and asks. The list is of the form
where bi is the ith bid and a0 is the ith ask. A typical auctioneer would clear by matching bi with ai for all i at some price.
matchOrders
in interface OrderBook
protected void initialise()
public void reset()
protected void reinsert(java.util.PriorityQueue<Order> heap, int quantity)
heap
- The heap to remove shouts from.quantity
- The total quantity to remove.public int size()
public boolean isEmpty()
isEmpty
in interface OrderBook
public int getDepth()
getDepth
in interface OrderBook
public java.util.List<Order> getUnmatchedBids()
getUnmatchedBids
in interface OrderBook
public java.util.List<Order> getUnmatchedAsks()
getUnmatchedAsks
in interface OrderBook
public void checkIntegrity()
protected void checkBalanced(Order s1, Order s2, java.lang.String condition)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |