Abstract
Few assets in financial history have been as notoriously volatile ascryptocurrencies. While the long term outlook for this asset class remainsunclear, we are successful in making short term price predictions for severalmajor crypto assets. Using historical data from July 2015 to November 2019, wedevelop a large number of technical indicators to capture patterns in thecryptocurrency market. We then test various classification methods to forecastshort-term future price movements based on these indicators. On both PPV andNPV metrics, our classifiers do well in identifying up and down market movesover the next 1 hour. Beyond evaluating classification accuracy, we alsodevelop a strategy for translating 1-hour-ahead class predictions into tradingdecisions, along with a backtester that simulates trading in a realisticenvironment. We find that support vector machines yield the most profitabletrading strategies, which outperform the market on average for Bitcoin,Ethereum and Litecoin over the past 22 months, since January 2018.
Quick Read (beta)
Cryptocurrency Price Prediction and Trading Strategies Using Support Vector Machines
Abstract
Few assets in financial history have been as notoriously volatile as cryptocurrencies. While the long term outlook for this asset class remains unclear, we are successful in making short term price predictions for several major crypto assets. Using historical data from July 2015 to November 2019, we develop a large number of technical indicators to capture patterns in the cryptocurrency market. We then test various classification methods to forecast short-term future price movements based on these indicators. On both PPV and NPV metrics, our classifiers do well in identifying up and down market moves over the next 1 hour. Beyond evaluating classification accuracy, we also develop a strategy for translating 1-hour-ahead class predictions into trading decisions, along with a backtester that simulates trading in a realistic environment. We find that support vector machines yield the most profitable trading strategies, which outperform the market on average for Bitcoin, Ethereum and Litecoin over the past 22 months, since January 2018.
Cryptocurrency Price Prediction and Trading Strategies Using Support Vector Machines
David Zhao Department of Statistics and Data Science Carnegie Mellon University Pittsburgh, PA 15213 [email protected] Alessandro Rinaldo Department of Statistics and Data Science Carnegie Mellon University Pittsburgh, PA 15213 [email protected] Christopher Brookins Valiendero Digital Assets, LP Pittsburgh, PA 15213 [email protected]
noticebox[b]Preprint. Under review.\[email protected]
1 Introduction
The price of Bitcoin has swung wildly over the past several years, drawing interest from both economists trying to fundamentally understand the phenomenon Ciaian et al. (2014) Mitchnick and Athey (2018) and investors trying to simply predict price swings in order to earn profits Barnwal et al. (2019) Jiang and Liang (2016) Kakushadze (2018). This paper falls into the latter camp. We abstract away the economic and political contexts in which cryptocurrencies exist, focusing solely on the problem of future price prediction given past trading data. Even without considering first principles, it is a daunting task to build an explicit model that accounts for the many possible sources of variation for a poorly understood asset like Bitcoin. Such a model is likely to be overly complex and not useful for prediction. Instead, in this paper we opt for a black-box approach that simply targets prediction accuracy and backtest profit in a time-varying setting.
1.1 What is Bitcoin?
Bitcoin is a peer-to-peer payment system introduced as open source software in January 2009 by a computer programmer using the pseudonym Satoshi Nakamoto Nakamoto (2008). Bitcoin utilizes cryptographic principles in transaction verification, privacy, and issuance. Key features of the Bitcoin system are having no central point of trust or failure (decentralization), not being confined to any local jurisdiction or fiat currency (global reach), a fixed money supply (only 21 million $BTC will ever be issued), divisibility and fungibility, and lower transaction costs than traditional alternatives.
Bitcoin has become a worldwide phenomenon and has experienced incredible growth, leaping from a market capitalization of essentially zero to over $114 billion (at time of writing) in less than 10 years. Coupled with this parabolic growth has been Bitcoin’s detachment from macroeconomic features that have been widely tracked for traditional financial asset pricing. Table 1 shows that Bitcoin has very little correlation with major traditional financial assets Klein et al. (2018).
Asset | Correlation with Bitcoin |
---|---|
Gold | 0.0459 |
Silver | 0.0071 |
WTI (Crude Oil) | 0.0158 |
S&P 500 | 0.0491 |
MSCI World | 0.0457 |
MSCI EM50 | 0.0042 |
The nascency of this market, its noise and extreme volatility, decorrelation with existing assets, rapidly shifting sentiment, lack of established fundamental economic valuation, and even suspected price manipulation Gandal et al. (2018) make Bitcoin one of the hardest prediction problems to solve. Investors with diverse strategies can be found across the spectrum. Some are purely fundamental investors in the venture capital style, focusing on the technological implications of the blockchain. (The blockchain is an immutable public ledger that records all transactions for a given cryptocurrency. We describe blockchain data in more detail in Section 2.2.) Some are applying high frequency trading strategies that are widely utilized in traditional markets. Some are mining sentiment data from news and social network platforms to predict market cycles.
Our approach is simple yet effective at beating the market over an almost 2-year period for Bitcoin, as well as “altcoins” Ethereum Wood (2014) and Litecoin Lee (2011), which are among the most widely used cryptocurrencies with the highest capitalizations, next to Bitcoin. In Section 2, we describe the datasets we work with and features we generate. In Section 3, we discuss our methodology for generating price predictions and translating them into trading decisions. In Section 4, we present our results on classification accuracy and backtested profit of our strategies.
2 Data and Features
We scrape publicly available historical price and volume data from Coinbase (https://coinbase.com/), which is the world’s largest Bitcoin (BTC) broker, as well as a platform for trading numerous other cryptocurrencies such as Ethereum (ETH) and Litecoin (LTC). We also scrape on-chain data, which describes the blockchain i.e. the underlying cryptographic network for crypto assets, via Blocktap (https://www.blocktap.io/). From this data, we develop a large number of technical indicators that serve as input features for our classification algorithms.
2.1 Coinbase data
Coinbase provides open, high, low, close, and volume data (OHLCV) at 1 hour intervals for the currency pairs BTCUSD, ETHUSD, and LTCUSD. open and close refer to the asset price at the start and end of the interval, respectively. high is the highest price the asset attains within the interval, while low is the lowest price within the interval. volume is the total volume, in units of cryptocurrency, of trades made on the Coinbase exchange within the interval. Historical data for BTCUSD is available at 1 minute intervals since July 2015. ETHUSD is available at 1 minute intervals since Aug 2016, and LTCUSD is available at 1 minute intervals since Sep 2016.
Figures 1 and 2 show that the prices and traded volumes of these cryptocurrencies have fluctuated dramatically over the past several years. Moreover, the cross-asset time series correlations are all high, and price and volume tend to be highly correlated as well.
We form various technical features based on historical prices and volumes. In Appendix A, we describe a few illustrative examples, to give context for the kinds of features one might derive from historical market data. The basic idea is we attempt to capture the “direction” prices have been moving in the recent past. We implicitly assume that recent price patterns do in fact influence future prices, and that our features capture relevant properties of recent price evolutions.
2.2 On-chain data
Blocktap is a data platform that provides on-chain data, which refers to all data for a digital asset that is natively stored on that asset’s public blockchain. Blockchain data differs by asset, because each asset has its own unique use case or terminology. Thus, blockchain metrics may differ in title and significance for price prediction, asset to asset. Some examples of on-chain data terminology include miners revenue, mining rate, gas, active addresses, native coin emission rate, transaction count, transaction volume, block size, and more. Furthermore, each metric represents some fundamental economic component of the asset’s network value, i.e. supply or demand. For example, active addresses generally denote a demand side feature while native coin emission rate is supply side.
The largest, free data repositories of such information can be found at coinmetrics.io and blocktap.io, whereas real-time transaction tracking and metric graphics can be found at blockchain.com (Bitcoin blockchain) and etherscan.io (Ethereum blockchain). These information sources provide a host of metrics ranging from user adoption rate to investor purchases to recent transactions. This type of open source and real-time insight into a financial economy and its player’s movements is the first of its kind. Furthermore, it is hypothesized that certain on-chain data metrics, such as stock-to-flow (supply of BTC vs. how much new BTC coming out), influence the underlying price of digital assets like Bitcoin. As the asset class matures, we expect greater utilization of on-chain data into predictive models as we have explored in this paper.
3 Methodology
First, we define price prediction as a classification problem and propose classifiers to solve it, using various features we derive from market and on-chain data, as described in Section 2. Beyond generating price predictions, we develop a framework for backtesting how well our strategy would have performed, in a quasi-realistic setting, over the period of available data.
3.1 Problem Formulation
Our response variable is the 1-hour-ahead percentage change in log price:
$${r}_{t+1}=\frac{\mathrm{log}{P}_{t+1}-\mathrm{log}{P}_{t}}{\mathrm{log}{P}_{t}}$$ |
Taking the logarithm removes the unit root present in currency prices Pan et al. (1997). (We see in Figure 4 that the series of log returns is whitened.) First, we discretize the response, turning this regression problem into a classification problem. We define 3 classes:
${c}_{1}$: “up”, ${r}_{t}\ge 0.5\%$; ${c}_{2}$: “down”, meaning ${r}_{t}\le 0.5\%$; ${c}_{3}$: “same”, otherwise
Figure 3 shows the distribution of 1-hour log-returns. Two vertical lines at -0.005 and 0.005 indicate the thresholds for class membership. We believe this threshold of 50 basis points is a reasonable, conservative choice, given the cost of transactions on Coinbase (see 3.4.2). It would of course not be practically useful to predict price moves too small to cover the transaction costs of trading.
Since our goal is prediction, not inference, we incorporate historical information directly into predictive features, instead of explicitly fitting a time series model. Moreover, Figure 4 shows the autocorrelations and partial autocorrelations of 1-hour log returns are all close to zero.
3.2 Classification Methods
Explicitly specifying a high-dimensional parametric model is not only prohibitively complex, but prediction intervals would also tend to be wide and unusable, given the inherent noisiness of the data generating process. Further, any such parametric model would require many assumptions (e.g. stationarity) that we have no reason to believe are true. All things considered, a black-box approach seems appropriate. We try several multiclass classification methods, including support vector machines (SVM), random forest, and XGBoost. We train these classifiers to predict ${r}_{t+1}$ given all the relevant features from Coinbase and Blocktap at time $t$. Since our dataset is sometimes very imbalanced (vast majority of returns in a 1-hour period fall into a single class, usually ${c}_{3}$), we weight classes inversely by their frequency in the dataset. We find that SVM with a squared hinge loss is our best performing classifier. See Appendix B for a detailed explanation of SVM.
We must also decide how much historical data to use to train our classifiers. Including too much history runs the risk of training on irrelevant information, as the present regime may differ completely from the past. Including too little history runs the risk of underfitting the classifiers due to inadequate data. We decide to use a rolling window of 9 months, which we believe is a sensible balance between training on enough data while avoiding unhelpful data from the distant past. We also find empirically that using a 9 month window performs well. Every month, we retrain the classifier on the most recent 9 months of data. Taking this classifier as fixed over the course of the next month, every hour we use the classifier to generate 1 hour ahead predictions based on the current data that hour. At the end of the next month, we retrain the classifier, then generate new hour-by-hour predictions for the following month. Empirically, we did not see any benefit to constantly refitting the classifiers with the latest hour of information$-$updating the models monthly was sufficient.
3.3 Gamma thresholding
As described in Section 3.2, every hour, SVM generates a class prediction for the return over the next hour. These predictions often are not “confident” or significant enough to warrant any action. Put another way, we would rather make fewer trading decisions that are very accurate, in lieu of many trades that on average are only slightly better than chance. The former scenario is more profitable, especially after considering the trading costs a small, non-institutional player would incur (see Section 3.4.2). To address this, we essentially use a form of classification with rejection Yuan and Wegkamp , saying “we don’t know” when the classifier does not seem “confident” enough in its prediction.
Formally, we define a tuning parameter $\gamma $, which serves as a threshold for making trading decisions. In the case of SVM, this tuning parameter is a threshold for the signed distance to the margin (See Appendix B.2). In other words, we will only consider potentially making a buy trade (i.e. consider a new point to belong to class ${c}_{1}$) if SVM predicts ${c}_{1}$ and the estimated distance to the margin exceeds $\gamma $. Random forest and XGBoost are perhaps more intuitive examples$-$here, $\gamma $ will serve as a threshold for the predicted class probability from the regression functions. For three classes, a naive Bayes’ rule would set $\gamma =1/3$ and suggest buy trades whenever the predicted probability weight on ${c}_{1}$ exceeds 1/3. If we choose a higher $\gamma >1/3$, we effectively make our trading strategy more conservative, setting a higher bar to meet before trading actions are taken. Empirically, we find that using a $\gamma $ threshold for predicting classes ${c}_{1}$ and ${c}_{2}$ improves NPV and PPV (see Figure 5), and in turn profitability (see Section 4.3).
3.4 Backtesting
We translate class predictions into trading decisions, and then we develop a backtester to simulate in a quasi-realistic setting how well our trading strategy would have done historically.
3.4.1 Trading Schedule
To simplify things, we assume we always hold either 100% cash or 100% cryptocurrency (only allowed to take long positions). If we are holding all cash, every hour we evaluate whether the predicted class is ${c}_{1}$ and the signed distance to the margin exceeds $\gamma $. If both conditions are met, we convert all our cash into cryptocurrency, buying at the current market price (we enter into a long position). If we are holding all cryptocurrency, every hour we evaluate whether the predicted class is ${c}_{2}$ and the signed distance to the margin exceeds $\gamma $. If both conditions are met, we convert all our cryptocurrency into cash, selling at the current market price (we exit the long position).
Algorithm 3.4.1 describes our trading strategy. Recall that we retrain the SVM classifier every month, using a rolling 9 month window, and we use it to make hourly predictions over the next month, denoted ${\widehat{y}}_{1},\mathrm{\dots},{\widehat{y}}_{T}$ in the algorithm below. We can of course refine this strategy by allowing shorting, as well as position sizing based on holdings and prediction confidence. But even the crude “all-in” strategy described here can outperform the market, as we will see in Section 4.3.
{algorithm}
{algorithmic}[1]
Input: SVM class predictions ${\widehat{y}}_{1},\mathrm{\dots},{\widehat{y}}_{T}$, SVM signed distances to margin ${d}_{1},\mathrm{\dots},{d}_{T}$, bitcoin prices ${P}_{1},\mathrm{\dots},{P}_{T}$, threshold $\gamma \ge 0$, take-profit ${s}_{G}>0$, stop-loss ${s}_{L}>0$, cash $C$
\Stateset bitcoins $B=0$, portfolio value $V=C$
\For$t=1,\mathrm{\dots},T$ \Commentloop over each 1-hour interval
\If$C>0$ \Commentcurrently holding all cash
\If${\widehat{y}}_{t}={c}_{1}$ AND ${d}_{t}\ge \gamma $
\State$B={\displaystyle \frac{C}{{P}_{t}}}$, $V=C$, $C=0$ \Commentconvert all cash into bitcoin
\EndIf\Else\Commentcurrently holding all bitcoin
\If${\widehat{y}}_{t}={c}_{2}$ AND ${d}_{t}\ge \gamma $
\State$C=B\cdot {P}_{t}$, $B=0$, $V=C$ \Commentconvert all bitcoin into cash
\EndIf
\If$\frac{B\cdot {P}_{t}-V}{V}}\ge {s}_{G$ OR $\frac{B\cdot {P}_{t}-V}{V}}\le {s}_{L$ \Commenttake-profit or stop-loss breached
\State$C=B\cdot {P}_{t}$, $B=0$, $V=C$ \Commentconvert all bitcoin into cash
\EndIf\EndIf\EndFor
\Return
3.4.2 Fees, Limits, and Risk
Our strategy is slow-moving enough and the market is active enough that we do not need market orders$-$limit orders at the best available price should execute within minutes, incurring a fee of 0.00% to 0.15% of the trade value to Coinbase Prime (https://prime.coinbase.com/). To be conservative, we assume trading costs of 0.25% for each trade. This is because in addition to fees explicitly paid to the exchange, trading also incurs invisible fees due to market impact Moro et al. (2009). The larger and more quickly one trades, the more expensive it is because one pushes the price further away.
Our backtester does not allow leverage, so the position size is limited to 100% of the portfolio value. We also include take-profit and stop-loss features to manage risk and modulate the aggressiveness of our strategy. These define the largest positional gain and loss, respectively, that one is willing to see before closing the position, either to lock in gains or prevent further losses.
4 Experimental Results
In both classification accuracy and backtest performance, SVM was our best model. Indeed, a trading strategy based on SVM beats the market on average from January 2018 to present.
4.1 Classification accuracy
Accuracy in key decision moments matters more than overall classification accuracy, especially as our strategies only decide to trade a small fraction of the time. The overall accuracy, taken over every hour of every day, is more indicative of “missed opportunities” and less relevant for our trading style. (See Appendix C for more detailed results.) We focus instead on PPV and NPV, which reflect how often our model is correct among the times that it chooses to actively buy or sell.
The positive predictive value (PPV) metric is defined as follows:
$$PPV=\frac{\text{\# of true positives}}{\text{\# of true positives + \# of false positives}}=\frac{\text{\# of true positives}}{\text{\# of predicted positives}}$$ |
The negative predictive value (NPV) metric is defined as follows:
$$NPV=\frac{\text{\# of true negatives}}{\text{\# of true negatives + \# of false negatives}}=\frac{\text{\# of true negatives}}{\text{\# of predicted negatives}}$$ |
Figure 5 shows the PPV and NPV for SVM, random forest, and XGBoost. Using the decision framework described in Section 3.4, we set a threshold $\gamma $, which means the prediction “confidence” must exceed $\gamma $ for the algorithm to treat it as positive (class ${c}_{1}$) or negative (class ${c}_{2}$). SVM consistently has the highest accuracy, and it forms the basis of a viable trading strategy.
4.2 Trading decisions
Figure 6 shows our trading strategy in action in the BTCUSD market in March 2018. Red x’s with vertical lines denotes trades, with green lines meaning buy and red lines meaning sell. Table 2 summarizes the 12 trades that were made. We see this was a particularly good month, where 5 out of 6 buy / sell pairs were profitable, and our algorithm made 22.7% after trading fees while the market dropped by 35.6%. It is also encouraging to see that visually, our trading decisions occur after sudden “jumps” in the price series, as expected for a strategy trading on momentum-based features.
Type | Time | Unit Price |
---|---|---|
buy | 2018-03-09 05:00:00 | 8499.90 |
sell | 2018-03-09 06:00:00 | 8815.08 |
buy | 2018-03-11 00:00:00 | 8529.96 |
sell | 2018-03-11 17:00:00 | 9631.78 |
buy | 2018-03-14 17:00:00 | 8335.12 |
sell | 2018-03-15 02:00:00 | 7797.50 |
buy | 2018-03-15 05:00:00 | 7791.95 |
sell | 2018-03-15 08:00:00 | 8194.61 |
buy | 2018-03-30 00:00:00 | 6815.01 |
sell | 2018-03-30 05:00:00 | 7110.39 |
buy | 2018-04-01 15:00:00 | 6450.01 |
sell | 2018-04-01 16:00:00 | 6805.01 |
4.3 Backtest results
Figure 7 shows monthly backtest results for BTCUSD. Each month begins on the 5th and ends on the 5th, and SVM returns are reported net of trading costs. We focus on the period Jan 2018 to the present as a separate “regime” from earlier years. Prior to 2018, crypto markets were in their infancy, with perhaps essentially different dynamics than the recent market, after the crypto bubble burst at the end of 2017. Our features seem work well over this recent period. Figure 8 shows monthly backtest results for ETHUSD and LTCUSD. Similar to Bitcoin, SVM outperforms the market somewhat consistently for Ethereum and Litecoin as well, while enjoying lower volatility.
These results are encouraging, as our naive “all-in” strategy performs well even without shorting or position sizing. Our average return over the 22 months from Jan 2018 to the present is higher than the market’s, while our fluctuations and drawdowns are smaller. This is true for all three assets we tested on: BTC, ETH, and LTC. It seems that in uncertain conditions when the market declines, such as the second half of 2018, our algorithm often does not trade at all, which helps overall performance while reducing overall volatility. In all 3 crypto markets, we are able to avoid the catastrophic losses of the market, while nimbly finding opportunities to make short term profits.
Figure 10 compares the time series of monthly returns from our strategy, rolling market volatility, and market returns for BTCUSD. In all 3 crypto markets we tested, our strategy seems to trade more when volatility is higher. (We study this in more detail in Appendix D.) Furthermore, its returns are relatively uncorrelated with the market, which is a great feature that allows one to, say, hold a long cryptocurrency position while using our strategy to trade short term around that position.
5 Discussion
Cryptocurrency price prediction is a difficult, open-ended problem with many possible approaches. We chose a black-box classification approach over the “medium term”, on the order of hours$-$neither ultra-short term like high frequency strategies, nor long term like venture capital investing. We gathered data from Coinbase and Blocktap, related to historical prices and volumes as well as on-chain metrics underlying the cryptographic networks. We then defined features to feed into a classification algorithm, and translated the resulting predictions into a trading strategy. While there remains much to be optimized and improved, it is heartening to see that our simple, straighforward black-box approach can deliver superior returns over an extended period of time.
5.1 Possible extensions
We believe there are opportunities in the cryptocurrency markets at other time horizons, both shorter and longer. For example, Coinbase provides order book information available at 1 minute intervals, which may be useful for higher frequency trading strategies. Instead of regular intervals, we could try retraining the classifier in an online fashion using change point detection Aminikhanghahi and Cook (2017). We could also adjust risk limits and position sizing dynamically based on market volatility. Another idea is to train only on short periods before and after major price spikes and drops, to try to understand these key events. We could also define the classification problem differently, or choose a regression approach instead. More powerful algorithms such as ensemble methods and recurrent neural networks might improve predictions. Also, the authors initially explored conformal methods for more cautious prediction intervals Hechtlinger et al. (2018), and it may prove fruitful to apply these ideas to our current framework. Outside of historical prices and volumes, sentiment data, in the form of news articles and social media posts, might reflect or influence investor sentiment and in turn influence prices. Additionally, macroeconomic factors may play an important role in cryptocurrency dynamics. Political and currency instability around the world, for example, might increase the demand for cryptoassets, which are relatively uncorrelated with the macroeconomy. Overall, we believe there is ample structure and opportunity in this relatively new, exciting asset class, and we are encouraged by the success of our simple black-box approach.
Acknowledgments
Firstly, I am grateful to my wonderful advisor Alessandro Rinaldo for his direction, guidance and support. I am also grateful to Christopher Brookins of Valiendero Digital Assets, LP for his wisdom and abundant industry experience. It has been rewarding to collaborate with dedicated colleagues Niccolo Dalmasso, Riccardo Fogliato, and Wanshan Li.
References
- Aminikhanghahi and Cook (2017) S. Aminikhanghahi and D. J. Cook. A survey of methods for time series change point detection. Knowledge and Information Systems, 51(2):339–367, 2017.
- Appel (2003) G. Appel. Become your own technical analyst. The Journal of Wealth Management, 6(1):27–36, 2003.
- Barnwal et al. (2019) A. Barnwal et al. Stacking with neural network for cryptocurrency investment. arXiv preprint arXiv:1902.07855, 2019.
- Bollinger (1992) J. Bollinger. Using bollinger bands. Stocks and Commodities, 10(2):47–51, 1992.
- Ciaian et al. (2014) P. Ciaian, Miroslava Rajcaniova, and d’Artis Kancs. The economics of bitcoin price formation. arXiv preprint arXiv:1405.04498, 2014.
- Gandal et al. (2018) N. Gandal et al. Price manipulation in the bitcoin ecosystem. Journal of Monetary Economics, 95:86–96, 2018.
- Hechtlinger et al. (2018) Y. Hechtlinger, B. Poczos, and L. Wasserman. Cautious deep learning. arxiv preprint arXiv:1805.09460, 2018.
- Jiang and Liang (2016) Z. Jiang and J. Liang. Cryptocurrency portfolio management with deep reinforcement learning. arXiv preprint arXiv:1612.01277, 2016.
- Kakushadze (2018) Z. Kakushadze. Cryptoasset factor models. Algorithmic Finance (forthcoming), 2018.
- Kannan et al. (2010) K. Senthamarai Kannan et al. Financial stock market forecast using data mining techniques. In Proceedings of the International Multiconference of Engineers and computer scientists., 1, 2010.
- Klein et al. (2018) T. Klein, H. P. Thu, and T. Walther. Bitcoin is not the new gold–A comparison of volatility, correlation, and portfolio performance. International Review of Financial Analysis, 59:105–116, 2018.
- Lee (2011) C. Lee. Litecoin. https://litecoin.org/, 2011. Online; accessed 1 November 2019.
- Mitchnick and Athey (2018) R. Mitchnick and S. Athey. A fundamental valuation framework for cryptoassets. https://s3-us-west-1.amazonaws.com/fundamental-valuation-framework-for-cryptoassets/A+Fundamental+Valuation+Framework+for+Cryptoassets_June+2018.pdf, 2018. Online; accessed 1 November 2019.
- Moro et al. (2009) E. Moro et al. Market impact and trading profile of hidden orders in stock markets. Physical Review E, 80.6:066102, 2009.
- Nakamoto (2008) S. Nakamoto. Bitcoin: A peer-to-peer electronic cash system. Consulted, 1:2012, 2008.
- Pan et al. (1997) M.S. Pan, Kam C.C., and R. Fok. Do currency futures prices follow random walks? Journal of Empirical Finance, 4.1:1–15, 1997.
- Wood (2014) G. Wood. Ethereum: A secure decentralised generalised transaction ledger. Ethereum project yellow paper, 151.2014:1–32, 2014.
- (18) M. Yuan and M. Wegkamp. Classification methods with reject option based on convex risk minimization. Journal of Machine Learning Research, 11.
Appendix A. Momentum-based features
Below, we give a few illustrative examples of the kinds of features we might derive from historical price and volume data. In particular, we seek features that capture the general “direction” or “momentum” of the market recently. The features below by no means represent an exhaustive list of the features used in our experiments in this paper.
A.1. Bollinger bands
Bollinger bands Bollinger [1992] compare the current price to rolling mean and volatility. Denote $P(i)$ as the price at time $i$, and $MA(n,t)$ as the $n$-day moving average price at time $t$. Define upper and lower bands:
$$U(t)=MA(n,t)+2\sqrt{\sum _{i=t-n+1}^{t}\frac{{(P(i)-MA(n,t))}^{2}}{n}}$$ |
$$L(t)=MA(n,t)-2\sqrt{\sum _{i=t-n+1}^{t}\frac{{(P(i)-MA(n,t))}^{2}}{n}}$$ |
Two features we derive from these Bollinger bands are %b and bandwidth. At time $t$, we write:
$$\%b=\frac{P(t)-L(t)}{U(t)-L(t)}$$ |
$$\text{bandwidth}=\frac{U(t)-L(t)}{MA(n,t)}$$ |
Figure 11 shows an example of Bollinger bands. Intuitively, we measure rolling mean and volatility in order to compare the current price level to levels in the recent past.
A.2. Moving average convergence-divergence
The moving average convergence-divergence (MACD) metric Appel [2003] compares two exponential moving averages (EMA) with different windows, and basically measures the level of the faster one relative to the slower one. Define the MACD line as
$$ |
where $P$ denotes price. Typical values for $m$ and $n$ are 12 and 26, respectively. Define the signal line as an exponential moving average of the MACD line:
$$S(t)=EMA(M,l,t)$$ |
A typical value for $l$ is 26. Finally, define the histogram line as
$$H(t)=M(t)-S(t)$$ |
Figure 12 illustrates features derived from the moving-average convergence divergence (MACD) metric. We compare a “slow” and “fast” exponential moving average, to capture where price levels have been recently relative to a slightly longer history.
A.3. Relative strength index
Here we give one additional example of a momentum-based feature. The relative strength index (RSI) metric Kannan et al. [2010] compares the magnitudes of recent gains and losses, producing a number between 0 and 100. Define the average gains and losses at time $t$:
$$AG(n,t)=\frac{{\sum}_{i=1}^{n}\mathrm{max}\{0,{R}_{t-i}\}}{n}$$ |
$$AL(n,t)=\frac{{\sum}_{i=1}^{n}|\mathrm{min}\{0,{R}_{t-i}\}|}{n}$$ |
where we define the return at time $t$ as
$${R}_{t}=\frac{{P}_{t}-{P}_{t-1}}{{P}_{t-1}}$$ |
Then define the first relative strength at time $t$ as
$$FRS(n,t)=\frac{AG(n,t)}{AL(n,t)}$$ |
and the smoothed relative strength at time $t$ as
$$SRS(n,t)=\frac{AG(n,t-1)\cdot (n-1)+\mathrm{max}\{0,{R}_{t}\}}{AL(n,t-1)\cdot (n-1)+|\mathrm{min}\{0,{R}_{t}\}|}$$ |
Now, the first relative strength index is defined as
$$RS{I}_{F}=100-\frac{100}{1+FRS}$$ |
and the smoothed relative strength index is defined as
$$RS{I}_{S}=100-\frac{100}{1+SRS}$$ |
A typical value for $n$ is 14 days.
Appendix B. SVM algorithm
B.1. Problem setup
Suppose data ${\mathbf{x}}_{1},\mathrm{\dots},{\mathbf{x}}_{n}$ belong to two classes, with labels ${t}_{1},\mathrm{\dots},{t}_{n}\in \{1,-1\}$ and feature transformation $\mathit{\varphi}$, and we model the predicted class assignment with
$$y(\mathbf{x})={\mathbf{w}}^{T}\mathit{\varphi}\mathbf{(}\mathbf{x}\mathbf{)}+{w}_{0}$$ |
We seek parameters $\mathbf{w},{w}_{0}$ such that
$${t}_{i}y({\mathbf{x}}_{i})\ge 0,\forall i=1,\mathrm{\dots},N$$ |
and that maximizes the minimal signed distance from any point to the boundary, known as the margin:
$$\widehat{\mathbf{w}},{\widehat{w}}_{0}=\underset{\mathbf{w},{w}_{0}}{\mathrm{arg}\mathrm{max}}\left(\frac{1}{\parallel \mathbf{w}\parallel}\underset{i\in \{1,\mathrm{\dots},N\}}{\mathrm{min}}\left({t}_{i}y({\mathbf{x}}_{i})\right)\right)$$ |
Equivalently, we solve
$$\widehat{\mathbf{w}},{\widehat{w}}_{0}=\underset{\mathbf{w},{w}_{0}}{\mathrm{arg}\mathrm{min}}\frac{1}{2}{\parallel \mathbf{w}\parallel}^{2}$$ |
such that
$${t}_{i}({\mathbf{w}}^{T}\mathit{\varphi}({\mathbf{x}}_{i})+{w}_{0})\ge 1,\forall i=1,\mathrm{\dots},n$$ |
B.2. Soft margin SVM
Often, the dataset is not exactly linearly separable in the given feature space, and furthermore, a solution that exactly separates the classes may overfit to training noise. We allow some points to remain “misclassified” by defining a slack variable ${\xi}_{i}$ for each data point ${\mathbf{x}}_{i}$:
$$ |
The slack variable represents the penalty incurred for violating the KKT conditions of the hard margin problem. If a point is exactly on the decision boundary, then $y({\mathbf{x}}_{i})=0$ and ${\xi}_{i}=1$. Points for which ${\xi}_{i}>1$ are misclassified, and points for which $$ are correctly classified but fall within the minimum margin. The soft margin problem can then be formulated as follows:
$$\widehat{\mathbf{w}},{\widehat{w}}_{0}=\underset{\mathbf{w},{w}_{0}}{\mathrm{arg}\mathrm{min}}\frac{1}{2}{\parallel \mathbf{w}\parallel}^{2}+C\sum _{i=1}^{n}{\xi}_{i}$$ |
such that
$${t}_{i}({\mathbf{w}}^{T}\mathit{\varphi}({\mathbf{x}}_{i})+{w}_{0})\ge 1-{\xi}_{i},\forall i=1,\mathrm{\dots},n$$ |
where $C>0$ is a tuning parameter that controls the tradeoff between minimizing training error and tolerating misclassifications. A larger $C$ more heavily discourages violating the hard margin KKT conditions. In the limit $C\to \mathrm{\infty}$, we recover the hard margin problem.
We can then write the Lagrangian, with Lagrange multipliers ${a}_{i},{b}_{i}\ge 0,\forall i=1,\mathrm{\dots},n$:
$$\mathcal{L}(\mathbf{w},{w}_{0},\mathbf{a},\mathbf{b})=\frac{1}{2}{\parallel \mathbf{w}\parallel}^{2}+C\sum _{i=1}^{n}{\xi}_{i}-\sum _{i=1}^{n}{a}_{i}({t}_{i}({\mathbf{w}}^{T}\mathit{\varphi}({\mathbf{x}}_{i})+{w}_{0})-1+{\xi}_{i})-\sum _{i=1}^{n}{b}_{i}{\xi}_{i}$$ |
The stationarity conditions are:
$$\frac{\partial \mathcal{L}(\mathbf{w},{w}_{0},\mathbf{a},\mathbf{b})}{\partial \mathbf{w}}=0\u27f9\mathbf{w}=\sum _{i=1}^{n}{a}_{i}{t}_{i}\mathit{\varphi}({\mathbf{x}}_{i})$$ |
$$\frac{\partial \mathcal{L}(\mathbf{w},{w}_{0},\mathbf{a},\mathbf{b})}{\partial {w}_{0}}=0\u27f90=\sum _{i=1}^{n}{a}_{i}{t}_{i}$$ |
$$\frac{\partial \mathcal{L}(\mathbf{w},{w}_{0},\mathbf{a},\mathbf{b})}{\partial {\xi}_{i}}=0\u27f9{a}_{i}=C-{b}_{i},\forall i$$ |
Observe that ${a}_{i}=C-{b}_{i},{b}_{i}\ge 0\u27f9{a}_{i}\le C$. Substituting back into the Lagrangian, we obtain the dual representation:
$$\mathcal{D}(\mathbf{a})=\sum _{i=1}^{n}{a}_{i}-\frac{1}{2}\sum _{i=1}^{n}\sum _{j=1}^{n}{a}_{i}{a}_{j}{t}_{i}{t}_{j}k({\mathbf{x}}_{i},{\mathbf{x}}_{j})$$ |
where $k({\mathbf{x}}_{i},{\mathbf{x}}_{j})=\mathit{\varphi}{({\mathbf{x}}_{i})}^{T}\mathit{\varphi}({\mathbf{x}}_{j})$. Notice that this expression is identical to the hard margin case. The difference between the soft and hard margin problems lies entirely in the constraints. For the soft margin problem, we have:
$$0\le {a}_{i}\le C,\forall i=1,\mathrm{\dots},n$$ |
$$\sum _{i=1}^{n}{a}_{i}{t}_{i}=0$$ |
The soft margin SVM must satisfy the following KKT conditions $\forall i=1,\mathrm{\dots},n$:
$${a}_{i}\ge 0$$ |
$${t}_{i}y({\mathbf{x}}_{i})-1+{\xi}_{i}\ge 0$$ |
$${a}_{i}[{t}_{i}y({\mathbf{x}}_{i})-1+{\xi}_{i}]=0$$ |
$${b}_{i}\ge 0$$ |
$${\xi}_{i}\ge 0$$ |
$${b}_{i}{\xi}_{i}=0$$ |
Every data point satisfies either ${a}_{i}=0$ or ${t}_{i}y({\mathbf{x}}_{i})=1-{\xi}_{i}$. The points for which ${a}_{i}=0$ are non-support vectors that do not contribute to the SVM solution at all. Only a sparse subset of points have ${a}_{i}\ne 0$: these are the support vectors that determine the solution.
B.3. Extension to multiple classes
SVM easily generalizes to multiple classes. With $K$ classes, we run $K$ different one-against-all SVMs, where in each case the label is +1 if it belongs to a class and -1 if it doesn’t. With functions ${\widehat{y}}_{1},\mathrm{\dots}{\widehat{y}}_{K}$, the final class assignment would then be $\widehat{k}\equiv \underset{k\le K}{\mathrm{max}}{\widehat{y}}_{k}(\mathbf{x})$. One issue with this approach is we cannot guarantee that ${\widehat{y}}_{1},\mathrm{\dots}{\widehat{y}}_{K}$ are comparable, since they are trained on different tasks. Also, the datasets for each classifier are unbalanced, with the proportions of labels are roughly $1/K$ for +1 and $(K-1)/K$ for -1. Despite these shortcomings, one-against-all remains a popular method. Another approach would be to train $K(K-1)/2$ pairwise one-against-one classifiers, which is more computationally expensive, and does not result in better performance on our datasets.
Appendix C. Extended classification accuracy results
Figure 13 shows the average monthly overall classification accuracy of SVM, random forest, and XGBoost from Jan 2018 to present. Because our model only trades a fraction of the time, these metrics are less relevant than PPV and NPV, as we described in Section 4.1.
Appendix D. Volatility vs. Returns
Figure 14 compares weekly SVM and market returns for ETHUSD, along with rolling weekly market volatility. As we described in Section 4.3, we suspect that our strategy trades more in periods of higher volatility, which is more clearly demonstrated at a weekly granularity.