Convex optimization for fun and profit.

Overview

CFMM Optimal Routing

This repository contains the code needed to generate the figures used in the paper Optimal Routing for Constant Function Market Makers.

Requirements

The requirements for running these examples are:

  • NumPy
  • Matplotlib
  • Cvxpy (see here for installation)

In order to generate the figures as done in the paper you will also need a working TeX distribution.

How to run

All examples are self-contained and can be run directly, e.g.:

python arbitrage.py

The figures were generated by running

python two-asset.py

but note that this requires a working TeX distribution. (This can be avoided by commenting out any call to latexify in two-asset.py which requires ps as a backend for plotting.)

You might also like...
A small fun project using python OpenCV, mediapipe, and pydirectinput
A small fun project using python OpenCV, mediapipe, and pydirectinput

Here I tried a small fun project using python OpenCV, mediapipe, and pydirectinput. Here we can control moves car game when yellow color come to right box (press key 'd') left box (press key 'a') left hand when thumb finger open (press key 'w') right hand when thumb finger open (press key 's') This can be improved later by: Improving press left and right to make them More realistic. Fixing some bugs in hand tracking.

Learning based AI for playing multi-round Koi-Koi hanafuda card games. Have fun.
Learning based AI for playing multi-round Koi-Koi hanafuda card games. Have fun.

