Would it not be wonderful if, by looking at the market, we could infer the probability of the next order ? That is the goal of this article. This is our roadmap:
The first step is to find what criterion to optimise for. We can start with a simple example. You have $1. You can bet any fraction of your money for a limited number of rounds.
What is the optimal bet? Let us formalise the problem:
Where is the step, and and are the number of wins and losses at that step. Indeed, every win multiplies your wealth by , and every loss, by . Per the law of large numbers, and . So:
Here is what looks like depending on the fraction :
We see that the optimal bet does not depend on the number of rounds . Since is monotonically increasing, finding the maximum of is equivalent to finding the maximum of : .
That is exactly the expectation of the logarithm of our wealth! That is the Kelly criterion: we should maximise the expected logarithm of our wealth.
Otherwise, if we maximised the expected wealth, we would bet everything, and with every round, the probability of bankruptcy would tend to 1.
Computing optimal betsNow that we have a value to maximise, imagine we had the probability of wins and losses for any investment in the market (would it not be wonderful?). Could we find the optimal bets? For example:
Let us compute the Kelly fractions:
Running this code will download ~30MB of compressed dependencies.
Per this code, we should bet 20%
on the first coin and 0%
on the second (the right value for the 60% coin, if you look at the graph above). You can fiddle with the values of to see what happens.
Even better now: can we find the probabilities, knowing the optimal fractions? Let us remember that should maximise the expectation, so its derivative should be zero:
It works! In other words, when we know the fractions of the optimal bets, we can infer the initial probabilities of winning.
The order bookOnce a price integrates an information, it is too late to gain profit from it. In other words, the market reflects past information. But how can we predict the future?
Let us examine how a market determines a price. Imagine that currently, 1 BTC = 1 USD, and you believe that the BTC will fall, then rise. You can set an order to buy BTC. It requires a unit price (in USD) and a quantity (how much BTC). The goal is to predict the probability of the next spot order.
So, you want to predict that is not too high, nor too low. And since you may consider many possible prices, you will spread your money across them. That is what traders do: predict the probability for all possible prices, then set orders. The record of such orders is called the order book, and it looks like this:
This is the current real-time order book for BTC/USD, with data kindly provided by Binance.
That is exactly what we are looking for: each one of these bars is a bet about future orders, and by applying our strategy from above, we may find the probability for any price to be the next order.
The CoinbotThe last step, developing the bot who will automatically invest optimally, is left to you! However, keep in mind that this article is merely a mathematical musing, and not financial advice.