Giter Club home page Giter Club logo

forex-exploit's Introduction

Forex Exploit in C - a graph problem

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.

Example

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.

Complexities

  • Time: O(N^3)
  • Space: O(N^2)

Implemented Concepts

  • Pointers
  • Matrices
  • Solving a graph problem
  • multi file project

Running

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
_______________________________

Credits

  • For Reading the csv file I've used this piece of code by @Tal.

TODOs

  • Make the csv filepath an input parameter for the main programm.

forex-exploit's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.