Anticipating cryptocurrency prices using machine learning

Machine learning and AI-assisted trading have attracted growing interest for the past few years. Here, we use this approach to test the hypothesis that the inefficiency of the cryptocurrency market can be exploited to generate abnormal profits. We analyse daily data for $1,681$ cryptocurrencies for the period between Nov. 2015 and Apr. 2018. We show that simple trading strategies assisted by state-of-the-art machine learning algorithms outperform standard benchmarks. Our results show that nontrivial, but ultimately simple, algorithmic mechanisms can help anticipate the short-term evolution of the cryptocurrency market.


Introduction
The popularity of cryptocurrencies has skyrocketed in 2017 due to several consecutive months of superexponential growth of their market capitalisation [1], which peaked at more than $800 billions in Jan.
2018. Today, there are more than 1, 500 actively traded cryptocurrencies. Between 2.9 and 5.8 millions of private as well as institutional investors are in the different transaction networks, according to a recent survey [2], and access to the market has become easier over time. Major cryptocurrencies can be bought using fiat currency in a number of online exchanges (e.g., Binance [3], Upbit [4], Kraken [5], etc) and then be used in their turn to buy less popular cryptocurrencies. The volume of daily exchanges is currently superior to $15 billions. Since 2017, over 170 hedge funds specialised in cryptocurrencies have emerged and bitcoin futures have been launched to address institutional demand for trading and hedging Bitcoin [6].
The market is diverse and provides investors with many different products. Just to mention a few, Bitcoin was expressly designed as a medium of exchange [7,8]; Dash offers improved services on top of Bitcoin's feature set, including instantaneous and private transactions [9]; Ethereum is a public, blockchain-based distributed computing platform featuring smart contract (scripting) functionality, and Ether is a cryptocurrency whose blockchain is generated by the Ethereum platform [10]; Ripple is a real-time gross settlement system (RTGS), currency exchange and remittance network Ripple [11], and IOTA is focused on providing secure communications and payments between agents on the Internet of The emergence of a self-organised market of virtual currencies and/or assets whose value is generated primarily by social consensus [13] has naturally attracted interest from the scientific community [8,[14][15][16][17][18][19][20][21][22][23][24][25][26][27][28][29][30].
Recent results have shown that the long-term properties of the cryptocurrency marked have remained stable between 2013 and 2017 and are compatible with a scenario in which investors simply sample the market and allocate their money according to the cryptocurrency's market shares [1]. While this is true on average, various studies have focused on the analysis and forecasting of price fluctuations, using mostly traditional approaches for financial markets analysis and prediction [31][32][33][34][35].
The success of machine learning techniques for stock markets prediction [36][37][38][39][40][41][42], suggests that these methods could be effective also in predicting cryptocurrencies prices. However, the application of machine learning algorithms to the cryptocurrency market has been limited so far to the analysis of Bitcoin prices, using random forests [43], Bayesian neural network [44], long short-term memory neural network [45] and other algorithms [32,46]. These studies were able to anticipate, to different degrees, the price fluctuations of Bitcoin, and revealed that best results were achieved by neural network based algorithms.
Deep reinforcement learning was showed to beat the uniform buy and hold strategy [47] in predicting the prices of 12 cryptocurrencies over one year period [48].
Other attempts to use machine learning to predict the prices of cryptocurrencies other than Bitcoin come from non-academic sources [49][50][51][52][53][54]. Most of these analyses focused on a limited number of currencies and did not provide benchmark comparisons for their results.
Here, we test the performance of three models in predicting daily cryptocurrency price for 1,681 currencies. Two of the models are based on gradient boosting decision trees [55] and one is based on long short-term memory (LSTM) recurrent neural networks [56]. In all cases, we build investment portfolios based on the predictions and we compare their performance in terms of return on investment. We find that all of the three models perform better than a baseline 'simple moving average' model [57][58][59][60] where a currency's price is predicted as the average price across the preceding days, and that the method based on long short-term memory recurrent neural networks systematically yields the best return on investment.
The article is structured as follows: In section Materials and Methods we describe the data (see Data description and pre-processing), the metrics characterizing cryptocurrencies that are used along the paper (see Metrics), the forecasting algorithms (see Forecasting algorithms), and the evaluation metrics (see Evaluation). In section Results, we present and compare the results obtained with the three forecasting algorithms and the baseline method. In section Conclusion, we conclude and discuss results.

