The Nitty-Gritty of Paper Trading a Market Making Strategy

Photo by Alexander Schimmeck on Unsplash

In a previous article, we provided an introductory discussion on the so-called simplified Avellaneda-Stoikov market making strategy and hope that you have enjoyed using our end-to-end spot market making application which is based on this strategy and designed specifically for liquidity providers. One indispensable component of a good trading tool set is the functionality of allowing traders to perform paper trading before they decide to deploy real capital. Many automated trading bots have such an option, e.g. 3commas, cryptohopper, hummingbot, etc. Standing on the shoulders of these giants, we added this feature to our end-to-end spot market making application. The first two giants are closed-sourced and therefore we cannot take a peek on how they perform order matching simulation on a market making strategy. The third giant is open-sourced and thus allows us to perform detailed inspections on their methodology. In this article we’ll explain some of the important details to consider when designing and coding a paper trading simulator, present the theoretical and practical foundations of our methodology, and along the way highlight the sharp differences between our methodology and the third giant’s methodology.

Paper trading, also known as forward performance testing, is a simulation of actual trading and is very closely related to backtesting. Because it is used as a test and a guidance on how an application might perform in a live trading environment, the simulation engine is of utmost importance: ill-formed simulation logics can lead to spurious simulation results. In a live trading environment, the orders that you place are sent to the exchange’s order matching engine. In highly simplified terms, what happens inside an order matching engine is that your new order’s price is compared against what are already present on the order book, if a price crossing happens, your order is immediately filled and you become a market taker, otherwise your order isn’t filled immediately and is placed on the order book and you become a market maker. In a paper trading environment, we should follow the same logics to build the simulated order matching engine. In particular for testing a market making strategy, that means after we place an order on the paper, it should sit on the simulated order book and wait to be matched (i.e. filled) by the next simulated incoming taker order. In more precise and technical terms, if our market making order is a bid which sits on the buy side of the order book, it should be considered to be matched by an incoming taker sell order. If our market making order is an ask which sits on the sell side of the order book, it should be considered to be matched by an incoming taker buy order. The industry’s standard practice is (in simplified terms) to use trades happening on the live market to simulate incoming taker orders in the simulated environment. Each live trade is either a taker-is-seller trade or a taker-is-buyer trade. The orders sitting in the simulated environment should then be simulated to be matched by the taker side orders of these live trades. For a taker-is-seller live trade, the taker side order is a sell order and should be considered to match our bids on the paper, which will potentially result in a taker-is-seller simulated trade. For a taker-is-buyer live trade, the taker side order is a buy order and should be considered to match our asks on the paper, which will potentially result in a taker-is-buyer simulated trade. Hope so far it doesn’t sound like a tongue twister. :) The remaining details are to properly determine whether a simulated match results in a partial-fill or a complete-fill and what the appropriate amount of transaction fees is to be deducted from the relevant balances. Sounds simple but definitely easier said than done. We spent the past several weeks to work out the coding details, test this feature inside-out, and make it ready for use:

Coding is our friend. It lets us to take very deep thoughts on the nitty-gritty of a trading system and thoroughly examine the theoretical foundation of a framework. Open source is our friend. It lends us the opportunity to learn from other team’s wisdom and gives us the courage to beat a different drum. Healthy debates build healthy communities. So here we’d like to take the opportunity to highlight the methodological difference between us and hummingbot (which we are a big fan of) in paper trading. We discovered that in their paper trading engine when deciding how to match a market making order they took the approach of looking at the other side of the order book from the live market and filling the paper order if the price on the other side of the order book from the live market crosses the price of the paper order: Let’s look at a very practical (and very common) situation to realize that such an approach can be problematic: the bid-ask bounce. The bid-ask bounce is a specific situation when the price bounces back and forth between the bid price and ask price. This happens when there are trades on both the bid and ask price, but no real movement in price. In such a situation, no matter at what price you place your market making orders in paper trading mode, hummingbot’s paper trading engine will never generate any simulated fill because the live market’s order book is stationary and will never cross your order on the paper. But in real life in such a situation if you place your market making orders at the best bid/ask prices, your orders constantly get filled and you are one contributor to the bid-ask bounce. If you are also a big fan of hummingbot, perhaps try to make a pull request to fix it? :)

To sum up, we have released the paper trading feature of our spot market making application. We put very deep thoughts into this feature as discussed in this article and devoted lots of time to make it come to life. Hope that paper trading can bring you some good luck! Stay tuned on our upcoming feature of backtesting. If you are interested in our work or collaborating with us, join us on Discord 🎉

Disclaimer: This is an educational post rather than investment/financial advice.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store