Maximize Profit and Minimize Risk with Bitcoin Price Prediction

Maximize Profit and Minimize Risk with Bitcoin Price Prediction
Photo by Towfiqu barbhuiya / Unsplash

Suppose you trained an algorithm which predicts the stock market correct about 70% of all cases. Now you would like to start using your algorithm in real life. Chances are that you don’t get what you expect! On every stock market, you have to pay fees for trading (both for buying and selling stocks). In this article, I will explain how I minimized the risk for my Bitcoin Stock Prediction algorithm mathematically.

Disclaimer: this should not be taken as financial advice. Please do your own research while investing money and do not solely rely on the predicted outcomes.

Give me a Model!

We first need a model! In this model, some characteristics of the stock market are captured. Here, I will make several assumptions and simplifications to the problem:


I assume that a fee is a percentage of the price. On Kraken, there is a fee for a transaction maker of 0.16% and a transaction fee for a transaction taker of 0.26%. This means that the total fee for a transaction is 0.16% + 0.26% = 0.42% (= 0.0042). I made 0.005 of this just for simplification. Also notice that I took the worst-case scenario. In many occasions (for example, if you would trade in large volumes), this fee will be lower. I call the fee amount


. If I would spend an amount


on the stock market, then I am left with

A \times (1 - \beta)

after buying and selling the stocks since I have to pay the fees.


Suppose that the buying fees are 5% and the selling fees are 5%. Then,
\beta = 0.10

(that is, the total transaction fees are 10%). If I would make a transaction and invest €100,- (so


), I have to pay €10,- for fees. After the transaction, I am left with

A \times (1 - \beta) = 100 \times (1-0.10) = 90

, so with €90,- (since I paid €10,- for the fees).

Price jumps

Suppose that


is the average jump between prices and for which the prices are separated one hour from each other. The stock market behaves like a random walk. By that, we know that the gaps get bigger over time. If you look from day-to-day, the gaps are bigger than the hour-to-hour gaps. By the assumption that the stock market behaves like a random walk, we actually know the following relation:

\gamma_1 = \gamma_0 \cdot \sqrt{T}

. Please, stay with me! I will explain it. Suppose


is our hour-to-hour average gap between prices and we want to know what the average day-to-day gap is. We can then simply take




hours fit in a day). Suppose the hour-to-hour gap is 25% = 0.25 (that is, a price increases or decreases on average by 25%). Then,

\gamma_1 = \gamma_0 \sqrt{24} \approx 1.22

. So, day-to-day prices differ approximately 122%. It makes sense, the day-to-day prices should be larger, since day-to-day gaps consists of many hour-to-hour gaps. For Kraken, I took hour-to-hour gaps and I approximated


by looking at actual gaps and estimated

\gamma = 0.002

(0.2%). Thus, that means that day-to-day gaps are approximately 0.9% (as an exercise: try to compute this yourself).


Suppose we have a classifier which can predict a stock price in the future by some accuracy


. As an example, assume that our classifier can predict a future stock price with 70% accuracy (that is, 7 out of the 10 prices are predicted correctly). As a simple model, the classifier could predict whether a stock goes up or down. Then, we can compare how well the classifier performed on real data. Assume that


is the accuracy of this model.


Suppose we have


amount of money. We start with


. Also, assume that we trade for


timesteps. We are interested in the following question: will


be larger than


? In words: will we end up with more money than we started with?

X_T > X_0

? We will try to answer this question with our model!

The actual Model

In summary,


are the fees on the trades,


are the average gaps between two consecutive stock prices. And


is the accuracy of our classifier.


is our capital at time




is the horizon or endpoint. With this, we could come up with the following model:

$latex X_{t+1} = \begin{cases}
X_t (1 – \beta) (1+ \gamma) & \mbox{with probability } \alpha\\
X_t (1 – \beta)(1 – \gamma) & \mbox{with probability } 1 – \alpha

So, what does this mean?


means the following timestep.


is the current timestep. Our goal is to compute the future amount at time


, so our goal is to compute


. At each timestep, one of the following scenarios can happen: either the classifier predicted correctly (this happens with probability


), or the classifier did not predict correctly (with probability

1 - \alpha

). For both cases, we have to pay the fees (this is the factor

1 - \beta

). If we predicted the stock movement correctly, we gain

1 + \gamma

since we moved up with the stock. Otherwise, have lost the gap (

1 - \gamma




for given




Suppose we know the average gap size


and the fees


, can we compute the minimum accuracy we need for the classifier in order to make profit? Yes, we can! I will leave out the mathematical details, but it boils down that the minimum accuracy equals the following:

\alpha = \log_{\frac{1 + \gamma}{1 - \gamma}}(\frac{1}{(1-\beta)(1 - \gamma)})


Model applied on Kraken

I applied my model on Kraken. Here,


is fixed since we know the transaction fees. Now we can plot




and this yields the following result:

Gamma versus Alpha.

Gamma versus Alpha

In this graph, you can clearly see that

\alpha > 0.5

. This is obvious, since if the classifier classifies incorrect in most of the cases, then it would be impossible to make profit. For relatively small gaps (

\gamma < 0.01

), the classifier accuracy needs to be extremely large! There is even a certain


for which no classifier could make profit. We can zoom in in this area and obtain the following graph:

Gamma versus alpha, zoomed in version.

Gamma versus alpha, zoomed in version

Okay, so we need at least price gaps of about 0.005 (0.5%) in order to make any profit at all. Since we know that the hour-to-hour price gaps of Kraken are 0.002, we know that we cannot make any profit on Kraken with an hour-to-hour classifier. However, we also know that the day-to-day gaps approximately have


. For this


, we need a classifier with a prediction accuracy of approximately 75% accuracy, which is doable. In this way, we can make profit. If we take a classifier with 90% accuracy, we take 365 timesteps (


), and we take the fees of Kraken (


) and the approximated day-to-day gaps of the Bitcoin stockprice (

\gamma = 0.009

) and if we invest €1000,- in the machine at timestep




), we get (using


simulations) that the average


equals €2205,-! So we could double our initial capital if we have a good classification algorithm.


In the real world, the stock market parameters make it hard for classification algorithms to make profit. A classifier should have an accuracy of nearly 80% in most cases in order to be valuable. If you have any questions or comments, feel free to post them below!