david234
This is from my arbitrage project. I need to find the best probability of where the client can buy and where he can sell to get maximum profits. For ex take a look at the below list
[
%{id: BTC, name: "Binance", price: 100},
%{id: BTC, name: "VCC Exchange", price: 102},
%{id: BTC, name: "CoinBene", price: 104},
%{id: BTC, name: "BitZ", price: 140},
%{id: BTC, name: "Huobi Global", price: 150},
%{id: BTC, name: "ZG.com", price: 170},
]
Maximum Profit to Buy and Sell BTC:
1. BUY from ZG.com and SELL in Binance Profit 70
2. BUY from ZG.com and SELL in VCC Exchange Profit 68
3. BUY from ZG.com and SELL in CoinBene Profit 66
4. BUY from Huobi Global and SELL in Binance Profit 50
5. BUY from Huobi Global and SELL in VCC Exchange Profit 48
6. BUY from Huobi Global and SELL in CoinBene Profit 46
....
....
..
I have to find the best profits and list them.
So to achieve this what I have done is I have sorted the map based on Price ASC.
Then do I need to loop through each exchange 5 times in order to find this?
Or is there any better method of achieving this? Your help will be greatly appreciated.
Any skeleton code if I can get that will be really helpful.
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kokolegorille
oh, this look like a good fit to try Genetic Algorithms.
eksperimental
You can find the minimum and maximum values? You may want to look into the Enum.{min/max/min_by/max_by} funcitions
amnu3387
Your example is giving the wrong values though, ZG would be the worse to buy since the price is highest there?
Because you need them all, ordered and not only the lowest and highest I would imagine a custom reduce would be the best option for doing it on almost a single pass.
I’ve added also other entries with the same prices to the sample list.
And a module for doing this:
This should give you some ideas for how to tackle it. The
build_outreductions could probably usereduce_whileon the two outer reduces but it would clog up the logic and it doesn’t seem like it would be a significant improvement. You could also change it to keep adding entries to the output even if the profit was 0 or negative.al2o3cr
The core idea is to find each possible (buy, sell) pair, evaluate the profit, and then sort the results.
Here’s a way to do it in SQL (based on my solution to this year’s Advent of Code day 1):
This gives the result:
My column labels don’t quite agree with yours, but you get the idea.
Note that this simple approach doesn’t scale particularly well: it evaluates every pair of buyers and sellers, so if you have
Nmarkets it takesN * (N-1)total calculations. Not bad when N=6, but not good when N=10000