Technology and Investment, 2012, 3, 181-186 http://dx.doi.org/10.4236/ti.2012.33025 Published Online August 2012 (http://www.SciRP.org/journal/ti) Genetic Algorithm for Arbitrage with More than Three Currencies Adrián Fernández-Pérez1, Fernando Fernández-Rodríguez1, Simón Sosvilla-Rivero2 1Department of Quantitative Methods, University of Las Palmas de Gran Canaria, Las Palmas de Gran Canaria, Spain 2Department of Quantitative Methods, Complutense University of Madrid, Madrid, Spain Email: adrian.fernandez102@alu.ulpgc.es, ffernandez@dmc.ulpgc.es, sosvilla@ccee.ucm.es Received June 19, 2012; revised July 20, 2012; accepted July 27, 2012 ABSTRACT We develop a genetic algorithm that is able to find the optimal sequence of exchange rates that maximizes arbitrage profits with more than three currencies, being both the triangular arbitrage and the direct exchange rate two special cases of the proposed algorithm. Applying the algorithm to the most traded currencies, we find average profits ranking from 4.5083% to 0.3162% for changing 1 USD for EUR with respect to the direct exchange rate, for different transac- tion costs, during the period October 2000-April 2012. Our results also suggest that the arbitrage profits increased just after the subprime crisis in summer of 2007 and that they are higher when the market is less liquid. Keywords: Arbitrage; Foreign Exchange Market; Genetic Algorithm 1. Introduction Triangular arbitrage is a widely used tool in foreign ex- change (FX) markets. It is based on exploiting an arbitrage opportunity resulting from a pricing discrepancy among three currencies. FX traders with many years of experi- ence are able to find triangular arbitrage opportunities at a glance, by comparing the prices of three currencies simultaneously. However, it is very unlikely that, at first glance, they could be able to find arbitrage opportunities when they come into play more than three currencies. Moreover, even if they are able to find triangular arbi- trage opportunities at any given time, the profits from triangular arbitrage based on only three currencies could be lower than those obtained from arbitrating with more than three currencies. We develop a fast genetic algorithm (GA) that is able to find the optimal sequence of exchange rates that maxi- mizes arbitrage profits with more than three currencies, be- ing both the triangular arbitrage and the direct exchange rate two special cases of the proposed algorithm. 2. A GA for Arbitrage with More than Three Currencies GAs are a class of adaptive search and optimization technique based on the principles of natural evolution, initially developed in Reference [1]. In our strategy, we follow the methodology developed in Reference [2] for automatic selection. The GA starts with a large number of randomly gener- ated chromosomes designed to encode potential solutions to the problem. Suppose that we begin by considering a sequence of exchange rates taken at random with a maximum of 5 currencies{x1, x2, x3, x4, x5}, encoding the sequence by means of vectors formed by natural numbers between 0 and 6, where 0 means no currency and where 1 = Australian Dollar (AUD), 2 = Euro (EUR), 3 = Swiss Franc (CHF), 4 = Japanese Yen (JPY), 5= United States Dollar (USD), and 6 = Pound Sterling (GBP). Since the EUR/USD is the most traded rate, we seek for a sequence that allows us to exchange 1 USD for EUR. For instance, vector {x1, x2, x3, x4, x5} = {3, 6, 2, 5, 4} means the fol- lowing sequence of currencies {CHF, GBP, EUR, USD, JPY}, or the following sequence of exchange rates (as- suming that we exchange USD to EUR): {CHF/USD, GBP/CHF, EUR/GBP, USD/EUR, JPY/USD, EUR/JPY}. Next, the following objective function evaluates each potential solution, assigning each chromosome a fitness value, ranking chromosomes from best to worst:     Max max ,0ix f d  d where f is the final amount of EUR that we obtain using the sequence suggested by chromosome {x1, x2, x3, x4, x5} and d is the amount of EUR that we obtain using the di- rect EUR/USD exchange rate. To keep our analysis real- istic, every time we use an exchange rate, we apply a transaction cost k·0.05%, k = {1, 5, 10, 15}1, where the 1The 0.05% transaction costs include bid-ask spread, commissions and fixed costs of using the trading platform. Copyright © 2012 SciRes. TI A. FERNÁNDEZ-PÉREZ ET AL. 182 parameter k represents a penalty used to correct for pos- sible data errors that could lead us to misleading profits2. In order to carry out our arbitrage algorithm, we pro- ceed as follows. We obtain an initial set of N sequences randomly selected currencies. Then, we select 50%·N of chromosomes better fitted as for the objective function. These chromosomes, the parents of the next generation, undergo a recombination process to produce descendants. Offspring are created combining information from two parent chromosomes to form a child that has the potential to outperform its parents. For instance, if we have the parent chromosomes {x1, x2, x3, x4, x5} = {3, 6, 2, 5, 4} and {x1, x2, x3, x4, x5} = {1, 3, 6, 5, 3}, for recombination we first randomly choose a cut off point within each chromosome (let us say the second position) and then the information is exchanged as outlined below:  1,3, 6,5,3 corresponding with the sequence (3, 6, 6, 5, 3)  3,6, 2,5,4 corresponding with the sequence (1, 3, 2, 5, 4) Finally, in order to avoid reaching local optima instead of global optima, all the chromosomes, except those best fitted as for the objective function, are candidates to be transformed by a mutation operator, which is essentially a mechanism by which information encoded along the chromosome is randomly altered. For example, if we select at random the penultimate element of the chromo- some {3, 6, 2, 5, 4}, a mutation would be changing cur- rency 5 by a random integer value between 0 and 6, as we proceeded when creating the initial population, namely: {3, 6, 2, 5, 4} → {3, 6, 2, 1, 4} The purpose of mutation is to recover lost genetic in- formation that may not be present in the initial popula- tion and is not obtainable by recombination alone. In our case, the mutation rate is very small (5%). After recombination and mutation, we obtained a sec- ond generation of chromosomes to which we apply again the same steps as before, the process ending when a convergence criterion is reached: either when the best of chromosomes remains stable during a given number of successive generations or when we reach a predeter- mined number of generations, this number being fixed beforehand. To shorten the computation time and to reduce the number of currencies in the final optimal sequence (with a consequent reduction in transaction costs), we make some adjustments. First, given that our initial currency is 5 and the final currency is 2, we sequence, we remove of the sequence all the currencies located from this position, e.g. the chromosome {3, 6, 2, 1, 4} becomes {3, 6, 0, 0, 0}. Similarly, if the initial currency is located within the sequence before the final currency, we would remove from the sequence all the currencies located before the initial currency, e.g. the chromosome {3, 6, 5, 4, 1} is transformed into {0, 0, 0, 4, 1}. Finally, if the sequence is such that the same currency is selected in two or more positions, we remove all repetitions, keeping only the first one, e.g. the chromosome {3, 6, 1, 3, 4} converts into {3, 6, 1, 0, 4}. 3. Empirical Results We have applied the GA arbitrage for changing 1 USD for EUR to daily data of closing cross rates from 01 Oc- tober 2000 to 30 April 2012 taken from Thomson Reuters Datastream. We have employed the cross FX for the following most traded currencies in the market: US dollar, Australian dollar, Canadian dollar, Euro, Hong Kong dollar, Indian rupee, Japanese yen, Mexican peso, New Zeland dollar, Norwegian krone, Singapore dollar, Swedish krona, Swiss franc and Streling pound Table 1 reports the average GA arbitrage profit with respect to direct exchange rate and the average number of exchange rates, as well as their standard deviation and median, for the entire sample and for two subsamples (before and after the subprime crisis in August 2007). 2The parameter k can also be conceived as a mean to account for the fact that the bid-ask spread could be different for any two currency pairs and that it could also change with the time under different market conditions. As can be seen, GA always renders more EUR from 1 USD than those from the direct exchange rate, diminish- ing with higher values of k, suggesting the existence of arbitrage opportunities in the major FX even when we allow for high transaction costs. These profits with re- spect to the direct exchange rate rank from 4.5083% for k = 1, to 0.3162% for k = 15. Besides, the number of ex- change rates in the optimal sequence is higher than 2 for values of k up to 10, indicating that the main opportuni- ties of arbitrage using more than three currencies. Interestingly, results in Table 1 also suggest both the GA relative arbitrage profit and the number of exchange rates used in the GA increase after the subprime crisis in August 2007. Moreover, there exists a positive and sig- nificant correlation among them (with an average corre- lation of 78.68% for k = {1, 5, 10, 15} and p-values of 0.000); it confirms our main result that the arbitrage profit is greater when applied to more than three curren- cies. This result could be an indication that foreign ex- change markets were very tight at that time leading to up- set exchange rates. Table 2 shows the Pearson correlations between monthly GA arbitrage profits, as well as the monthly average num- ber of exchange rates, and both the liquidity indicators proposed by Reference [3] and the Chicago Board Options Exchange Market Volatility Index (VIX) and EUROVIX as measures of implicit volatility. As can be seen, in line with Reference [4-6], we detect higher arbitrage profits Copyright © 2012 SciRes. TI A. FERNÁNDEZ-PÉREZ ET AL. Copyright © 2012 SciRes. TI 183 Table 1. GA arbitrage profits and number of exchange rates in each sequence. All Sample Profits of the Arbitrage with More than 3 Currencies with Respect to Direct Exchange Rate (%) Number of Exchange Rates in the Sequence k Mean STD Median Mean STD Median 1 4.5083 0.9672 4.3895 10.2924 0.4221 10.2609 5 2.7602 0.8559 2.6483 6.5316 0.8187 6.4762 10 1.1929 0.7333 1.0305 3.3231 1.1785 3.1818 15 0.3162 0.3589 0.2237 1.1830 0.8679 1.0000 Before Subprime Crisis Profits of the Arbitrage with More than 3 Currencies with Respect to Direct Exchange Rate (%) Number of Exchange Rates in the Sequence k Mean STD Median Mean STD Median 1 4.4504 0.6113 4.4561 10.2882 0.4157 10.2609 5 2.7607 0.5010 2.7940 6.3805 0.6519 6.2381 10 1.1943 0.4342 1.1831 3.3785 0.7944 3.4091 15 0.2775 0.1902 0.2337 1.1647 0.6178 1.1739 After Subprime Crisis Profits of the Arbitrage with More than 3 Currencies with Respect to Direct Exchange Rate (%) Number of Exchange Rates in the Sequence k Mean STD Median Mean STD Median 1 4.5941 1.3434 4.1043 10.2986 0.4388 10.2554 5 2.7596 1.2191 2.2712 6.7555 0.9902 6.5119 10 1.1909 1.0402 0.7591 3.2409 1.604 2.8416 15 0.3736 0.5157 0.1619 1.2101 1.1474 0.7267 Table 2. Correlation between GA arbitrage profits and number of exchange rates in each sequence with liquidity and volatility indicators. All Sample Profits of the Arbitrage with More than 3 Currencies (%) k Levels of Aggregate Liquidity Innovation in Aggregate Liquidity VIX EUROVIX –0.2618 –0.1867 0.4700 0.6121 1 (0.0017) (0.0194) (0.0000) (0.0000) –0.2866 –0.2059 0.4462 0.5990 5 (0.0007) (0.0111) (0.0000) (0.0000) –0.2582 –0.2164 0.3917 0.6180 10 (0.0020) (0.0081) (0.0000) (0.0000) –0.2448 –0.1902 0.3164 0.5364 15 (0.0032) (0.0176) (0.0000) (0.0000) Number of Exchange Rates in the Sequence k Levels of Aggregate Liquidity Innovation in Aggregate Liquidity VIX EUROVIX –0.0194 0.0555 0.0703 0.0399 1 (0.4156) (0.2710) (0.0002) (0.1254) –0.3381 –0.1897 0.2657 0.2744 5 (0.0007) (0.0111) (0.0000) (0.0000) –0.2706 –0.2070 0.2637 0.4315 10 (0.0020) (0.0081) (0.0000) (0.0000) –0.2298 –0.1624 0.2495 0.4518 15 (0.0053) (0.0363) (0.0000) (0.0000) Pre-subprime Crisis Profits of the Arbitrage with More than 3 Currencies (%) k Levels of Aggregate Liquidity Innovation in Aggregate Liquidity VIX EUROVIX A. FERNÁNDEZ-PÉREZ ET AL. 184 Continued –0.1744 –0.0304 0.3019 - 1 (0.0574) (0.3926) (0.0000) - –0.2203 –0.0539 0.2911 - 5 (0.0227) (0.3141) (0.0000) - –0.1803 –0.0382 0.2247 - 10 (0.0514) (0.3660) (0.0000) - –0.0954 0.0030 0.1353 - 15 (0.1954) (0.4892) (0.0000) - Number of Exchange Rates in the Sequence k Levels of Aggregate Liquidity Innovation in Aggregate Liquidity VIX EUROVIX 0.0350 0.1086 0.0628 - 1 (0.3766) (0.1641) (0.0046) - –0.1892 –0.0487 0.1817 - 5 (0.0227) (0.3141) (0.0000) - –0.1739 –0.0295 0.1582 - 10 (0.0514) (0.3660) (0.0000) - –0.1119 –0.0149 0.1497 - 15 (0.1569) (0.4469) (0.0000) - Post-subprime Crisis Profits of the Arbitrage with More than 3 Currencies (%) k Levels of Aggregate Liquidity Innovation in Aggregate Liquidity VIX EUROVIX –0.2988 –0.2773 0.6639 0.6121 1 (0.0306) (0.0416) (0.0000) (0.0000) –0.3241 –0.2989 0.6583 0.5990 5 (0.0206) (0.0305) (0.0000) (0.0000) –0.3021 –0.3275 0.6369 0.6180 10 (0.0291) (0.0196) (0.0000) (0.0000) –0.3144 –0.2880 0.5440 0.5364 15 (0.0241) (0.0358) (0.0000) (0.0000) Number of Exchange Rates in the Sequence k Levels of Aggregate Liquidity Innovation in Aggregate Liquidity VIX EUROVIX –0.0567 0.0135 0.0730 0.0399 1 (0.3641) (0.4671) (0.0154) (0.1254) –0.4508 –0.2937 0.3384 0.2744 5 (0.0206) (0.0305) (0.0000) (0.0000) –0.3366 –0.3395 0.4511 0.4315 10 (0.0291) (0.0196) (0.0000) (0.0000) –0.3049 –0.2661 0.4577 0.4518 15 (0.0279) (0.0485) (0.0000) (0.0000) when markets are less liquid, and vice versa. We also detect a positive association between GA excess profit and market perceived volatility. Finally, Figure 1 plots the monthly evolution of aver- age GA arbitrage profits and mean number of exchange rates with more than three currencies for the entire sam- ple and for k = 15. Therefore, in view of the encouraging results of the present study, some optimism about the benefits from the use of a genetic algorithm to exhaustively examine all possible permutations to find the optimal sequence that achieves maximum arbitrage profit seems justified, spe- cially given the fact determining the optimal exchange sequence takes minimal computation time (about 10 seconds on a laptop with Intel Core i3). 4. Concluding Remarks We have presented empirical evidence on the existence of arbitrage opportunities in foreign exchange markets us- ing more than three currencies using a genetic algorithm Copyright © 2012 SciRes. TI A. FERNÁNDEZ-PÉREZ ET AL. 185 Figure 1. Monthly evolution of average GA arbitrage profits and mean number of exchange rates with more than three currencies (October 2000 to April 2012) for k = 15. that is able to quickly find the optimal sequence of ex- change rates that maximizes the arbitrage profit with respect to that from a simple direct exchange rate. After correcting the database to avoid disturbances from errors in the data and taking into account several levels of transaction costs, we found arbitrage opportuni- ties with more than three currencies during the 01 Octo- ber 2000-30 April 2012 period for the EUR/USD case using AUD, CAD, HKD, INR, JPY, MXN, NZD, NOK, SGD, SEK, CHF and GBP as intermediate currencies and transaction costs of k·0.05%, k = {1, 5, 10, 15}. These results would be indicating the existence of market anomalies that, drawing on recent work on the theory of investment under uncertainty, could be interpreted as the tendency for traders to wait for sufficiently large arbi- trage opportunities to open up before entering the market, Reference [7]. The authors are aware of the difficulty of finding in- formation on all the exchange rates quoted in the real market in the same source, since exchange rates are traded on an OTC market and the available information is the daily average rate of market operations. Even though, we believe that the algorithm presented here is a useful tool for market operators seeking to maximize arbitrage profits in FX markets (where the number of global currencies is very high, and thus the proposed algorithm is more suitable and powerful) taking advan- tages of mismatches between quoted exchange rates at any given time, since our algorithm encompasses as par- ticular cases both the triangular arbitrage and the direct exchange rate. Therefore, in the worst scenario where there are no arbitrage opportunities, our algorithm will render as optimal solution the direct exchange rate and, in the best scenario where there are arbitrage opportuni- ties, our algorithm will select as the optimal solution a sequence of exchange rates that maximizes the arbitrage profits with three or more currencies. 5. Acknowledgements The authors wish to thank two anonymous referee for helpful comments and Analistas Financieros Internacion- ales for kindly providing us with the data set. The authors gratefully acknowledge financial support from the Spanish Ministry of Science and Innovation (projects ECO2010- 21318 and ECO2011-23189). REFERENCES [1] J. Holland, “Adaptation in Natural and Artificial Sys- tems,” MIT Press, Cambridge, 1975. [2] E. Acosta-González and F. Fernández-Rodríguez, “Model Selection via Genetic Algorithms Illustrated with Cross- Country Growth Data,” Empirical Economics, Vol. 33, No. 2, 2007, pp. 313-337. doi:10.1007/s00181-006-0104-3 [3] L. Pástor and R. F. Stambaugh, “Liquidity Risk and Ex- pected Stock Returns,” Journal of Political Economy, Vol. 111, No. 3, 2003, pp. 642-685. doi:10.1086/374184 [4] S. J. Grossman and J. E. Stiglitz, “Information and Com- petitive Price Systems,” The American Economic Review, Vol. 66, No. 2, 1976, pp. 246-253. [5] S. J. Grossman and J. E. Stiglitz, “On the Impossibility of Informationally Efficient Markets,” The American Eco- nomic Review, Vol. 70, No. 3, 1980, pp. 393-408. [6] B. R. Marshall, S. Treepongkaruna and M. Young, “Ex- Copyright © 2012 SciRes. TI http://dx.doi.org/10.1007/s00181-006-0104-3 http://dx.doi.org/10.1086/374184 A. FERNÁNDEZ-PÉREZ ET AL. 186 ploitable Arbitrage Opportunities Exist in the Foreign Exchange Market,” Discussion Paper, Massey University, Palmerston North, 2007. [7] A. Carruth, A. Dickerson and A. Henley, “What Do We Know about Investment under Uncertainty?” Journal of Economic Surveys, Vol. 14, No. 2, 2000, pp. 119-154. doi:10.1111/1467-6419.00107 Copyright © 2012 SciRes. TI http://dx.doi.org/10.1111/1467-6419.00107