Koi-Koi AI Learning based AI for playing multi-round Koi-Koi hanafuda card games. Platform Python PyTorch PySimpleGUI (for the interface playing vs AI

TensorFlow Metal Backend on Apple Silicon Experiments (just for fun)
TensorFlow Metal Backend on Apple Silicon Experiments (just for fun)

tf-metal-experiments TensorFlow Metal Backend on Apple Silicon Experiments (just for fun) Setup This is tested on M1 series Apple Silicon SOC only. Te

One-line your code easily but still with the fun of doing so!

One-liner-iser One-line your code easily but still with the fun of doing so! Have YOU ever wanted to write one-line Python code, but don't have the sa

A numpy-based implementation of RANSAC for fundamental matrix and homography estimation. The degeneracy updating and local optimization components are included and optional.
A numpy-based implementation of RANSAC for fundamental matrix and homography estimation. The degeneracy updating and local optimization components are included and optional.

Description A numpy-based implementation of RANSAC for fundamental matrix and homography estimation. The degeneracy updating and local optimization co

Fast and scalable uncertainty quantification for neural molecular property prediction, accelerated optimization, and guided virtual screening.
Fast and scalable uncertainty quantification for neural molecular property prediction, accelerated optimization, and guided virtual screening.

Evidential Deep Learning for Guided Molecular Property Prediction and Discovery Ava Soleimany*, Alexander Amini*, Samuel Goldman*, Daniela Rus, Sangee

An optimization and data collection toolbox for convenient and fast prototyping of computationally expensive models.
An optimization and data collection toolbox for convenient and fast prototyping of computationally expensive models.

An optimization and data collection toolbox for convenient and fast prototyping of computationally expensive models. Hyperactive: is very easy to lear

A Free and Open Source Python Library for Multiobjective Optimization

Platypus What is Platypus? Platypus is a framework for evolutionary computing in Python with a focus on multiobjective evolutionary algorithms (MOEAs)

Hyperparameter Optimization for TensorFlow, Keras and PyTorch
Hyperparameter Optimization for TensorFlow, Keras and PyTorch

Hyperparameter Optimization for Keras Talos • Key Features • Examples • Install • Support • Docs • Issues • License • Download Talos radically changes

Comments
  • Reserves are not pair specific

    Reserves are not pair specific

    It seems that the reserves here have been handled as though there is a quantity for each token, but in fact on CFMMs there is of course a pair of reserve values for each trading pair. E.g. reserves for pair ABC-DEF on exchange i could be R_ABC = 5 and R_DEF = 10 but then for ABC-GHI could be R_ABC = 2 and R_GHI = 7 (still on exchange i). This is how we get the prices for each pair and is necessary for the correct application of this to real live CFMM markets.

    (To me it looks like R_i should already be a 2 dimensional object - for each pair of tokens there should be a length 2 tuple of reserve values, considering that the exchange index 'i' ranges over more than one exchange should then make it 3 dimensional. Then we should be translating local PAIR indices (rather than token indices) to global and vice versa with matrices analogous to the A matrices).

    Another way of stating it would be to say that the trading function constraints must apply pair-wise, e.g. in the case of Uniswap that changes in values of the reserves for a specific pool / trading pair must preserve the product invariant of the reserves for that specific trading pair.

    Thoughts?

    opened by Granger7 3
  • A question about routes order...

    A question about routes order...

    Hello,

    Thank you for the great paper, the thoughtful explanation in it and the accompanied code. It really helps someone like me.

    I have one or two question please :

    1. If I understood very well your formulation about including transaction cost in the objective function and without thinking about the fact that the problem is solvable or not, the way you included the transaction cost is by adding a constant transaction cost for each CFMM, meaning if we do one trade in that CFMM we'll have to pay that transaction cost, while in reality the transaction cost is dependent not on if we did a trade or not on a CFMM but on how many trades we did on that CFMM and your formula omit this detail. Am I right ?

    Your response for these questions will be so much helpful.

    opened by IceCr34m 1
  • Solver fails with large range of values (real world reserve sizes)

    Solver fails with large range of values (real world reserve sizes)

    When attempting to apply the code to real reserve sizes it has become apparent that the distribution of these values presents a significant problem for the underlying numerical solver, namely that the values tend to deviate by several orders of magnitude and thus cannot be normalised by an overall factor to produce a set of O(1) values. This is causing the solver to fail, although it works very well for the example numbers in the code files.

    Has the code been used / tested with real world reserve values over a sizable selection of markets or is it considered more of a theoretical / reference implementation?

    Is there a recommended normalisation to be used when using real reserve values that may deviate by many orders of magnitude?

    Many thanks

    opened by Granger7 0
Owner
Guillermo Angeris
BS/MS/PhD in Electrical Engineering interested in optimization, physics, and puppies; I also sometimes pretend to do research and things.
Guillermo Angeris
Neural Fixed-Point Acceleration for Convex Optimization

Licensing The majority of neural-scs is licensed under the CC BY-NC 4.0 License, however, portions of the project are available under separate license

Facebook Research 27 Oct 6, 2022
Code in PyTorch for the convex combination linear IAF and the Householder Flow, J.M. Tomczak & M. Welling

VAE with Volume-Preserving Flows This is a PyTorch implementation of two volume-preserving flows as described in the following papers: Tomczak, J. M.,

Jakub Tomczak 87 Dec 26, 2022
Riemannian Convex Potential Maps

Modeling distributions on Riemannian manifolds is a crucial component in understanding non-Euclidean data that arises, e.g., in physics and geology. The budding approaches in this space are limited by representational and computational tradeoffs. We propose and study a class of flows that uses convex potentials from Riemannian optimal transport. These are universal and can model distributions on any compact Riemannian manifold without requiring domain knowledge of the manifold to be integrated into the architecture. We demonstrate that these flows can model standard distributions on spheres, and tori, on synthetic and geological data.

Facebook Research 61 Nov 28, 2022
ESGD-M - A stochastic non-convex second order optimizer, suitable for training deep learning models, for PyTorch

ESGD-M - A stochastic non-convex second order optimizer, suitable for training deep learning models, for PyTorch

Katherine Crowson 53 Dec 29, 2022
Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing, Ant Colony Optimization Algorithm,Immune Algorithm, Artificial Fish Swarm Algorithm, Differential Evolution and TSP(Traveling salesman)

scikit-opt Swarm Intelligence in Python (Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing, Ant Colony Algorithm, Immune Algorithm,A

郭飞 3.7k Jan 3, 2023
library for nonlinear optimization, wrapping many algorithms for global and local, constrained or unconstrained, optimization

NLopt is a library for nonlinear local and global optimization, for functions with and without gradient information. It is designed as a simple, unifi

Steven G. Johnson 1.4k Dec 25, 2022
Racing line optimization algorithm in python that uses Particle Swarm Optimization.

Racing Line Optimization with PSO This repository contains a racing line optimization algorithm in python that uses Particle Swarm Optimization. Requi

Parsa Dahesh 6 Dec 14, 2022
Fast, flexible and fun neural networks.

Brainstorm Discontinuation Notice Brainstorm is no longer being maintained, so we recommend using one of the many other,available frameworks, such as

IDSIA 1.3k Nov 21, 2022
piSTAR Lab is a modular platform built to make AI experimentation accessible and fun. (pistar.ai)

piSTAR Lab WARNING: This is an early release. Overview piSTAR Lab is a modular deep reinforcement learning platform built to make AI experimentation a

piSTAR Lab 0 Aug 1, 2022
Computer vision - fun segmentation experience using classic and deep tools :)

Computer_Vision_Segmentation_Fun Segmentation of Images and Video. Tools: pytorch Models: Classic model - GrabCut Deep model - Deeplabv3_resnet101 Flo

Mor Ventura 1 Dec 18, 2021