Session2:
Continuous Market Implementation in ASX
9 April 2013
The
aim of this session is to learn about the representation of trades and to
demonstrate a trading engine that is conformant with a typical market microstructure.
We use some market rules that are typically found in most financial markets.
This session is demonstrated by a simple trading engine tool that simulates ASX
continuous trading market during the normal trading hours.
Familiarity
with ASX microstructure; in particular:
A
trade corresponds to the exchange of certain volume of securities between a seller
(i.e. the “best ask” order) and a buyer (i.e. the “best bid” order) at the
agreed price. In typical trading, a trade can be executed if a match is
triggered between a seller and a buyer (e.g. when the spread is equal to zero).
The trading process is automated by trading engine software which can
determine and trigger the execution of matched orders trade and calculate the
trading price. Different markets may implement different rules that govern the
order matching criteria and the determination of the trading prices. A trading
engine must implement a matching algorithm that obeys the market
regulations.
In
general terms, the usage of matching algorithms in a trading engine can be summarised as follows:
Here is a diagram illustrating the trading engine architecture
Like orders, a
trade is represented as a line in a text file with comma separated attributes.
The first line gives the positions of such attributes. We adopt the SIRCA
format uses the following attributes:
Instrument |
Date |
Time |
Record Type |
Price |
Volume |
Value |
Trans ID |
Bid ID |
Ask ID |
Bid/Ask |
Security |
Date of the order |
Time of the order |
TRADE |
The Price |
The Volume |
The Value |
Transaction ID |
The Bid ID |
The Ask ID |
Bid or ask representaion |
String |
date |
date |
String |
Double |
Double |
Double |
Long |
Long |
Long |
String |
Where “record Type”
is the trade that occurred at particular time slot.
Here is a
sample of trade transactions in Sirca’s format
In ASX, a continuous market is used during normal
trading hours. Continuous market means that a matching algorithm is exercised
after each corresponding market event. Such events include submitting new
orders and amending existing orders. Normal trading hours is one phase in ASX
trading that we consider in this session. ASX exercises the following matching
algorithm during normal trading hours. The algorithm is typically triggered by
the arrival of a new submit, delete or amend order.
Firstly, each
order receives priority in accordance with the limit price and time of entry.
If the price of a bid (ask) equals or overlaps the best ask (bid), orders will
be automatically traded at successive prices to the extent that stock is
available at the specified limit price. For example, if an order is placed to
buy 100,000 units for 20 cents and the best ask is at 19 cents where there is 50,000 units on offer and a further 25,000 units are
available at 20 cents, the buy order will trade with all units at 19 cents and
25,000 units at 20 cents. The remaining 25,000 units of the buy order will not
be executed but remain on SEATS as a limit buy order at 20 cents depending upon
instructions given to the broker by an investor.
The matching algorithm can be generally described
as follows:
While spread <=
0 do the following:
i. Volume
traded is the minimum volume of best bid and best ask orders.
ii. The
trading price is determined as:
1.
if spread = 0 then the price is best bid
price (which is also the same as best ask)
if spread
<0 (i.e. overlapping in the orderbook) then the
trading price is the price of the earlier order submitted.
iii. Update
the orderbook as follows:
1.
Remove best bid and best ask orders if both
have the same volume.
2.
Otherwise, remove the order with the
minimum volume (either best bid or best ask) from the orderbook,
and update the volume of the other order
Where
spread=(best ask-best bid)
Let’s examine the following input file:
#Instrument,Date,Time,Record
Type,Price,Volume,Value,Trans ID,Bid
ID,Ask ID,Bid/Ask
AMC,20100401,7:33:26,ENTER,831,500,415500,5044,,8890248881250480000,A
AMC,20100401,7:33:41,ENTER,831,700,581700,5045,,6572914060944080000,A
AMC,20100401,7:34:03,ENTER,832,500,416000,5046,,2420623594072300000,A
AMC,20100401,7:45:35,ENTER,835,500,417500,5047,,11271937057675900000,A
AMC,20100401,7:46:03,ENTER,832,1000,832000,5048,2538037108379030000,,B
AMC,20100401,7:46:24,ENTER,831,500,415500,5049,12651623552247000000,,B
AMC,20100401,7:46:41,ENTER,832,2000,1664000,5050,1606954646700300000,,B
AMC,20100401,7:48:34,ENTER,829,2000,1658000,5051,12072779608763100000,,B
AMC,20100401,7:48:52,ENTER,828,2000,1656000,5052,9502744826424640000,,B
AMC,20100401,7:48:55,ENTER,827,2000,1654000,5053,11747846948127600000,,B
AMC,20100401,7:49:45,ENTER,827,2000,1654000,5054,7226869866406870000,,B
When running
previous matching algorithm in a continuous market, the corresponding trades
file is:
#Instrument,Date,Time,Record Type,Price,Volume,Value,Trans
ID,Bid ID,Ask ID,Bid/Ask
AMC,20100401,7:33:26,ENTER,831,500,415500,5044,,8890250000000000000,A
AMC,20100401,7:33:41,ENTER,831,700,581700,5045,,6572910000000000000,A
AMC,20100401,7:34:03,ENTER,832,500,416000,5046,,2420620000000000000,A
AMC,20100401,7:45:35,ENTER,835,500,417500,5047,,11271900000000000000,A
AMC,20100401,7:46:03,ENTER,832,1000,832000,5048,2538040000000000000,,B
AMC,20100401,7:46:03,TRADE,831,500,415500,5055,2538040000000000000,8890250000000000000,
AMC,20100401,7:46:03,TRADE,831,500,415500,5056,2538040000000000000,6572910000000000000,
AMC,20100401,7:46:24,ENTER,831,500,415500,5057,12651600000000000000,,B
AMC,20100401,7:46:24,TRADE,831,200,166200,5059,12651600000000000000,6572910000000000000,
AMC,20100401,7:46:41,ENTER,832,2000,1664000,5060,1606950000000000000,,B
AMC,20100401,7:46:41,TRADE,832,500,416000,5061,1606950000000000000,2420620000000000000,
AMC,20100401,7:48:34,ENTER,829,2000,1658000,5062,12072800000000000000,,B
AMC,20100401,7:48:52,ENTER,828,2000,1656000,5063,9502740000000000000,,B
AMC,20100401,7:48:55,ENTER,827,2000,1654000,5064,11747800000000000000,,B
AMC,20100401,7:49:45,ENTER,827,2000,1654000,5065,7226870000000000000,,B
Notice how a
continuous market is implemented which examines the existence of a trade after
each submission of an order. For example, the first trade is generated just
after a buy order with ID=2538037108379030000 is submitted at the price=832.0
and volume=1000 that makes it a best bid order with spread=-1. The trade
counterpart in this example is ask
ID=8890248881250480000 which is standing at the best ask. Since both orders
have the same price, they are both removed from the orderbook
by the time this trade is generated.
After processing all the order transactions, the orderbook looks as follows:
ORDERBOOK FOR
SECURITY AMC - BEGIN
Best bid=832.0,
Best ask=835.0
Ask[5047], 835.0,
vol:500.0, [11271937057675900000]
<--spread=3.0-->
Bid[5060], 832.0,
vol:1500.0, [1606954646700300000]
Bid[5057], 831.0,
vol:300.0, [12651623552247000000]
Bid[5062], 829.0,
vol:2000.0, [12072779608763100000]
Bid[5063], 828.0,
vol:2000.0, [9502744826424640000]
Bid[5064], 827.0,
vol:2000.0, [11747846948127600000]
Bid[5065], 827.0,
vol:2000.0, [7226869866406870000]
ORDERBOOK FOR
SECURITY AMC - END
Figure 1
illustrates another example of generating trades.
Figure
1: Example of an order generating (1) one trade (2) two trades