Materials and Methods
Data description and pre-processing Cryptocurrency data was extracted from the website Coin Market Cap [61], collecting daily data from 300 exchange markets platforms starting in the period between November 11, 2015 and April 24, 2018.
The dataset contains the daily price in U.S. dollars, the market capitalisation and the trading volume of 1, 681 cryptocurrencies, where the market capitalization is the product between price and circulating supply, and the volume is the number of coins exchanged in a day. The daily price is computed as the volume weighted average of all prices reported at each market. Fig. 1 shows the number of currencies with trading volume larger than V min over time, for different values of V min . In the following sections, we consider that only currencies with daily trading volume higher than 10 5 USD can be traded at any given day.
The website lists cryptocurrencies traded on public exchange markets that have existed for more than 30 days and for which an API as well as a public URL showing the total mined supply are available.
Information on the market capitalization of cryptocurrencies that are not traded in the 6 hours preceding the weekly release of data is not included on the website. Cryptocurrencies inactive for 7 days are not included in the list released. These measures imply that some cryptocurrencies can disappear from the list to reappear later on. In this case, we consider the price to be the same as before disappearing.
However, this choice does not affect results since only in 28 cases the currency has volume higher than 10 5 USD right before disappearing (note that there are 124,328 entries in the dataset with volume larger than 10 5 USD).

Metrics
Cryptocurrencies are characterised over time by several metrics, namely • Price, The exchange rate, determined by supply and demand dynamics.
• Market capitalization, The product of the circulating supply and the price.
• Market share, The market capitalization of a currency normalized by the total market capitalization.
• Rank, The rank of currency based on its market capitalization.
• Volume, Coins traded in the last 24 hours.
• Age, Lifetime of the currency in days.
The profitability of a currency c over time can be quantified through the return on investment (ROI), measuring the return of an investment made at day t i relative to the cost [62]. The index i rolls across days and it is included between 0 and 844, with t 0 = January 1, 2016, and t 844 = April 24, 2018. Since we are interested in the short-term performance, we consider the return on investment after 1 day defined as In Fig. 2, we show the evolution of the ROI over time for Bitcoin (orange line) and on average for currencies whose volume is larger than V min = 10 5 USD at t i − 1 (blue line). In both case, the average return on investment over the period considered is larger than 0, reflecting the overall growth of the market.

Forecasting algorithms
We test and compare three supervised methods for short-term price forecasting. The first two methods rely on XGboost [63], an open-source scalable machine learning system for tree boosting used in a number of winning Kaggle solutions (17/29 in 2015) [64]. The third method is based on the long shortterm memory (LSTM) algorithm for recurrent neural networks [56] that have demonstrated to achieve state-of-the-art results in time-series forecasting [65]. Method 1: The first method considers one single regression model to describe the change in price of all currencies (see Fig. 3). The model is an ensemble of regression trees built by the XGboost algorithm.
The features of the model are characteristics of a currency between time t j − w and t j − 1 and the target is the ROI of the currency at time t j , where w is a parameter to be determined. The characteristics considered for each currency are: price, market capitalization, market share, rank, volume and ROI (see equation Eq. (1)). The features for the regression are built across the window between t j − w and t j − 1 included (see Fig. 3). Specifically, we consider the average, the standard deviation, the median, the last value and the trend (e.g. the difference between last and first value) of the properties listed above. In the training phase, we include all currencies with volume larger than 10 5 USD, and t j between t i − W training and t i . In general, larger training windows do not necessarily lead to better results (see results section), because the market evolves across time. In the prediction phase, we test on the set of existing currencies at day t i . This procedure is repeated for values of t i included between January 1, 2016 and April 24,

