Algorithmic Trading 101 — Lesson 6: Market Making & Performance Evaluation

The Ocean
The Ocean
8 min readAug 10, 2018

--

With beta testing ongoing and launch right around the corner, our 101 series is coming to a close. However, this doesn’t mean the end. We’ll be pushing out more educational content and contests to determine the lucky winners of our pool of $5000 reserved for this series. (Stay tuned for that!) But for now, let’s wrap it up with market making strategies and proper performance evaluation.

Introduction to Market Making

When investing money across markets, there are a variety of types of strategies that can be implemented. So far, we have discussed arbitrage trading, regression predictions, and machine learning models. These three types of strategies are known as alpha generation or buy-side methods they create a profit from fluctuations on the market. Conversely, there are execution strategies or sell-side methods which are designed to capture spreads, otherwise known as the difference in price between buys and sells. This is known as the world of market making.

Broadly, a market maker is a trader that provides liquidity to both buy and sell products. They are essentially a guaranteed counterparty for other traders that are single directional in the market. This makes for an equitable marketplace as the market maker is able to provide the liquidity, and the market taker is able to match off with the corresponding trades. As a result, the market maker must be proficient at consistently updating the prices of the asset based on the relative supply and demand provided in the industry.

There are two main ways that market makers create a profit:

  • They raise the price of an undervalued asset. By doing this, the market maker will attract individuals who were long (buying with the expectation of a higher price in the future) at an even lower price. Then once this executes, the market maker will sell it at a slightly higher prices to turn in a profit.
  • They lower the value of an overpriced stock. This is similar to the previous case as individuals will sell to the market maker however this will cause an increase in the supply of the stock as there will not be many buyers in an overpriced market. The market maker will thus lower their price to sell their inventory.

In essence, the market maker controls how many units (of stock, cryptocurrency, etc.) are available in the marketplace and adjusts the price based on the supply and demand of said asset. This means that market makers are both useful and influential. By guaranteeing liquidity of certain quantities, they have the power to dictate price.

Let’s talk through an example of how makers and takers interact in a continuous double auction (which is how most stock and crypto exchanges work). Typically there are two general types of traders someone can place on the book:

  • A market order is executed at the next available price and fills the full size based on what the current market price is.
  • A limit order sets the price of execution but may not fill the full size if the liquidity is not present at the given price.

Let’s suppose that the current market price of ZRX is $1.05. Overnight, there is a positive news headline about ZRX. The assumption naturally is that the market price will increase, so any individual trader will want to place a market buy order for 100 ZRX at $1.05, anticipating that price increase once everyone hears the positive news. However, chances are that a fair amount of people also heard the same news at the same time, and have also placed market buy orders as a result. A market maker, knowing this behavior is likely, sets his price at $1.10 as a result. When everyone wakes up — presuming that a large amount of buyers trade on the good news — the price will be pushed to the market maker’s $1.10. In fact, it might be pushed even higher to $1.15.

Since many individual traders are likely placing market orders, to (try to) instantly capitalize on the news, it’s likely that the average fill price is much higher than the price of $1.05 from the day before. Eventually, after the price of ZRX rises to $1.15 with the rush of demand, the price could fall back to $1.12. In this case, the market maker would be able to sell their ZRX inventory to meet peak demand at $1.15 — and then restock their inventory when the price falls to $1.12 for a quick profit. This type of strategy is known as price gaping.

In any market making strategy, the trader is trying to capture changes in spreads, both across markets and over time in the same market. In volatile or fragmented markets, there will be large spreads — and in the cryptocurrency markets, there are significant spreads. Even in stable markets with tight spreads, market making can be quite profitable as market makers trade very frequently throughout a single day.

As a result, automated market making algorithms can:

  • Provide tighter spreads due to automation and spread capture
  • Increase liquidity for all market takers
  • More efficiently price the market based on supply and demand
  • Reduce market volatility and price gaps

On The Ocean, we provide the tools to be an effective market maker and taker. We provide both limit and, unlike any other DEX, true market orders. Our low fees (especially if you sign up early for OCEAN tokens) makes spread capture strategies more profitable. And because we never take custody, you don’t need to wait or pay for withdrawals to trade again. And finally, with our client libraries and CCXT integration, it’s easy to trade algorithmically on our platform in no time at all.

In the future, we’ll release some sample market making code. For now, here’s some additional resources regarding market making strategies:

Performance Evaluation

