Algorithmic trading

 
 

From data to value

This portfolio item highlights my ability to execute an entire data-driven project from inception to deployment. The project goal was to identify and exploit an arbitrage opportunity. This means taking advantage different prices between exchanges for the same asset. Software was written in R, C, and Python, and leveraged both borrowed code and web communication libraries (OpenSLL via libcrypto, cURL via libcurl, and a Python websocket client). After profitability was realised, the project was ended due to a lack of leverage. The whole project can be summarised in the following steps.

  1. Understand arbitrage

  2. Automate data farming

  3. Survey for arbitrage opportunities (see $)

  4. Design a trading policy

  5. Implement broker interfaces

  6. Implement trading pipeline

  7. Turn on (get $)

What is arbitrage?

Arbitrage is the exploitation of pricing differences between exchanges for the same asset. Under healthy market conditions, the different prices inevitably converge, and profit may be extracted by hedging--simultaneously taking a long position (bet up) on one exchange and short (bet down) on the other. This form of profit certainty makes arbitrage trading popular enough to often be eliminated through exploitation.

However arbitrage opportunities still exist in riskier frontiers, where previously assumed healthy market conditions are in doubt. Our opportunity exists on the Cryptocurrency (Bitcoin) frontier, where heists sometimes destroy entire exchanges. I've anonymized my particular market inefficiency, because it still exists, and I could still exploit it. Another risk to leveraging this strategy is that insufficient market depth may exist to make it a worth-while investment.

Value discovery process

Cryptocurrency brokerages have RESTful and sometimes websocket APIs that can be used to farm data. Data farming software was written for many exchanges. Because arbitrage is the exploitation of pricing differences, discovering opportunities was as simple as using R to plot several exchanges' prices over time and looking for significant separation. A discordant asset pair was found.

After visual inspection, projected cost-of-exploitation was compared to expected revenue. The discovery of net-positive expected profit finally identified the opportunity as worth attempting. Prototypes were constructed with borrowed code and written in RC/C++, and Python. Prototypes further validated the strategy.

Value extraction process

The final software was written in C. Shared object (.so) files were used to compartmentalise software modules. Abstract interfaces were defined to standardise local brokerage interfaces. The software was implemented in three major modules: (1) farming and execution, (2) broker 1 local interface, (3) broker 2 local interface.

The software was allowed to run for two months and produced net-positive returns as expected. However, the strategy was never leveraged (invested in with borrowing) due to the persistent risk of an exchange heist. This strategy, like other arbitrage opportunities, requires leverage to be effective, so the software was shut down and the hardware was repurposed.

Conclusions

Without leverage and not accounting for the risk of an exchange heist, this strategy produced an expected annual return of 3%. The choice to properly leverage this strategy depends on how much profit one can extract in a short amount of time. The risk of a heist is likely estimable because Cryptocurrency technology is now maturing. The amount of profit which could be extracted per unit time depends on the market depth of the exploited inefficiency. Because this potentially profitable avenue remains open, I consider this project a success.