# An Efficient Algorithm to Exploit Arbitrage Opportunities in Crypto Markets

By Federico Caccia

The crypto market is still inefficient. Cryptoassets have different rates on different exchanges. The big question is how we can profit from that inefficiency. One approach is making transactions between exchanges, but if we buy a cryptoasset on one exchange, by the time we can sell it on another, the price difference may no longer exist. For a discussion of this problem, see What I Have Learned from My Arbitrage Experiences with Cryptoassets.

A more efficient approach is using what I call virtual transactions: buying a pair on one exchange and simultaneously selling this pair in another exchange. In order to use virtual transactions to exploit arbitrage opportunities, you must have funded wallets before profitable oscillations events. In a profitable oscillation event, the price difference for a given pair between two exchanges allows you to make profit using two virtual transactions. The first virtual transaction at the time of the event and the opposite operation once the event dissapears and the price difference returns to average values in a considered period.

Put in mathematical terms:

where is the amount of assets you are exchanging, refers to the values you would pay buying these assets, refers to the values you would receive selling these assets, the sub-indices and refers to the two exchanges and the supra-indices and refers to the first and second virtual transactions. The  operator is used to average the values in a given period. This method is a statistical arbitrage method known as pair trading and works using co-integrated pairs. For a deeper look into pair trading algorithms, see Introduction to Pairs Trading. Most arbitrage only monitor for price differences and is just a particular case of this method, considering the second half of the equation equal to zero.

Statistical arbitrage has its risks, since it is necessary to hold cryptoassets, unless the chosen exchanges accept a stable currency as collateral for margin trading. Although there is a profit due to arbitrage, there may also be a devaluation of our capital due to market volatility. On the other hand, it is also necessary to hold a quote currency buffer in each exchange to cover price fluctuations.