This project is about finding arbitrage opportunities in foreign exchange rates by finding negative weight cycles by implemeting the Bellmann Ford Alogrithm. Exchange rates are read from a csv file.
Would this work in practice? Most likely not as exchange rates are changed constantly to prevent this and I would be too slow filling trades.
Lets use the following currencies and fictional exchange rates.
CHF | EUR | USD | GBP | YEN | CAD |
---|---|---|---|---|---|
1 | 0.23 | 0.25 | 16.43 | 18.21 | 4.94 |
4.34 | 1 | 1.11 | 71.40 | 79.09 | 21.44 |
3.93 | 0.90 | 1 | 64.52 | 71.48 | 19.37 |
0.061 | 0.014 | 0.015 | 1 | 1.11 | 0.30 |
0.055 | 0.013 | 0.014 | 0.90 | 1 | 0.27 |
0.20 | 0.047 | 0.052 | 3.33 | 3.69 | 1 |
By doing the following chain of currency changes we can find arbitrage.
GBP -> YEN -> CHF -> GBP
1(GBP) * 1.1 = 1.1(YEN)
1.1(YEN) * 0.05 = 0.06105(CHF)
0.06105(CHF) * 16.43 = 1.0030515(GBP)
Arbitrage of risk free: 0.003.- (GBP)
Now Repeat with 1.003(GBP)
Doing this from hand is tricky and takes long. This program is doing exactly that.
- Time: O(N^3)
- Space: O(N^2)
- Pointers
- Matrices
- Solving a graph problem
- multi file project
Run make to start the program.
$ make
Output of the example data provided.
Arbitrage Opportunity detected:
GBP -> YEN -> CHF -> GBP
_______________________________
Arbitrage Opportunity detected:
USD -> CAD -> USD -> GBP -> YEN -> EUR -> CHF
_______________________________
Arbitrage Opportunity detected:
USD -> CAD -> USD -> CHF
_______________________________
- For Reading the csv file I've used this piece of code by @Tal.
- Make the csv filepath an input parameter for the main programm.