Hacker News new | ask | show | jobs
by mrdmnd 3102 days ago
I remember a classic MIT problem set in computer science where we reduced the problem of finding a "profitable arbitrage loop" in a directed graph to a shortest path problem: imagine a graph where nodes are currencies and edges are exchange rates: we're seeking to find some loop of nodes U,V,W,...U such that the cumulative product of the edge weights is greater than unity.

The trick is to transform the graph by taking the negative log of the edge weights, which turns problem of finding a cumulative product > 1 into one of finding a negative sum loop. Then, you can just run the Bellman Ford algorithm and if it detects a negative cost cycle in the transformed graph, this corresponds to a positive arbitrage cycle in the original graph.

I always thought that was a neat application.

4 comments

It's nice to do that to banks that didn't set their trading prices to avoid arbitrage (did it couple of times myself).

For cryptocoins it's nearly impossible. Because in most cases there's no idea when the actual transfer will be executed (if arbitraging between exchanges).

The trick is to have the currencies already there so you dont need to do a transfer (well you will want to do one afterwards to get ready for another round, but it isnt that time sensitive).
That just pushes the problem to the next trade. Even if you diligently keep your accounts funded, you’ll need to rebalance them after most trades (by definition of arbitrage), so your velocity will eventually be limited.

Concretely, imagine if every ten minutes you made an arbitrage buy on GDAX, and sell on BitFinex. As long as GDAX remains the “buy side” of the arbitrage, you will need to keep refilling your fiat funds at GDAX. You could “keep it filled,” but this becomes more unsustainable as you deplete your bankroll. You will eventually need to rebalance which will affect your velocity.

Disclaimer: I am not a financial professional.

Not entirely true. If you wait for the arbitrage opportunity to occur in the reverse direction, you can rebalance. But you take the risk of waiting days/weeks for a reverse dip opportunity.

Source: I tried to make money arbitraging BTC back in 2015. I made a 2x return, entirely because of inflation, realized I didn't understand anything I was doing and pulled my 8k out. If only I had kept it in :)

I would expect that the same exchanges tend to be on the same side of arbitrage spreads, for various reasons that could include lack of liquidity.
If you plot them, you will see the spreads intersect now and then.

However, all the same risks apply e.g. with orders not being processed enough.

it's still a better situation compared to the one posed by the parent. at least now the profits are guaranteed (barring an exchange hack).
You could get completely hammered if one of the exchanges goes down temporarily helfway through your arbitrage
Yep, I've tried to do arbitrage on one exchange during dumps (there's quite a lovely way to realize there will be a massive dump done on the exchange) and most of my trades couldn't even execute because the trading engine can't meet the demand.

When you look at the price history (and open orders history) between some pairs on one exchange you'll find that during these spikes there was no arbitrage being done at all.

One example is seeing the price on ETH-BTC pair being constant despite BTC dropping 10-20%, and then combing back in 5-10 minutes.

I rather suspect if it was possible to arbitrage the crypto´s, then we wouldn´t be seeing these kinds of fluctuations.
While I mostly agree with your take, there is always that joke that reminds me it's not true:

Two economists walk down the road.

E1: look, a 100$ bill over there!

E2: if it were one, somebody would have picked it up already!

E1: nods

The elevated chance of an exchange going down in the middle of a crisis is actually a major source of the risk that one needs to take into account when evaluating the expected profitability of arbitrage strategies.
I know the exact exercise you are talking about and about 4 years ago it inspired me to try arbitrage on bitcoin across the exchanges. My hopes were soon dashed when I found out how slow everything in bitcoin processes.

Although I did recently see a more sophisticated example of arbitrage where you have money on all the exchanges at once and then you don't actually do a transfer, but you long on one and short on the other. However, I don't think it would work w/ bitcoin b/c I don't think shorting is much of a thing yet.

While this is true and is efficient in the computational complexity sense, I’ve found in practice it is easier, faster, and qualitatively better to set the problem up as a simple LP. Qualitatively better in the sense that the LP tells you the potential magnitude of the arbitrage cycle, not just its existence, and faster in the sense of actual computed latency.

While transaction costs are easy to model in LPs, transaction clearing times are much harder. To the point where most opportunities are better described as phantasma.

This is a classic Network Flow optimization problem as well.