Extra material: Forex Arbitrage
This notebook presents an example of linear optimization on a network model for financial transactions. The goal is to identify whether an arbitrage opportunity exists given a matrix of cross-currency exchange rates. Other treatments of this problem and application are available, including the following links.
Preamble: Install Pyomo and a solver
The following cell sets and verifies a global SOLVER for the notebook. If run on Google Colab, the cell installs Pyomo and the HiGHS solver, while, if run elsewhere, it assumes Pyomo and HiGHS have been previously installed. It then sets to use HiGHS as solver via the appsi module and a test is performed to verify that it is available. The solver interface is stored in a global object SOLVER for later use.
Problem
Exchanging one currency for another is among the most common of all banking transactions. Currencies are normally priced relative to each other.
At this moment of this writing, for example, the Japanese yen (symbol JPY) is priced at 0.00761 relative to the euro (symbol EUR). At this price 100 euros would purchase 100/0.00761 = 13,140.6 yen. Conversely, EUR is priced at 131.585 yen. The 'round-trip' of 100 euros from EUR to JPY and back to EUR results in
The small loss in this round-trip transaction is the fee collected by the brokers and banking system to provide these services.
Needless to say, if a simple round-trip transaction like this reliably produced a net gain then there would many eager traders ready to take advantage of the situation. Trading situations offering a net gain with no risk are called arbitrage, and are the subject of intense interest by traders in the foreign exchange (forex) and crypto-currency markets around the globe.
As one might expect, arbitrage opportunities involving a simple round-trip between a pair of currencies are almost non-existent in real-world markets. When the do appear, they are easily detected and rapid and automated trading quickly exploit the situation. More complex arbitrage opportunities, however, can arise when working with three more currencies and a table of cross-currency exchange rates.
Demonstration of Triangular Arbitrage
Consider the following cross-currency matrix.
| i <-- j | USD | EUR | JPY |
|---|---|---|---|
| USD | 1.0 | 2.0 | 0.01 |
| EUR | 0.5 | 1.0 | 0.0075 |
| JPY | 100.0 | 133.3 | 1.0 |
Entry is the number units of currency received in exchange for one unit of currency . We use the notation
as reminder of what the entries denote. For this data there are no two way arbitrage opportunities. We can check this by explicitly computing all two-way currency exchanges
by computing
This data set shows no net cost and no arbitrage for conversion from one currency to another and back again.
Now consider a currency exchange comprised of three trades that returns back to the same currency.
The net exchange rate can be computed as
By direct calculation we see there is a three-way triangular arbitrage opportunity for this data set that returns a 50% increase in wealth.
Our challenge is create a model that can identify complex arbitrage opportunities that may exist in cross-currency forex markets.
Modeling
The cross-currency table provides exchange rates among currencies. Entry in row , column tells us how many units of currency are received in exchange for one unit of currency . We use the notation to remind ourselves of this relationship.
We start with units of currency , where is the set of all currencies in the data set. We consider a sequence of trades where is the amount of currency on hand after completing trade .
Each trade is executed in two phases. In the first phase an amount of currency is committed for exchange to currency . This allows a trade to include multiple currency transactions. After the commitment the unencumbered balance for currency must satisfy trading constraints. Each trade consists of simultaneous transactions in one or more currencies.
Here a lower bound has been placed to prohibit short-selling of currency . This constraint could be modified if leveraging is allowed on the exchange.
The second phase of the trade is complete when the exchange credits all of the currency accounts according to
We assume all trading fees and costs are represented in the bid/ask spreads represented by
The goal of this calculation is to find a set of transactions to maximize the value of portfolio after a specified number of trades .