2018.
Method 2: Also the second method relies on XGboost, but now the algorithm is used to build a different regression model for each currency c i (see Fig. 4). The features of the model for currency c i are    Baseline method: As baseline method, we adopt the simple moving average strategy (SMA) widely tested and used as a null model in stock market prediction [57][58][59][60]. It estimates the price of a currency at day t i as the average price of the same currency between t i − w and t i − 1 included.

Evaluation
We compare the performance of various investment portfolios built based on the algorithms predictions.
The investment portfolio is built at time t i − 1 by equally splitting an initial capital among the top n currencies predicted with positive return. Hence, the total return at time t i is: The portfolios performance is evaluated by computing the Sharpe ratio and the geometric mean return.
The Sharpe ratio is defined as: where R is the average return on investment obtained between times 0 and t i , and s R , the corresponding standard deviation.
The geometric mean return is defined as: where t i corresponds to the total number of days considered. The cumulative return obtained at t i after investing and selling on the following day for the whole period is defined as The number of currencies n to include in a portfolio is chosen at t i by optimising either the geometric mean G(t i − 1) (geometric mean optimisation) or the Sharpe ratio S(t i − 1) (Sharpe ratio optimisation) over the possible choices of n. The same approach is used to choose the parameters of Method 1 (w and W training ), Method 2 (w and W training ), and the baseline method (w).

Results
We predict the price of the currencies at day t i , for all t i included between Jan, 1st 2016 and Apr 24th, 2018. The analysis considers all currencies whose age is larger than 50 days since their first appearance and whose volume is larger than $100000. To discount for the effect of the overall market movement (i.e., market growth, for most of the considered period), we consider cryptocurrencies prices expressed in Bitcoin. This implies that Bitcoin is excluded from our analysis.

Parameter setting
First, we choose the parameters for each method. Parameters include the number of currencies n to include the portfolio as well as the parameters specific to each method. In most cases, at each day t i we choose the parameters that maximise either the geometric mean G(t i − 1) (geometric mean optimisation) or the Sharpe ratio S(t i − 1) (Sharpe ratio optimisation) computed between times 0 and t i .
Baseline strategy: We test the performance of the baseline strategy for choices of window w ≥ 2 (the minimal requirement for the ROI to be different from 0) and w < 30. We find that the value of w mazimising the geometric mean return (see Appendix Fig. A1-A) and the Sharpe Ratio (see Appendix  Fig. A9). This is expected, since the Bitcoin price has increased during the period considered. While some of these figures appear exaggerated, it is worth noticing that (i) we run a theoretical exercise assuming that the availability of Bitcoin is not limited and (ii) under this assumption the upper bound to our strategy, corresponding to investing every day in the most performing currency results in a total cumulative return of 6 · 10 123 BTC (see Appendix Fig. A6).
We consider also the more realistic scenario of investors paying a transaction fee when selling and buying currencies (see Appendix Section A3). In most exchange markets, the fee is typically included between 0.1% and 0.5% of the traded amount [66]. For fees up to 0.2%, all the investment methods presented above lead, on average, to positive returns over the entire period (see Table A1). The best performing method, Method 3, achieves positive gains also when fees up to 1% are considered (see Table A1). The cumulative return in Fig. 5 is obtained by investing between January 1st, 2016 and April 24th, 2018. We investigate the overall performance of the various methods by looking at the geometric mean return obtained in different periods (see Fig. 6). Results presented in Fig. 6 are obtained under Sharpe ratio optimisation for the baseline (Fig. 6-A), Method 1 ( Fig. 6-B), Method 2 ( Fig. 6-C), and Method 3 ( Fig. 6-D). Note that, while in this case the investment can start after January 1st, 2016, we optimised the parameters by using data from that date on in all cases. Results are considerably better than those achieved using geometric mean return optimisation (see Appendix Fig. A10). Finally, we observe that better performance is achieved when the algorithms consider prices in Bitcoin rather than USD (see Table A2).

Feature importance
In Fig. 7

