Sitemap

Profitable Arbitrage Opportunity : A programmer’s perspective

3 min readJun 2, 2020

--

Press enter or click to view image in full size
Currency Arbitrage

ARBITRAGE

Arbitrage is the use of discrepancy in exchange rates of goods, services and currency to make a profit. Here I will be talking about currency arbitrage and the algorithm to find the profit.

What is Currency Arbitrage?

A currency arbitrage is a strategy in which a currency trader takes advantage of different spreads offered by brokers for a particular currency pair by making trades. Different spreads for a currency pair imply disparities between the bid and ask prices. Currency arbitrage involves buying and selling currency pairs from different brokers to take advantage of the miss priced rates.

Example:

Suppose that 1 U.S. dollar buys 49 Indian rupees, 1 Indian rupee buys 2 Japanese yen, and 1 Japanese yen buys 0.0107 U.S. dollars. Then, by converting currencies, a trader can start with 1 U.S. dollar and buy 49x2x0.0107 = 1.0486 U.S. dollars, thus turning a profit of 4.86%.

Identifying a currency arbitrage with real data

Let there be n currencies(C₀, C₁, C₂, …,Cₙ₋₁) with exchange rates given as R[i, j]. So 1 unit Cᵢ buys R[i, j] units of currency Cⱼ. The exchange rates of all the currencies can be given as an n*n table. Below is such an example I have taken from today’s exchange rates:

Press enter or click to view image in full size
Exchange Rates

We see it clearly that table represents a weighted directed graph. INR->USD is an edge with weight 0.013, GBP->EURO is an edge with weight 1.14 and so on, and the currencies represents the vertices.

Get Prashantprakash’s stories in your inbox

Join Medium for free to get updates from this writer.

We start with one unit of a currency and there is an arbitrage whenever we reach it back after exchanging through different currencies and have more money than what we started with. The problem hence narrows down to finding a loop such that the product of all the weights of edges we traverse through to be more than 1. This can be mathematically written as:

Reciprocating both sides, we get,

Taking log,

Press enter or click to view image in full size

Hence the question can now be re-framed as finding the cycle in the graph with negative total weight and the weight of edges can be given as:

This can be solved using Bellman-Ford. Here I am providing Java code for solving the problem with a list-based representation of graph.

Java Solution

Output:

Press enter or click to view image in full size
Output showing the profits

Conclusion

The profit percentages may seem small but for big amounts this is pretty big. Consider the second arbitrage we found. For an investment of INR 10,00,000, you will get a profit of about INR 13,112 which is a significant amount.

References:

1. Thinking of Investing in arbitrage you found? Have a look at the following link and find out Is it legal to invest in Arbitrages?

2. Follow the link to get a deeper understanding of the algorithm I used to find the negative weight cycle in the graph: Bellman-Ford Algorithm

--

--