|
OrderMatcherAn Order Matcher for an Electronic Stock Exchange (2000 Version) |
Prepared by
Torsten Layda (SWX Swiss Exchange)
Most financial markets have moved away from the traditional open out-cry mode (with people shouting at each other) towards an electronic system with participants sitting behind their computer screens. Only electronic systems are considered capable of meeting today's challenges of globalisation and rapidly increasing turn-over. This evolution is by no means limited to financial markets, but virtually applies to all commodities which can be bought and sold.
Electronic trading has given rise to a new price-fixing mechanism. In open out-cry trading the price derives from a process in which every seller seeks the highest bidding buyer and every buyer looks for the seller asking for the lowest price; this process is also referred to as two-sided auction. In an electronic exchange an order book is kept: All buy and sell orders are entered into this order book and the prices are set according to specific rules. Bids and asks are matched and trades occur.
We would like you to design a program, called OrderMatcher, that can determine in real-time the current market price and combine matching orders to trades. This is challenging, because of the complex matching rules and the high number of trading parameters involved and due to the large amount of orders entered by the market participants.
In a market-oriented system, no matter whether cows, apples, books, CDs or billions worth of stock are involved, the price always regulates the balance between supply and demand. A higher price results in a larger supply, while demand decreases. Conversely, at a low price the demand is greater and the supply smaller. The equilibrium price lies somewhere half-way and allows the execution of the greatest possible volume of orders. At any other price the turnover would be lower either because of less supply or less demand.
In practice, this simple rule is subject to certain complications. First, specific price increments must be considered for price fixing. They determine the difference between two adjacent valid prices. They must neither be too small, to assure enough order volume at each price increment, nor too big, to avoid big price jumps. Price increments range from hundredths of the monetary unit at low prices up to multiples of the monetary unit at high prices. There are also markets where price increments lie on, e.g., multiples of thirty-seconds of the monetary unit.
Supply and demand are neither changing in a smooth manner. The fewer bid and ask prices are available, the more randomness there is, leading to discontinuity in the supply and demand curves. For this reason, additional rules are sometimes needed in order to arrive at definitive price fixing, which can easily be explained to customers.
A particular beast are market orders. For such orders, no price is specified, which indicates that a buyer is willing to pay any price, while a seller is prepared to accept any price. Obviously, before entering a market order one has to be sure that no important price changes will lead to bad surprises.
A stock exchange is a market place where buyers and sellers of financial instruments (securities) get together to conclude trades.
A stock market can be operated in basically two modes: quote driven and order driven. In a quote driven market, so-called market makers always have to mention (to "quote") a bid and an ask price for the securities they are trading. Potential buyers or sellers walk from market maker to market maker, ask for quotes and make their choice. In an order driven market, all participants feed their buy or sell orders into the price forming process.
A stock market has to be attractive to both, to investors willing to spent money and to issuers introducing securities to trade. Therefore, the market has to be
To reach these objectives, more and more markets are moving away from the open out-cry system, where traders physically meet around rings or in pits, to an electronic, networked system. The access to this market from remote sites is not an issue anymore, not only due to the advent of the internet. This means that participants can be anywhere in the world, which in turn leads to increased liquidity and more consistent prices due to the centralised market place. Also, the complete order and trade routing cycle from the customer via the broker to the exchange and back via the clearing house (where the trade is executed) and the broker to the customer can become paper-less, or, at least, less paper intensive.
In an electronic exchange, the situation of supply and demand is represented in the form of an order book. This is the compilation of all buy and sell orders for a specific security at a certain point in time. Consider the following example for the share of OO Tech, Inc.
|
Buy orders |
Bid |
Price |
Ask |
Sell orders | ||
|---|---|---|---|---|---|---|
|
Individual orders |
Cumulative per price |
Cumulative least favorable price |
Cumulative least favorable price |
Cumulative per price |
Individual orders | |
|
400 + 300 |
700 |
700 |
Market | |||
|
200 |
200 |
900 |
101.0 | |||
|
300 |
300 |
1200 |
100.5 | |||
|
400 |
400 |
1600 |
100.0 |
4200 |
500 |
200+300 |
|
500 |
500 |
2100 |
99.5 |
3700 |
700 |
700 |
|
800 + 100 |
900 |
3000 |
99.0 |
3000 |
500 |
500 |
|
1000 |
1000 |
4000 |
98.5 |
2500 |
300 |
100 + 200 |
|
700 + 200 |
900 |
4900 |
98.0 |
2200 |
300 |
300 |
|
97.5 |
1900 |
300 |
100 + 200 | |||
|
97.0 |
1600 |
100 |
100 | |||
|
Market |
1500 |
1500 |
700 + 800 | |||
In the center column, all possible prices are shown in decreasing sequence from top to bottom. On the left side the buy orders (demand) are shown, and on the right side the sell orders (supply). The outmost columns show the individual orders. The columns next to them show the cumulative total of order volumes per price. The two columns directly beside the price column are decisive. Here all orders are accumulated from the least favorable prices onwards, starting with market orders. On the buy side, market orders and then the orders with the highest purchase limits down to the lowest are added continuously. On the sell side, accumulation starts with market orders and then goes from the lowest sell price up to the highest.
Maximum execution occurs at a price of 99, where 3000 units change hands.
Generally speaking, securities can be traded either
Correspondingly, the order book is said to be in various states. The two most important order book states are
Other less important order book states include
Not all states are valid successors for a given state. E.g., it is not possible to put a new security immediately into permanent trading. There must be an Accepting Orders state followed by a break before.
Note that an auction is not a state of its own, but happens instantly. All trades resulting from the auction bear the same time stamp.
Typical 24 hours order book state cycles are (each 'A' stands for an auction)
(i.e. permanent trading during the day with a break for lunch)Break --- -A- Trading --- Break(60'@12:00am) --- -A- Trading --- Break
or
(i.e. permanent trading with a closing auction)Break --- -A- Trading --- Break (10'@4:50pm) --- -A- --- Break
or
(i.e. seven auctions a day).Break -A- Break -A- Break -A- Break -A- Break -A- Break -A- Break -A- Break
As on any market place, also the trading on an electronic exchange needs a set of rules which govern the matching of orders to trades. These matching rules are representing the market model and aim at the generation of trades as the participants expect them to occur.
There is one set of matching rules for every order book state in which matching can occur. Usually they are quite complicated (cf. Ref. 1). The precise rules vary from exchange to exchange. In this sense, the following is to be understood as an example only.
During a break, the opening price is most often determined on the basis of the orders in the order book, according to the principle of maximum execution. All trades occur at the same price, the opening price. In the example above, this would be 99. After the opening, the only orders remaining in the order book are those not executable due to a lack of matching orders.
It may well happen that no opening price can be fixed because there are no orders in the order book which could be matched according to the rules. In such a case, trading is either opened without an opening price or not opened at all.
In permanent trading, matching is governed by different rules than the determination of the opening price. Here an attempt is made to execute each new incoming order and hence trigger a trade (or several trades). If no matching is possible, or if only part of the order has been matched, the remainder is entered in the order book.
Most commonly, the orders are matched in price/time priority: The order with the better price has a higher priority than an order with a worse price. Here "better" has to be read as "higher" for a buy order and "lower" for a sell order: A buyer who is prepared to pay more money than anybody else gets the deal; in the same way a sell order which is asking for the least money gets highest priority. Remember that market orders are always considered to have the best price. For orders at the same price, the order which was entered first is executed first.
A common way to avoid big price fluctuations is to impose a limit on the difference between two subsequently paid prices. When this so called stop trading range would be exceeded, trading is stopped for a few minutes to give everybody a chance to settle down.
Typical stop trading ranges go from 10% or 5% of the last paid price for illiquid securities down to less than a percent of the last paid price for securities with high liquidity and of particular importance. The latter include the securities from which the market index is calculated.
If the order book is in a break or in permanent trading, each insertion or deletion of an order in the book triggers the order matcher to apply the matching rules.
No trade is generated if the difference between a resulting trade price and the last paid price exceeds the stop trading range. If no stop trading arises, the trades are either generated and published (permanent trading) or the theoretical opening price is updated (break). If a stop trading occurs, the order book is either put into stop trading (permanent trading) or the opening is delayed (break).
Each security traded on an electronic exchange belongs to a market segment, e.g. to the domestic shares or the foreign issuer bonds. Trading hours and trading mode (permanent trading or auction) are typically set on a per segment basis.
This description has been restricted to the most important key features of an electronic exchange, but it should be sufficient to grasp all basic principles.
More complicating features of an electronic exchange such as
Develop a design for a program "OrderMatcher", which implements an order matcher for an electronic, order driven stock exchange.
OrderMatcher has to keep an order book for each security. The OrderMatcher has to support various states and has to switch from one state to the next based on a schedule established for the segment the security belongs to.
We want you to focus on the actual matching of orders. The matching is based on the matching rules applicable to the current order book state and on the trading parameters for the security. Keep in mind that trades must only be generated if the order book is in the trading state.
As for the matching rules, a first version should observe price/time priority during permanent trading, and in a break, in addition, the principle of maximum execution (cf. the use cases).
The OrderMatcher has to support stop trading, by first determining all trade candidates for one cycle of the application of the matching rules and then verifying that none of the trade prices is further away from the last paid price than the stop trading range. Only then the actual trades are to be generated.
Also design an infrastructure based on which the order book states and trading parameters for a given security and a given segment can be readily adjusted to market requirements by the exchange personnel.
You can safely ignore the mechanisms of how orders reach the order book and of how the trading parameters are actually set-up.
The following requirements apply to the order matcher application:
The following use cases give examples of typical scenarios as they occur in the operation of an electronic stock exchange. They illustrate some of the above requirements.
For the matching rule use cases, incoming orders are underlined, while the orders which actually match are in italics. The resulting trade price or the new theoretical opening price is in bold-face. All orders at a given price are accumulated.
A buy order with a price better than or equal to the incoming order price (from the point of view of the incoming order) is already in the order book.
Last Paid Price = 44
|
Bid |
Ask | ||
|---|---|---|---|
|
200 |
40 |
39 |
100 |
|
100 |
38 |
41 |
100 |
|
100 |
37 |
43 |
100 |
No order with a price better than the incoming order price (from the point of view of the incoming order) is already in the order book.
Last Paid Price = 44
|
Bid |
Ask | ||
|---|---|---|---|
|
200 |
Market |
46 |
200 |
|
200 |
41 | ||
|
200 |
40 | ||
A sell order with a price better than or equal to the incoming order price (from the point of view of the incoming order) is already in the order book.
Last Paid Price = 44
|
Bid |
Ask | ||
|---|---|---|---|
|
200 |
43 |
Market |
200 |
|
42 |
200 | ||
|
43 |
200 | ||
Note that the order determining the trade price is actually not involved in the trade.
No order with a price better than the reference price (from the point of view of the incoming order) is already in the order book.
Last Paid Price = 44
|
Bid |
Ask | ||
|---|---|---|---|
|
100 |
Market |
Market |
100 |
No order with a price better than the arithmetic mean of the last two orders matched is in the order book.
Last Paid Price = 44
Arithmetic Mean = 39.5, rounded to 40 (price increment = 1)
|
Bid |
Ask | ||
|---|---|---|---|
|
100 |
40 |
39 |
100 |
|
100 |
39 | ||
Buy order with a price better than the arithmetic mean of the last two orders matched is in the order book.
Last Paid Price = 44
Arithmetic Mean = 39.5
|
Bid |
Ask | ||
|---|---|---|---|
|
100 |
40 |
39 |
100 |
|
100 |
39 | ||
Note that the order determining the opening price would actually not be executed in the auction.
A new stock exchange act has become effective. The matching rules have to be adapted such that for the same price, customer orders have priority over orders entered on behalf of the broker, irrespective of their time of entry.
The matching rules are adapted by the development department, tested with the members and put into operation on the pre-defined date.
The trading and listing department introduces ("lists") 7 new securities and assigns them to the relevant market segments:
The securities become tradable in two weeks and will accept orders in a week from now.
The shares from which the market index is deduced show too much volatility: The oscillations of the paid prices do not reflect the market behaviour, but are mostly due to input errors of market participants due to a lack of experience. Last week, e.g., somebody sold 5000 pieces at 100 instead of 100 pieces at 5000.
The stop trading range for these shares is reduced by the trading department from 2% to 0.5%.
Program trading has drastically increased the order flow. Participants frequently adapt all their order prices in the market when the market situation changes. The trading department decides to double the price increments, so that only larger fluctuations justify an adaptation of order prices.
The change is executed at the end of a pre-defined bank working day. All orders in the concerned order books are deleted to get rid of orders sitting on the now invalid intermediate ticks.
In a couple of low volume bonds the last paid prices become out-dated and do no longer reflect the current market situation. Also, the bonds become quite volatile. The trading department switches these market segments from permanent trading to auction mode.
Trading volume in the B Chemicals security has risen and is expected to continue to do so at a high pace due to various rumours in the market. The order matcher for B Chemicals is moved to a dedicated hardware unit.
The OrderMatcher is interfaced to the systems of the market participants, from which orders are received and to which the resulting trades are broadcast. Also, there is an interface to the clearing house, to which all trades are forwarded for clearing and settlement. The exact mechanisms are beyond the scope of this problem. It is sufficient to assume that there is an infrastructure for market participants to insert and delete orders and for trades to flow out.
The same holds for the maintenance of the trading parameters by the exchange personnel.
The OrderMatcher would be the core of an Electronic Commercial Network (ECN). Other components are discussed in DesignFest, too: The thin client (client/server) application, e.g., would be used by the participants to enter orders and receive trade information.
All these books, and many more, can be ordered at the bookstore of the SWX Swiss Exchange.