Skip to content

Instantly share code, notes, and snippets.

@nth-commit
Last active June 18, 2021 04:01
Show Gist options
  • Save nth-commit/1f4dc34cd5c88bbb818cfe0dd8ddcd6a to your computer and use it in GitHub Desktop.
Save nth-commit/1f4dc34cd5c88bbb818cfe0dd8ddcd6a to your computer and use it in GitHub Desktop.
The effect of tournament-style asset selection on hold-time, for a long-term triangle arbitrage trading algorithm

The effect of tournament-style asset selection on hold-time, for a long-term triangle arbitrage trading algorithm

Introduction

A long-term triangle arbitrage strategy is one that takes advantages of differences between markets over an extended period of time, as opposed to difference that exist between markets in fractions of a second.

Example

Let's say we are tracking three assets, and those assets each have markets between them.

At a point in time, the exchange rates between those assets might be:

Market Rate
CurrencyA/CurrencyB 0.5
CurrencyA/CurrencyC 0.25
CurrencyB/CurrencyC 0.5

Given we are holding 100 units of CurrencyA, and we trade them all to CurrencyB, we will end up with 50 units of CurrencyB.

= CurrencyA(100) => CurrencyA(100 * 0.5)
= CurrencyA(100) => CurrencyB(50)

At this point in time, the trade can be revalued with respect to another asset, CurrencyC. If the delta with respect to CurrencyC is non-zero, that means there is an immediate arbitrage opportunity between the three markets. However, this is not often the case.

= CurrencyC(100 * 0.25) => CurrencyC(50 * 0.5)
= CurrencyC(25) => CurrencyC(25)
∴ Δ CurrencyC = 25 - 25 = 0

As time progresses, we can continually revalue this trade with respect to the other assets. For example, at some point in time, the trade might be revalued as such:

= CurrencyC(100 * 0.225) => CurrencyC(50 * 0.475)
= CurrencyC(22.5) => CurrencyC(26.25)
∴ Δ CurrencyC = 26.25 - 23.75 = 2.5

From the perspective of CurrencyC, we have made a gain of 2.5. The algorithm sees the advantageous trade, and will trade the held asset of CurrencyB for CurrencyC.

It's not immediately obvious how this is beneficial - we haven't realised any gain in any of the currencies we held prior to this trade. However, if markets continue to fluctuate over time, at some point in the future, we will likely end up with CurrencyA or CurrencyB again, and when we do, we will be holding more than we did prior.

This continues to profit, based on the assumption that, over time, assets will have gains and losses against each other. These gains and losses need only be relative - it is just as possible to exploit differences between assets that have a starkly different absolute value, as it is with assets of similar values.

If all the trades we are making are advantageous, we want to be making as many of those trades as possible. It's worth noting that the algorithm will immediately trade on a gain based on some given threshold, e.g. 5%. Because trades are happening in real-time, then all advantageous trades will occur around that threshold. This makes "number of advantageous trades" our ultimate metric, and a great proxy for profit.

The bootstrapping problem

When we either initialize the algorithm for the first time, or we give it more of our base asset to operate with, there exists a problem.

Which asset do we place our initial investment in?

The algorithm described above is not applicable, as we do not have a previous trade to compare it to. A naïve (but valid) approach would be to pick one of the tracked assets at random, trade the base asset to it, and then use that as our initial trade to compare future potential trades to.

However, when picking an asset at random we risk:

  • Picking a weakly performing asset that is stagnant or decreasing - "bought low, stays low" or "bought low, whilst collapsing"
  • Picking a strongly performing asset that is about dip - "bought high, whilst overvalued".

Remember, we want to maximize the number of advantageous trades we make, to maximize profits.

Market analysis with tournament-style asset selection

When we are bootstrapping, it feels like there is some market analysis that we could do to improve the initial performance of the algorithm.

One non-naïve, but simple, approach might be to pit each asset against each other in a round-robin tournament, comparing their relative change in strength over a period of time.

For example,

Over a 24-hour period, the ETHBTC price might have gone from 0.025464 to 0.028065. That's a win for ETH over BTC. Over that same period of time, ETHUSDT might have gone from 736.42 to 946.38, whilst DOGEUSDT might have gone from 0.0046716 to 0.0106441. That's a win for DOGE over ETH (it increased more relative to USDT).

If we pit enough assets against each other, we can build a rank of all assets relative to each other over the period, like so:

Currency Wins Losses Draws
DOGE 19 0 0
VET 18 1 0
ETH 17 2 0
BTC 16 3 0
OMG 15 4 0
ETC 14 5 0
ONT 13 6 0
ADA 12 7 0
NEO 11 8 0
TRX 10 9 0
QTUM 9 10 0
BAT 8 11 0
EOS 7 12 0
XLM 6 13 0
IOTA 5 14 0
ICX 4 15 0
USDT 3 16 0
DASH 2 17 0
XMR 1 18 0
ATOM 0 19 0

The question is, can we use this rank to inform our initial currency selection in cryptocurrency markets?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment