FOREX and arbitrage
The foreign exchange market (FOREX) is a global decentralized market for trading of currencies. This includes all aspects of buying, selling and exchanging currencies at current or determined prices. What does arbitrage mean? Arbitrage is the simultaneous purchase and sale of an asset to profit from a difference in the price. It is a trade that profits by exploiting the price differences of identical or similar financial instruments on different markets or in different forms. Basically, it is “riskless” money. Maybe we are able to design an algorithm that is capable of detecting these arbitrage situations.
There are several graph algorithms. Breadth-first search or depth-first search are able to traverse a graph. We can find a shortest path between two nodes in a given graph either with Dijkstra’s algorithm or Bellman-Ford algorithm. Usually Dijkstra’s approach is better, but Bellman-Ford method is more robust. It can handle negative edge weights as well. This is exactly what we are looking for when dealing with FOREX arbitrage.
So, here is a table of exchange rates. We just consider few currencies such as USD, EUR or GBP. First, we have to construct a graph out of this table. The nodes of the graph will be the currencies. The edges represent the relationship between the currencies: it will be a fully connected graph of course.
Ok, we have managed to construct the graph. What weights should we assign to the edges? We have to take the natural logarithm of the values in the currency table and we have to negate it (multiple it by -1). We end up with a directed, negative weighted graph. How to find the arbitrage situations? We just have to make a Bellman-Ford algorithm. It is able to detect cycles. In this case, the cycles are the arbitrage situations.