Git Product home page Git Product logo

arbitrager's Introduction

How it Works

The basic premise of arbitrage is to buy something for one price and instantly sell it for another. In our case, we want to find a currency with a price discrepancy, e.g. one where converting between multiple currencies will eventually lead you to make more money in your starting currency than you began with. If we assume we have $1, our goal is to convert our money until we end up with x<$1.

We turn each coin into a node and each conversion into an arc. This setup creates a directed graph where the weights of each edge is the conversion rate. Utilizing a neat high school math trick, we can log() each conversion rate which then makes addition of logged conversions really multiplication of unlogged. Utilizing a neat little middle school trick, we can apply a negative sign to each number to make it negative.

Now, all we need to do is apply the Bellman-Ford algorithm to detect a negative loop, which indicates an aribitrage opportunity. Why? Because a negative loop indicates you can cycle along this path infinitely, at increasing negative cost. When we unlog our numbers and reverse the negative sign, this translates to a loop that can start with $1 and infinitely increase it as it follows this loop.

Once the Bellman-Ford detects a negative loop, we trace back the loop in the negative_trace function and spit out the answer.

arbitrager's People

Contributors

bancaofficial avatar billzheng2 avatar chrisbanca avatar melodytata avatar seantata avatar techbanca avatar

Watchers

 avatar  avatar

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.