Bitcoin Algo Trading and Market Making Seminar

BitMEX CEO, Arthur Hayes, will lead an interactive seminar on the basics of algo trading and market making in the Bitcoin markets.

Arthur will touch on API connectivity through the use of an example python trading bot. He will also talk about the basic principles of market making Bitcoin spot and derivatives.

Participants should bring a laptop, and visit this GitHub repository for the example trading bot.

Date: Wednesday 22 March 2017

Time: 7pm to 9pm

Location: The Hive, 23 Luard Rd, 21/F The Phoenix, Wanchai, Hong Kong

Cost: Free

Please RSVP on Eventbrite.

How to Market Make Bitcoin Derivatives Lesson 2

In Lesson 1, I described how to calculate a two-way quote, dynamically hedge, and match the settlement for an ETC7D futures contract. In this lesson, I will discuss how to calculate Basis and Skew, and how to apply these to your two-way quotes.

Calculating Basis

To calculate the future value of any currency pair, you need to know the cost to borrow and lend the home and foreign currencies. The underlying currency of ETC7D is the ETC/XBT exchange rate. Assume that as a market maker you only own Bitcoin and not any other currency.

To buy ETC, you must sell XBT that you own. That XBT has an opportunity cost of capital. If you were to borrow this Bitcoin from another party to fund your business, how much would it cost?

To sell ETC, you must borrow it. There are two ways this is accomplished. For more well established digital currencies, spot exchanges like Poloniex will operate a borrow market. You can automatically pledge Bitcoin as collateral and borrow ETC at the market interest rate when you wish to short it.

If margin trading is not available, you need to borrow it from another trader. The other party will lend you ETC for a period of time at a rate of interest.

Using Covered Interest Rate Parity, we can calculate the Basis.

Basis = (1 + XBTr * t) / (1 + ETCr * t) – 1

XBTr = Bitcoin annualised interest rate

ETCr = Ether Classic annualised interest rate

t = Time in years

In practical terms, we ignore the opportunity cost of XBT. You can compensate for that by increasing your spread profit margin. As a market maker, you are concerned about how much you will pay to short ETC.

Assume it costs you 50% per annum to borrow ETC.

Basis for 7-day Future = 1 / (1 + 50% * 7/365) – 1 = -0.95%

If the spot price is 0.02 XBT, translate that Basis into points.

-0.95% * 0.02 XBT = -0.00019 XBT

ETC7D Quote Mid = Spot + Basis = 0.02 XBT – 0.00019 XBT = 0.01981 XBT

You have lowered your mid price. This will compensate you in the event someone sells to you. If you become long ETC7D, you will have to short ETC and pay the borrow fee.

Calculating Skew

You don’t have infinite capital. Left unchecked, you could build up a large long or short position in ETC7D. Your goal is to capture two-way flow so that you earn half of your quoted spread.

If someone continues selling into your bids, you want to progressively lower your quotes. If someone continues buying your asks, you want to progressively raise your quotes. A simple example will help illustrate the concept.

Assume you quote a two-way market of 10 / 11 for 1 contract each side. The total amount you are quoting on each side is 1 contract; I will call your Total Size Quoted. The bid / ask spread is 10%, half of that spread is 5%; I will call this your Weighted Average Half Spread.

Skew = (Change in Position / Total Size Quoted) * Weighted Average Half Spread * -1

Your position changed by +1.

Skew = (1 / 1) * 5% * -1 = -5%

You originally had a mid price of 10.5. Assume that the mid price represented the spot price.

New Mid Price = Spot + Skew = 10.5 * (1 – 5%) = 9.98

New Bid Price = 9.98 * (1 – 5%) = 9.48

New Ask Price = 9.98 * (1 + 5%) = 10.47

Combining Basis and Skew

Before you begin quoting, you will calculate the Basis. You will do this calculation based on how expensive it is for you to borrow the home currency.

Then while quoting, your trading program will adjust the Skew based on whether traders buy or sell from you.

Quote Mid Price = Spot Price + Basis + Skew

Using these two concepts, you cover your cost of funds, and manage your inventory.

In Lesson 3, I will explain how to handle Auto-Deleveraging events, and other advanced topics. To view the BitMEX sample market making bot, please visit Github.

How to Market Make Bitcoin Derivatives Lesson 1

high frequency trading

Providers of liquidity, or market makers, provide an essential service to any tradable market. They ensure that there is always a buy (bid) price and sell (ask or offer) price. This allows traders to enter and exit a market at any time.

If Bitcoin and the digital currency trading industry are to grow, exchanges will need more and more market makers to provide additional liquidity. There are many traders who have graduated from purely directional trading, to providing liquidity on various spot markets. This series of lessons is meant to give traders a basic understanding of how to market make digital currency derivatives.

Lesson 1 will focus on how to quote a two-way price, a simple dynamic hedging strategy, and settlement. In order to keep the math simple, we will use an 7-day expiring Ethereum Classic / Bitcoin futures contract, ETC7D.

Contract Details:

Contract Value: 1 ETC