After any trade, everyone’s always interested in the most “important”, how much money did I make?! However, looking solely at profit numbers can be misleading in evaluating the effectiveness of a strategy, as the magnitude of the trade could lead to some wrong conclusions. For example:

  • Say in Strategy A, you invest $1M and return 8% — you’ve made $80,000
  • Say in Strategy B, you invest $2M and return 6% — you’ve made $120,000

If you focus on $ returned, Strategy B appears more successful than Strategy A, but in reality Strategy A, on a per dollar invested basis, is the better strategy, since it’s return % is higher.

There are a number of different metrics we can use to evaluate strategy effectiveness. There is no “right” metric — it all comes down to what you, with your own risk-return profile, choose to care most about. And no one metric can capture everything good — or bad — about a trade. As a result, we suggest to always evaluate your strategy with a variety of metrics, some of which are listed below:

Realized and unrealized PnL

Realized PnL is the “profit and loss” that you book once you exit/close your position. Unrealized PnL is the potential profit or loss on your current position. The theoretical exit price for unrealized PnL computation is the price which crosses the spread to flatten the position. Traders generally have multiple positions open at any one time, but the summation of the realized and unrealized PnL is viewed at the total PnL for accounting purposes.

Let’s look at an example:

  • Buy 10 lots at 1.00 and buy 5 lots at 1.03
  • Sell 8 lots at 1.05
  • Active positions: 10 + 5 — 8 = 7
  • Average buy price: ((10 * 1.00) + (5 * 1.03)) / (10 + 5) = 1.01
  • Average sell price: (8 * 1.05)/8 = 1.05
  • Realized PnL: (average buy price — average buy price) * quantity = (1.05 — 1.01) * 8 = 0.32
  • Theoretical exit price: 0.99
  • Current market price: 1.02
  • Unrealized PnL: (theoretical exit price — current market price) * active position = (0.99 — 1.02) * 7 = -0.21
  • total PnL = realized PnL + unrealized PnL = 0.32 — 0.21 = 0.11

You can read more about PnL on BitMex.

Sharpe Ratio

Sharpe Ratios put your strategy’s performance into the larger context of how much risk (or volatility) that you took to achieve returns.

Bigger Sharpe ratios are better — it means either higher returns or lower volatility to get returns. This measurement helps examine a portfolio holistically, and because it is a commonly used metric across many types of markets, an individual can see how their strategy compares to others easily.

Win/Loss Ratio

Any time a position is taken, there is generally a stop-loss and a take-profit level also associated with the position. The distance of these levels can be determined by numerous factors, including technical levels, confidence intervals, psychological levels, time horizons, and risk tolerance. Based on the distance of the levels, you can determine what win-loss ratio you need to make the strategy profitable.

In order for a strategy to be profitable, the following inequality must hold:

x * TP + (1 - x) * SL >= 0

where x = win trade percentage
SL = stop loss pips
TP = take profit pips

How a trader sets his or her TP/SL ratio determines how many trades they need to “win” in order to be profitable:

  • If we set TP = SL, then we need x> 50% in order to make money. In other words, if we choose levels that are equidistant away from the market, we need to make sure that over half of the trades hit the TP to make money.
  • If we set TP/SL = 2, then we need x > 33.3%. So if our TP margin is double our SL margin, we need more than a third of our trades to hit the TP level. This could be a situation where we have a larger number of trades that actually lose money but since our win trades are making significant profit, we are still overall profitable.
  • If we set TP/SL = 0.5, then we need x > 66.7%. If our TP margin is half of our SL margin, we need over two/thirds of our trades to be profitable. This could be a situation where we believe we can short squeeze a quick profit, since our SL is much further from current market than the TP.

Challenge #6— Market Making

Challenge: Use the CCXT library to create a market making algorithm for The Ocean.

Bonus: Use your algorithm on The Ocean during our beta period. Email hello@theocean.trade to join.

And that’s a wrap! For all you that have been following our journey since April, we truly appreciate your support. We hope that this series has been educational and helpful, and we look forward to creating more content for you in the future.

Stay tuned for announcements around our pool of $5000 reserved for students, mentors, and community members.

__________________________

🤖 Links to Lessons 🤖
The Syllabus & How to Win
Lesson 1: Time Series Analysis
Lesson 2: Data, Strategy Design, and Mean Reversion
Lesson 3: Intro to Arbitrage Strategies
Lesson 4: Portfolio Management and Machine Learning in Python
Lesson 5: More Machine Learning
Lesson 6: Market Making & Performance Evaluation

Remember to join our Telegram if you have any questions!

--

--

The Ocean
The Ocean

The Ocean is a high performance 0x-based Ethereum ERC20 token trading platform. Sign up for launch news: www.theocean.trade