# Background

In this research, we dive into the bitcoin perpetual swap contract on the BitMEX exchange. Specifically, we are interested at the predicting power of its funding structure and the subsequent applications to algorithmic trading.

Traditionally, future provides additional liquidity and leverage to market participants. With $10k$ USD, one may either buy $1$ Bitcoin, or $100$ Bitcoin futures which provide $100$x more gain potentials. However, every future contract has an expiry date and can be traded at significantly spread. The first Bitcoin future in the U.S. was traded on Dec 10, 2017 on the Cboe Futures Exchange.

The Bitcoin perpetual swap contract, on the contrast, does not have an expiry date thus removing the need to rollover. It trades much closer to the underlying Bitcoin price via a funding mechanism. On BitMEX, the swap holders must exchange fundings every $8$ hours between the long and short counter-parties. This create price pressure for the swap price to converge to the actual Bitcoin price.

For example, if swap price $>$ Bitcoin price, then the funding would be positive and therefore the long positions will need to pay funding to its short counter-parties. This creates pressures for the swap price to decrease and move towards the Bitcoin price.

# Strategy

The funding creates a great monetary incentive if you are holding the contract on the right side and we would like to see if we can capture the funding gain overtime with an algorithmic trading strategy. Since the funding is announced $8$ hours before the actual exchange happens, we have an $8$ hour window of entry after knowing that a profitable funding will occur. After we enter the contract and collect the funding, we then have another $8$ hour window for exiting (this assumes we only want to enter $1$ contract at any given time). We will try to look for optimal enter/exit time combinations and evaluate performances.

This is similar to the mean reversion strategy discussed by BitMEX’s founder Arthur Hayes in his blog[1][2]. We are carrying this strategy further, analyzing enter and exit options at more granular level and proposing a more optimal execution strategy.

# Data

We can retrieve historical funding rates and minutely swap price data from the BitMEX api.

swapPrice fundingRate swapRet
timestamp
2016-06-05 04:00:00+00:00 585.6001 0.000242 -0.002756
2016-06-05 12:00:00+00:00 581.3784 0.000237 -0.004034
2016-06-05 20:00:00+00:00 580.9900 0.000234 -0.000978
... ... ... ...
2019-11-06 04:00:00+00:00 9314.4560 0.000100 0.013475
2019-11-06 12:00:00+00:00 9395.8470 0.000198 -0.008921
2019-11-06 20:00:00+00:00 9301.4603 0.000374 0.002900

# Analysis

Regress the funding rates to the swap return at different enter/exit time. Here we are trying to look for statistically significant (ideally, negative) correlation between the two. Since a negative correlation would imply additional gain from price change on top of the funding profit. We only consider entering a contract if the funding is outside twice of its 60-day historical rolling standard deviations.

Here we observe that as exit time becomes longer, the coefficient becomes more negative and p-value of the coefficient indicates higher significance. Thus we would want to hold the swap position more than 360 minutes/6 hours. Next we look at the impact from entry time.

Similar trends are observed in the entry times and that earlier the entry, the more profit it seems to imply from price changes. We show a summary of the regression at enter time$=-60$ minutes and exit time$=420$ minutes. There is a moderate R-square of 0.039 and high significance in coefficient which suggest a mean reversion in price given that specific time window.

# Strategy

Based on the research above, this strategy will enter into a swap agreement to collect funding at $t1= -1H$ and exit at $t2= +7H$. At $t2$, if the next funding does not fall outside of the 2-sigma band AND if we are in a position to collect the next funding, we will test two choices of

• holding for $1H$ more and exit after colllecting the funding
• exiting

We will test the impact of a 10bps fee + slippage on each trade.

swapPrice fundingRate swapRet swapRet1H sigma pnl pnlOptimized pnlFee
timestamp
2016-11-16 20:00:00+00:00 748.1800 0.000264 0.008467 0.014128 0.001042 1.000000 1.000000 1.000000
2016-11-17 04:00:00+00:00 744.8734 0.003750 0.008865 0.001431 0.001066 0.994885 0.994885 0.993885
2016-11-17 20:00:00+00:00 742.2400 0.003140 -0.007095 -0.001269 0.001081 1.010235 1.008677 1.009235
2016-11-18 04:00:00+00:00 740.0665 0.001242 0.012663 0.002800 0.001080 1.000000 1.000000 1.000000

Strategy P&L Sharpe Ratio Maximum Drawdown
0 Baseline 5.5625 2.2086 -0.1438
1 Optimized 6.7478 2.3101 -0.1221

We can see that this strategy does provide substantial P&L from the historical periods tested with relatively limited capital exposure. Fees would impact the gains slightly, and using an optimize approach would further improve the performance.

Reference:

[1]: XBTUSD Funding Mean Reversion Strategy, https://blog.bitmex.com/xbtusd-funding-mean-reversion-strategy/
[2]: Funding Mean Reversions 2018, https://blog.bitmex.com/funding-mean-reversions-2018/