+7 906 906 18 20 Envelop 5927e2bc4f7195a77dda21f7859ed9d3bf9c3c724f49439b85f191cfc618519c info@megatrader.org
en

Bitcoin statistical arbitrage

Recently, little-known Bitcoin (BTC) cryptocurrency attracted unprecedented hype, setting it on par with "big" currencies. Amid growing popularity cryptocurrencies trade volumes skyrocketed. Meanwhile, bitcoin trading exchanges are still very young, ineffective and lack professional players, which means that they can be successfully used for implementing various strategies like cross-exchange arbitrage. Given the bitcoin’s unusually high volatility and the fact that price differences on various exchanges often reach 20 % or even more, the potential profitability of arbitrage strategies in bitcoin market becomes huge, especially in comparison with "classical" markets. In this article we describe a unique trading strategy - Bitcoin statistical arbitrage and show how to create a MegaTrader trading robot that implements this strategy.

Currently there are several cryptocurrency exchanges, but only two of them have satisfactory liquidity. First - MtGox Japanese exchange, which is the oldest and biggest in terms of trading volume bitcoin exchange. The second is young and rapidly evolving BTC-e. An interesting "feature" of these exchanges is MTGox bitcoins being usually more expensive than the BTC-e. As an example, we provide the price chart for MTGox (blue line) and BTC-e (red line) from 14 August to 24 December 2013:

Price chart for MTGox and BTC-e

To make it clearer, here’s the spread chart (MtGox price - BTC-e price):

Spread price for MTGox and BTC-e

After a short glance at the charts first thing that comes to mind is buying bitcoins at BTC-e, transferring them to MtGox and selling there. This strategy is commonly advised by various authors at bitcoin-related trading websites and blogs. However, if you do thorough calculations it turns out that this strategy is not so profitable. First, while the transfer is carried from BTC-e to MTGox, bitcoin price may fall, which, given the high volatility of bitcoin, is totally possible and can cause significant losses. Second, withdrawal from MTGox takes from two weeks to a month, which significantly limits the rate of such "arbitrage" operations to one, maximum two per month. Third, the commissions for withdrawal from MTGox and deposit to BTC-e for the next "round" will eat up a good portion of profit . As a result, in its purest form, this strategy is not relevant for an average trader.

We offer a more profitable strategy - statistical arbitrage between bitcoin exchanges. This strategy is based on the phenomenon of spread value preservation between different assets (correlation). We profit with speculation on pair’s spread fluctuations. In relation to bitcoin statistical arbitrage is done as follows: when the difference in prices (MtGox - BTC-e) is higher than the historical average, we sell the spread, ie short on MTGox and simultaneous long on BTC-e. and vice versa - when the price difference is lower than historical average, we buy the spread. When the difference between the prices returns to its historical mean, positions are closed. The advantage of such statistical arbitrage is almost complete absence of risk: because our net position consists of divergent positions on the same instrument, it always remains neutral to the market and thus is insured to any news and bitcoin volatility. The only risk is the historical mean value changing. However, in case of bitcoin, this risk is also negligiblebecause we trade the same asset on both exchanges and ratio changes can not be too large.

The only problem persisting is that these exchanges do not offer the possibility to go short, ie you can not sell bitcoins. But, fortunately, there is a "way around" - using bitcoin CFD contracts. Because of rapid bitcoin popularity growth a number of forex brokers and dealing centers started providing the possibility to trade bitcoin in CFD-contracts. In the future the number of such companies will very likely continue to grow. Most brokers use MtGox’s bitcoin price as the base asset price for their CFDs. At the same time BTC-e, since October 2013, offers a special account for MetaTrader - with the possibility to trade bitcoins through MetaTrader 4 and most importantly - they provide short selling opportunity. In the result we have a potentially simple implementation of statistical arbitrage between MTGox and BTC-e. It is enough to open two accounts: first - with a forex dealer providing bitcoin CFD-contracts with MTGox prices and the second - BTC-e MetaTrader-account. Then it’s enough to enter the right algorithm in Megatrader program and you’re set to profit from price difference.

