from
Order book simulation
by Dimitri Shvorob
(a naive artificial stock market)
|
| OrderHeap |
classdef OrderHeap < PriorityQueue
properties
Side
Type
TradePrice
end
methods
function[obj] = OrderHeap(side,type)
if strcmp(type,'MKT')
orderPriority = @(x,y) x.Order.Time < y.Order.Time;
else
if strcmp(type,'LIM')
if strcmp(side,'BUY')
orderPriority = @(x,y) x.Order.Price > y.Order.Price;
else
orderPriority = @(x,y) x.Order.Price < y.Order.Price;
end
end
end
obj = obj@PriorityQueue(orderPriority);
if strcmp(type,'LIM')
obj.TradePrice = @(x,y) x.Order.Price;
else
obj.TradePrice = @(x,y) y.Order.Price;
end
obj.Side = side;
obj.Type = type;
end
function disp(obj)
fprintf('OrderHeap: %s, %s\n',obj.Side,obj.Type)
if isempty(obj)
disp('<empty>')
else
for i = 1:length(obj.Values)
shortdisp(obj.Values(i))
end
end
end
end
end
|
|
Contact us at files@mathworks.com