/match-maker

C++/Python order matching engine

Primary LanguageC++

Match Maker

This is the source code for an order matching system written in Python/C++ to support trading operations for the Quantitative Impact Investment Club at the University of Toronto.

Credits

Written by the Quantitative Derivatives Research Team at the Quantitative Impact Investment Club.

Members:

  1. Michal Fishkin

  2. John Song

  3. Sam Qiao

  4. Muhammed Yakubu

  5. Tanya Humeniuk

  6. Rafay Kalim

Overview

This document contains an overview of our order matching, Match Maker. First, we give a brief explanation of how the system works. Then, we outline the high-level components that the system is composed of.

System Description

The system accepts an initial list of commands. From then, the system is continuously running and can accept a new command through some communication protocol. There are 3 types of commands that the system can receive:

  1. Buy Order - This is an order from an external party to buy shares of a security. It contains the following parameters:
  • Order Id - Identifier for this order. Could be automatically generated.

  • Security Id - Identifier for the security to be purchased

  • Price - Price (in an arbitrary currency) per share desired by the party. This is also known as the bid price. For now we are ignoring market buys, i.e. the price specified is the maximum someone is willing to pay for the security.

  • Quantity - Number of shares that the party wants to buy

  1. Sell Order - This is an order from an external party to sell shares of a security. It contains the following parameters:
  • Order Id - Identifier for this order. Could be automatically generated.

  • Security Id - Identifier for the security to be sold

  • Price - Price (in an arbitrary currency) per share desired by the party. This is also known as the ask price. For now we are ignoring market sells, i.e. the price specified is the minimum someone is willing to pay for the security.

  • Quantity - Number of shares that the party wants to sell

  1. Cancel Order - This is a request from an external party to cancel a previous buy or sell order. It contains the following parameters:
  • Order Id - Identifier for the order to cancel.

The system interacts with each party by sending notifications through a communication protocol. These notifications can be of many types:

  1. Order acknowledgement

  2. Order confirmation

  3. Order filled

  4. Order cancelled

But why?

A natural question to ask is how does the firm (the Market Maker, MM) that operates this system make money? To answer this question, consider two commands received by the firm’s order matching system:

  1. Buy Order from Party A
  • Order Id - 1

  • Security Id - “ABC”

  • Price - $10

  • Quantity - 100

  1. Sell Order from Party B
  • Order Id - 2

  • Security Id - “ABC”

  • Price - $9.97

  • Quantity - 100

This is a simplified scenario where A and B are a perfect match (in terms of security type and quantity) entering the system. Now, from the perspective of the MM, this situation can be handled in two steps:

  1. Purchase 100 shares of “ABC” at $9.97/share from Party B

  2. Sell 100 shares of “ABC” at $10/share to Party A

From this, it can be seen that there is a difference between the bid and ask prices of $0.03. When completing these two steps, the MM keeps the difference of $0.03*100 = $30. This $0.03 difference between the bid price and the ask price is known as the bid-ask spread, and is the primary source of income for the MM.

Software Components

This section contains the high-level components that our system is composed of.

  1. Data Reader
  • Command Validation

  • Order Id Assignment

  1. Matching Algorithm
  • Pro-Rata

  • Price/Time priority or FIFO

  • LMM

  1. Order Book

  2. Logger

  3. Visualizations