Underlying: Poloniex ETC/XBT exchange rate

Settlement: 30-minute Time Weighted Average Price (TWAP) Friday 12:00 UTC

How to Calculate Bid / Ask Quotes

A futures contract derives its value from the underlying asset. For ETC7D, the underlying asset is the Poloniex ETC/XBT exchange rate.

Your trading program needs a live feed of the bid, ask, and last price of ETC/XBT on Poloniex. For starters, I advise you to calculate the mid price (average of bid and ask). As a market maker, you will hold futures contracts until settlement. Because a futures contract will equal spot at settlement, we can value ETC7D by the following formula:

ETC7D Quote Mid = ETC/XBT Mid Price (Spot) + Basis or Skew

After calculating your ETC7D Quote Mid, you will apply your spread. We will discuss how to calculate a Basis or Skew in Lesson 2.

As a market maker your spread compensates you for hedging costs (trading commissions, and bid / ask spread) on the underlying exchange, and the volatility of the underlying asset.

I will ignore the volatility component for now.

Spread = Spot Trading Fees + Spot Bid / Ask Spread + Market Maker Profit

The Market Maker Profit is how much you would like to earn on every trade.

Example:

Spot = 0.02 XBT

Basis or Skew = 0 XBT

Spot Trading Fees = 0%

Spot Bid / Ask Spread = 0%

Spread = 1.00%

ETC7D Quote Mid = 0.02 XBT

ETC7D Quote Bid = 0.02 XBT * 0.995 = 0.0199 XBT

ETC7D Quote Ask = 0.02 XBT * 1.005 = 0.0201 XBT

These quotes will be calculated then sent to BitMEX.

Simple Dynamic Hedging

Your goal as a market maker is to be market neutral. As other traders hit your bids and lift your asks, you must hedge yourself in the spot market.

Since each ETC7D contract represents 1 ETC, if you sell 1 ETC7D contract, you must buy 1 ETC. If you buy 1 ETC7D contract you must long sell or short 1 ETC.

A trader buys 300 ETC7D contracts at 0.0201 XBT from you. You are now short 300 ETC. Your trading program will automatically buy 300 ETC/XBT on Poloniex for 0.02 XBT.

Symbol Position Trade Price XBT Value
ETC7D -300 0.0201 XBT -6.0300 XBT
ETC/XBT +300 0.0200 XBT +6.0000 XBT
Unrealised Profit +0.03 XBT

You now have 0 ETC exposure. Because you have sold ETC7D at a greater price than where you bought ETC spot, you have an unrealised profit of 0.03 XBT.

You are still quoting a two-way market of 0.0199 XBT / 0.0201 XBT for 300 contracts each side. A new trader decides to sell 300 contracts at your Bid price of 0.0199 XBT. Your ETC7D position is flat (you sold 300 ETC7D previously, and now you just bought 300 ETC7D), and you are long 300 ETC/XBT; your net exposure is long 300 ETC. Your trading program long sells 300 ETC/XBT at 0.02 XBT.

Symbol Position Trade Price XBT Value
ETC7D -300 0.0201 XBT -6.0300 XBT
ETC/XBT +300 0.0200 XBT +6.0000 XBT
ETC7D +300 0.0199 XBT +5.9700 XBT
ETC/XBT -300 0.0200 XBT -6.0000 XBT
Realised Profit +0.06 XBT

Your portfolio is flat. You have realised a profit of 0.06 XBT or 1% of the value of your quotes. That 1% equates to the spread you built into your Bid and Ask quotes.

This is the simplest form of market making. You take the underlying spot price, apply a spread, and dynamically hedge 1:1 whenever anyone trades on your quotes.

Settlement

If you hold a futures contract over settlement, it will expire and leave you with no exposure.

Your Portfolio:

Symbol Position Trade Price XBT Value
ETC7D -300 0.0201 XBT -6.0300 XBT
ETC/XBT +300 0.0200 XBT +6.0000 XBT
Unrealised Profit +0.03 XBT

If you do nothing, on Friday 12:00 UTC your ETC7D position will go to 0, and you will be left long 300 ETC/XBT. Your goal is to be market neutral, so during the settlement calculation period you need to reduce your spot hedge to 0.

ETC7D expires based on a 30-minute TWAP. BitMEX will take the spot prices on Poloniex each minute and compute an average, which then becomes the settlement price. To capture the unrealised profit of 0.03 XBT, you to sell ETC/XBT at the ETC7D settlement price.

Your trading program will split your spot hedge into 30 slices, or 10 ETC. Each minute you will sell 10 ETC at market to match the price used in the settlement calculation. Because the settlement calculation uses the last price each minute, you theoretically will match the settlement price.

Any difference between your sell trade executions and the prices used in the settlement calculation is called Slippage. In this example, if your Slippage is more than 0.50%, you will lose money. If you have 0% of Slippage you will earn the full unrealised profit.

In Lesson 2, I will explain how to calculate a Basis and Skew. These two variables tie in closely with inventory management.

If you wish to begin market making on BitMEX, please take a look at our sample market making bot on Github.