24-3 Arbitrage

Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 11 U.S. dollar buys 4949 Indian rupees, 11 Indian rupee buys 22 Japanese yen, and 11 Japanese yen buys 0.01070.0107 U.S. dollars. Then, by converting currencies, a trader can start with 11 U.S. dollar and buy 49ร—2ร—0.0107=1.048649 \times 2 \times 0.0107 = 1.0486 U.S. dollars, thus turning a profit of 4.864.86 percent.

Suppose that we are given nn currencies c1,c2,โ€ฆ,cnc_1, c_2, \ldots, c_n and an nร—nn \times n table RR of exchange rates, such that one unit of currency cic_i buys R[i,j]R[i, j] units of currency cjc_j.

a. Give an efficient algorithm to determine whether or not there exists a sequence of currencies โŸจci1,ci2,โ€ฆ,cikโŸฉ\langle c_{i_1}, c_{i_2}, \ldots, c_{i_k} \rangle such that

R[i1,i2]โ‹…R[i2,i3]โ‹ฏR[ikโˆ’1,ik]โ‹…R[ik,i1]>1.R[i_1, i_2] \cdot R[i_2, i_3] \cdots R[i_{k - 1}, i_k] \cdot R[i_k, i_1] > 1.

Analyze the running time of your algorithm.

b. Give an efficient algorithm to print out such a sequence if one exists. Analyze the running time of your algorithm.

a. To do this we take the negative of the natural log (or any other base will also work) of all the values cic_i that are on the edges between the currencies. Then, we detect the presence or absence of a negative weight cycle by applying Bellman Ford. To see that the existence of an arbitrage situation is equivalent to there being a negative weight cycle in the original graph, consider the following sequence of steps:

R[i1,i2]โ‹…R[i2,i3]โ‹…โ‹ฏโ‹…R[ik,i1]>1lnโก(R[i1,i2])+lnโก(R[i2,i3])+โ‹ฏ+lnโก(R[ik,i1])>0โˆ’lnโก(R[i1,i2])โˆ’lnโก(R[i2,i3])โˆ’โ‹ฏโˆ’lnโก(R[ik,i1])<0. \begin{aligned} R[i_1, i_2] ยท R[i_2, i_3] \cdot \cdots \cdot R[i_k, i_1] & > 1 \\ \ln(R[i_1, i_2]) + \ln(R[i_2, i_3]) + \cdots + \ln(R[i_k, i_1]) & > 0 \\ โˆ’\ln(R[i_1, i_2]) โˆ’ \ln(R[i_2, i_3]) โˆ’ \cdots โˆ’ \ln(R[i_k, i_1]) & < 0. \end{aligned}

b. To do this, we first perform the same modification of all the edge weights as done in part (a) of this problem. Then, we wish to detect the negative weight cycle. To do this, we relax all the edges โˆฃVโˆฃโˆ’1|V| โˆ’ 1 many times, as in BellmanFord algorithm. Then, we record all of the dd values of the vertices. Then, we relax all the edges โˆฃVโˆฃ|V| more times. Then, we check to see which vertices had their dd value decrease since we recorded them. All of these vertices must lie on some (possibly disjoint) set of negative weight cycles. Call SS this set of vertices. To find one of these cycles in particular, we can pick any vertex in SS and greedily keep picking any vertex that it has an edge to that is also in SS. Then, we just keep an eye out for a repeat. This finds us our cycle. We know that we will never get to a dead end in this process because the set SS consists of vertices that are in some union of cycles, and so every vertex has out degree at least 11.