Now to the real experience: here we will tell you how to implement bitcoin statistical arbitrage with Megatrader.

First the spread symbol must be formed. To do this, go to "Settings > Composite instrument settings". Now we add bitcoin’s CFD contract to "hort" tab, BTC-e goes to "Long" tab. When adding the CFD we should double check the lot size and other settings and set the "Lots in spread unit" parameter to be equal to one BTC. For example, if a contract is 100 BTC, "Lots in spread unit" should be set to 0.01. BTC-e contract is equal to 1 BTC, so we set "Lots in spread unit" as 1.

Spread settings

Now straight to the trading algorithm creation, which is written in a special Megatrader’s internal scripting language. Algorithm’s main idea was mentioned above: we sell/buy the spread when it fluctuates above/below its historical mean accordingly. Positions are closed when the spread reverts to the mean value. The question appears - how is this historical mean value calculated? The easiest method is applying a high-period moving average (say, 5000) on the spread.

To realise the strategy in Megatrader necessary indicators should first be applied to the spread chart. To do so, go to "Chart > Add chart", then we add the indicator "Mean Price", which shows the average value of Bid and Offer prices. Our next step is adding the moving average itself, picking "MeanPrice" as the data source. Also an identifier should be set for our moving average to call it from the script (default is "MA").

Now we can proceed to script creation itself. The easiest to write script (simplest) implementing the strategy looks approximately as follows:

Script for bitcoin statistical arbitrage

Let’s test it on a historical data chunk from 25 November to 20 December of 2013 year. Please take into consideration that BTC-e exchange charges a commission for each order, and it should be taken into the calculation while backtesting. Let’s set the commission to 2.5 points (it’s excessive, frankly spreaking). After backtesting we get the following resulting profitability chart:

Trading robot profitability chart

Trading robot financial result

Now to a more peculiar historical ratio calculation method. To do so, we build the chart of MTGox divided by BTC-e prices:

ratio chart for MTGox and BTC-e

As can be seen, the resulting chart is more stationary (cointegrated) than the one we got before. We can clearly see that the average value fluctuates somewhere near 1.1. It means, that, on average, MtGox’s bitcoin price is 1.1 times (+10%) more than BTC-e’s. Let’s call this a "fair historical ratio". From here we can easily calculate that the real "spread" (MTGox - BTC-e), will be equal to 10% of BTC-e’s price:

So, assuming prices are currently at a "fair ratio":

MTGox / BTC-e = 1.1, therefore MTGox = 1.1*BTC-e.

By placing this into the spread’s formula we get:

Spred = MTGox – BTC-e = 1.1*BTC-e – BTC-e = 0.1*BTC-e.

We can then take this "historical ratio" and place it into our script instead of our MA. The results are:

Second script for bitcoin statistical arbitrage

As it can be seen, the script mainly remained the same. The only change is "historical ratio" calculation formula in the script. Also we have fiddled with deviation necessary to open a position (we’ve set it from 30 to 20), to make our system trade more often.

Testing our new script on the same historical data period:

Trading robot profitability chart

Trading robot financial result

System’s results became even better: after a month’s trading of 1 BTC we gained a profit of 863$ with 100% profitable trades.

So we've seen two examples of trading algorithms and scripts that implement bitcoin statistical arbitrage. Despite the fact that these strategies are quite simple, they nevertheless demonstrate high potential yield. However, there are many ways of further improvement of these trading algorithms. For example, multi-level position averaging can be added. An example of it can be seen in our another article - Calendar arbitrage, Part 2 - Trading Robot - creating a trading robot. Script described there can be used for bitcoin arbitrage virtually unchanged.

In conclusion, we would like to note that as long as there will be funds transfer difficulties between trading exchanges, and most will not offer short selling opportunity, a significant difference in prices between different bitcoin exchanges is likely to stay , which means that this strategy does not lose its relevance. Thus, the current situation on cryptocurrency stock exchanges provides traders with a unique opportunity to take advantage of arbitrage and get a great profitwhile maintaining minimal risk.