Conclusion
We tested the performance of three forecasting models on daily cryptocurrency prices for 1, 681 currencies.
Two of them (Method 1 and Method 2) were based on gradient boosting decision trees and one is based on long short-term memory recurrent neural networks (Method 3). In Method 1, the same model was used to predict the return on investment of all currencies; in Method 2, we built a different model for each currency, that uses information on the behaviour of the whole market to make a prediction on that The three methods performed better than the baseline strategy when the investment strategy was ran over the whole period considered. The optimisation of parameters based on the Sharpe ratio achieved larger returns. Methods based on gradient boosting decision trees (Method 1 and 2) worked best when predictions were based on short-term windows of 5/10 days, suggesting they exploit well mostly shortterm dependencies. Instead, LSTM recurrent neural networks worked best when predictions were based on ∼ 50 days of data, since they are able to capture also long-term dependencies and are very stable against price volatility. They allowed to make profit also if transaction fees up to 1% are considered.
Methods based on gradient boosting decision trees allow to better interpret results. We found that the prices and the returns of a currency in the last few days preceding the prediction were leading factors to anticipate its behaviour. Among the two methods based on random forests, the one considering a different model for each currency performed best (Method 2). Finally, it is worth noting that the three methods proposed perform better when predictions are based on prices in Bitcoin rather than prices in USD. This suggests that forecasting simultaneously the overall cryptocurrency market trend and the developments of individual currencies is more challenging than forecasting the latter alone.
It is important to stress that our study has limitations. First, we did not attempt to exploit the existence of different prices on different exchanges, the consideration of which could open the way to significantly higher returns on investment. Second, we ignored intra-day price fluctuations and considered an average daily price. Finally, and crucially, we run a theoretical test in which the available supply of Bitcoin is unlimited and none of our trades influence the market. Notwithstanding these simplifying assumptions, the methods we presented were systematically and consistently able to identify outperforming currencies. Extending the current analysis by considering these and other elements of the market is a direction for future work.
A different yet promising approach to the study cryptocurrencies consists in quantifying the impact of public opinion, as measured through social media traces, on the market behaviour, in the same spirit in which this was done for the stock market [67]. While it was shown that social media traces can be also effective predictors of Bitcoin [68][69][70][71][72][73][74] and other currencies [75] price fluctuations, our knowledge of their effects on the whole cryptocurrency market remain limited and is an interesting direction for future work.

A1 Parameter optimisation
In Fig. A1, we show the optimisation of the parameters w (A,C) and n (B,D) for the baseline strategy. In          A2 Return under full knowledge of the market evolution.
In Fig. A6, we show the cumulative return obtained by investing every day in the top currency, supposing one knows the prices of currencies on the following day. A3 Return obtained paying transaction fees.
In this section, we present the results obtained including transaction fees between 0.1% and 1% [66]. In general, one can not trade a given currency with any given other. Hence, we consider that each day we trade twice: We sell altcoins to buy Bitcoin, and we buy new altcoins using Bitcoin. The mean return obtained between Jan. 2016 and Apr. 2018 is larger than 1 for all methods, for fees up to 0.2% (see Table A1). In this period, Method 3 achieves positive returns for fees up to 1%. The returns obtained with a 0.1% (see Fig. A7) and 0.2% (see Fig. A8

A4 Results in USD
In this section, we show results obtained considering prices in USD. The price of Bitcoin in USD has considerably increased in the period considered. Hence, gains in USD (Fig. A9) are higher than those in Bitcoin (Fig. 5). Note that, in Fig. A9, we have made predictions and computed portfolios considering prices in Bitcoin. Then, gains have been converted to USD (without transaction fees). In Table A2, we show instead the gains obtained running predictions considering directly all prices in USD. We find that, in most cases, better results are obtained from prices in BTC. Geometric mean in USD (from BTC prices) Geometric mean in USD (from USD prices) Baseline  Table A2: Geometric mean returns in USD. Results are obtained for the various methods by running the algorithms considering prices in BTC (left column) and USD (right column).

A5 Geometric mean optimisation
In Fig. A10, we show the geometric mean return obtained by between two arbitrary points in time under geometric mean return optimisation for the baseline (Fig. A10-