In a previous blog post, I had introduced a way of labeling time series data as bullish or bearish. For a time series of prices $P=\{p_1,\dots,p_n\}$ and corresponding times $T=\{t_1,\dots,t_n\}$, we introduce for a subset $\bar{T}=\{t_{X+1},\dots, t_{n-Y}\}$ a mapping $C: \bar{T}\to\{\text{bullish},\text{bearish}\}$ such that

for $i=X+1,\dots,n-Y$, where $X,Y\in \mathbb{Z}_{>0}$ are the preceding and following smoothing factors, respectively.

Denoting by $I_i$ the set of all information recorded before $t_i$, let $\mathcal{I}=\{I_1, \dots, I_n\}$ be the set of classifier inputs. A trained classifier $C’: \mathcal{I} \to \{\text{bullish},\text{bearish}\}$ maps every set in the input set to a market sentiment.

The goal of every algorithm proposed for this classification task is to minimize $|\varepsilon|$ where $\varepsilon= \{t \mid t\in T; X,Y \in \mathbb{Z}_{>0}; C \neq C’\}$.

The simple trading bot $B$ on the other hand is defined as a finite state machine executing the orders

for predicted classes $c’_i$ at $t_i$. How the buying and selling operations affect the bot’s balances is described in more detail in the previous blog post.

A Grid Search on $X$ and $Y$ with Linear SVMs

For training, we used 3.5 years of hourly Bitcoin prices given below.

Model: Linear Support Vector Machine.

Features: Given $X$ and $Y$, for every point in the price time series, take preceding $\max(X, 5)$ points and standardize them.

Targets: Classes calculated by $C$.

The dataset is split 75-25% (not shuffled) for training/testing. Below are the accuracies obtained for each $(X,Y) \in [1,100]\times [1,100]$.

Accuracies obtained through the grid search. Maximum accuracy was given by $X=100$ and $Y=1$ at 93.6%.

Monte-Carlo Simulation with Resulting Accuracies

Before looking into how the trading bot performs with the trained classifier, let’s first simulate a trading bot that gets the sentiment right $accuracy\%$ of the time. We do this by implementing a Poisson process and running a Monte Carlo simulation to get the expected value of accuracies, as described in the previous blog post.

Monte Carlo simulation of the returns (ran 20 times and averaged) if the classifier went wrong according to a Poisson distribution.

The returns range between over 1 billion times to actual loss below 1x. The results look optimistic: more than half of the values are greater than 1000x. Is it too good to be true?

Actual Returns with the Trained Classifiers

Kind of… The maximum return we get is 152x:

Actual returns obtained when bought and sold according to the input from trained classifiers.

There seems to be a region $25<X<45$ where trading yields 80x return on average. The highest returns are obtained for $1<Y<25$ and $80<Y<100$, but there is not enough evidence to draw conclusions of a pattern. To do that, the bot should be trained and run on more price data.

The reason for the drastic difference from the simulation is that classifiers don’t err through a Poisson process: there is a dependence between consecutive events. Errors are clumped together, meaning that an error happening increases the likelihood of it happening in the next hour.

Another interesting result was that trading with the actual classifier yielded much higher returns than the simulation for certain values, e.g. towards top-left.

Being optimistic, we could make the assumption that the cryptocurrency market would perform similarly in the next 3-4 years. Deploying the bot for the apparently optimal range, ~80x in 3.5 years equals an average return of ~3.5x/year.

Or we could just buy and hold Bitcoin, because minimum and maximum prices for the data above were \$200 versus \$19847, and selling at the right time would have nevertheless yielded ~100x returns. The problem is, of course, knowing when to buy and sell. The value of such a bot arguably comes from the fact that it saves an investor from the hassle and opportunity cost of keeping track of the market.

A proposed heuristic: Choose a volatile and promising asset with more than 10,000 hours of history. Train over past data, run, and forget about it for a couple of years. Hopefully, it will have generated enough returns to compensate running costs.

Summary

The classifier and trading bot given in the previous blog post were formalized. A grid search was performed over smoothing factors with linear SVMs. The returns for resulting accuracies were simulated with the assumption of a Poisson distribution. The actual returns were given and compared with the simulation.