Using algorithmic trading to analyze short term profitability of Bitcoin

Cryptocurrencies such as Bitcoin (BTC) have seen a surge in value in the recent past and appeared as a useful investment opportunity for traders. However, their short term profitability using algorithmic trading strategies remains unanswered. In this work, we focus on the short term profitability of BTC against the euro and the yen for an eight-year period using seven trading algorithms over trading periods of length 15 and 30 days. We use the classical buy and hold (BH) as a benchmark strategy. Rather surprisingly, we found that on average, the yen is more profitable than BTC and the euro; however the answer also depends on the choice of algorithm. Reservation price algorithms result in 7.5% and 10% of average returns over 15 and 30 days respectively which is the highest for all the algorithms for the three assets. For BTC, all algorithms outperform the BH strategy. We also analyze the effect of transaction fee on the profitability of algorithms for BTC and observe that for trading period of length 15 no trading strategy is profitable for BTC. For trading period of length 30, only two strategies are profitable.


INTRODUCTION
Cryptocurrencies have seen a surge in the recent past. Researchers and investors alike have focused on the growth and evolution of cryptocurrencies like Bitcoin (BTC), Etherum, and Litecoin etc. Moore (2013) attributed three main factors that contributed towards the rise and adaptation of bitcoins. First, higher profit margins, maintained by credit card agencies for using their platforms has resulted in dis-satisfied customers. The customers are thus lured to use BTC, which promises extremely low transaction fee. Second, the anonymity that is offered by the bitcoins. Bitcoins offer the possibility of conducting transactions using pseudonyms and thus omitting the need of using real names. Third is the decentralization of the bitcoin that protects against inflation. Over time, BTC has become one of the choice currencies for online payment and beside others is accepted by tech-giants like Amazon, Apple, Microsoft, and Paypal etc. The introduction of cryptocurrencies provided a new and technical analysis. We investigate the short term profitability of BTC against two other major currencies euro and yen. More specifically, we consider daily exchange rates of dollar-BTC, dollar-euro, and dollar-yen from 1st Jan 2011 to 31st Dec 2018. We investigate the short term profitability (15 and 30 days) as it is a common observation that in the long term BTC has observed significant price movement and is highly profitable.
We consider two categories of algorithms namely reservation price algorithms and moving average based algorithms and consider buy and hold as a benchmark strategy. Our findings are based on the geometric average period return, the effect of transaction fee, the number of buy and sell transactions, the number of completed transactions, and the number of profitable vs. non-profitable transactions. Using buy and hold strategy as our benchmark, we compare the geometric average period returns of the seven strategies with buy and hold. Rather surprisingly, we found that in short term the yen is more profitable than BTC and euro; however the answer also depends on the choice of algorithm. Reservation price algorithms result in 7.5% and 10% of average returns over 15 and 30 days respectively, which is the highest for all algorithms for the three assets. For BTC, all algorithms outperform the BH strategy. After introducing a transaction fee of 4%, we observe that for the trading period of length 15 no trading strategy is profitable for BTC, whereas for trading period of length 30, only two strategies are profitable.
It is important to mention that we do not consider machine learning techniques but instead focus on algorithmic trading strategies which do not rely on past trends and patterns, thus do not need future to follow the patterns of the past. Machine learning based algorithms are presented in the literature, the reader is referred to Uras et al. (2020), Alessandretti et al. (2018) and Zbikowski (2016) Rest of the paper is organized as follows; In 'Literature Review', we briefly present literature review on the use of experimental evaluation of trading algorithms. In 'Research Questions and Data Set', we present a set of research questions and the methodology for the extraction of data set. In 'Experimental Setup and Methodology', we describe the set of algorithms, followed by the description of the evaluation criterion. Results are presented in 'Results and Discussions', whereas 'Conclusion' presents conclusion, and directions for future work.

LITERATURE REVIEW
Experimental evaluation of trading strategies is an established area of research in Computer Science (Iqbal, Ahmad & Schmidt, 2012;Mohr, Ahmad & Schmidt, 2014), and Computational Finance (Brock, Lakonishok & LeBaron, 1992;Coakley, Marzano & Nankervis, 2016). Ever since the seminal work of Brock, Lakonishok & LeBaron (1992) there is a considerable literature devoted to the study of algorithmic trading strategies. The strategies are investigated from different perspectives and for various markets around the world. In the following, we present a brief literature review of the work based on experimental analysis of trading algorithms.
Iqbal,  performed an experimental evaluation of DAX 30 to answer the question ''Can online trading algorithms beat the market?''. The authors considered a number of trading algorithms, and compared their performance with classical buy and hold (BH ) algorithm over trading periods of various length. They concluded that trading algorithms can beat the market, i.e., a trading algorithm can achieve a better return (profit) than BH algorithm.  presented an extensive experimental evaluation of trading algorithms for uni-directional conversion problem (see Mohr, Ahmad & Schmidt (2014) for a definition of uni-directional conversion problem). The authors considered two data sets DAX 30 and S&P500 over a period of 10 years (2001)(2002)(2003)(2004)(2005)(2006)(2007)(2008)(2009)(2010), and compared the performance of various algorithms using average competitive ratio. Unlike, Iqbal, Ahmad & Schmidt (2012),  used bootstrapping to avoid data snooping bias. Coakley, Marzano & Nankervis (2016) performed a comprehensive analysis of various trading rules for 22 currencies over a period of 19 years. Authors reported evidence of profitability for rules based on classical moving average as well as rules based on Bollinger bands and relative strength index. Jiang, Tong & Song (2019) investigated the profitability of trading rules in Chinese stock market. The authors used 19 years daily data from Chinese aggregate market return and confirmed the profitability of trading rules even in the presence of transaction costs. Strobel & Auer (2018) analyzed the diminishing predictive power of fundamental variables and seasonal effects over time. They considered Variable Length Moving Average (VLMA) rules introduced by Brock, Lakonishok & LeBaron (1992), and using data set covering 1972 to 2015 concluded that VLMA rules have lost the predictive ability. Chang, Jong & Wang (2017) used VLMA rules to Taiwanese Stock Exchange (TWSE) and computed excess returns to buy and hold (BH ) strategy. The objective of the work was to evaluate the effectiveness of VLMA rules against BH . The results confirmed the superiority of VLMA rules against BH . The novelty of the work lies in the application of VLMA rules to all individual stock listed on TWSE. Hsu, Taylor & Wang (2016) investigated the profitability of technical trading rules in the forex market by analyzing 30 currencies over a period of 45 years. It is argued that there is a significant evidence of the profitability of technical trading rules for some periods. Likewise, the profitability variations are consistent with the adaptive market hypothesis. Fang, Jacobsen & Qin (2014) used the technical trading rules of Brock, Lakonishok & LeBaron (1992) and out-of-sample tests based on fresh data. They inferred that there is no conclusive evidence to support the predictive ability of these strategies. However, they attributed the lack of predictive ability to potential bias rather than efficient market hypothesis.
Despite the plethora of work dedicated to analyze the profitability of various trading strategies and markets, to the best of our knowledge there is no work that compares the profitability of Bitcoin with various other currencies, and to evaluate the performance of various algorithms on Bitcoin.

Research questions
We formulate a set of research questions (RQ), which essentially provide a base for the data analysis. The main objectives of the research questions are to identify the most profitable asset, the most appropriate (profitable) algorithm for various assets, and to analyze the effect of transaction cost on the profitability of various algorithms. RQ 1. Which asset is the most profitable in terms of geometric average period returns? RQ 2. Which strategy is the most profitable for each of the assets? RQ 3. How the number of buy and sell signals vary for BTC? RQ 4. What are the number of positive and negative returned transactions for BTC? RQ 5. How the transaction fee effects the profitability of algorithms?
Note that the research questions are not arbitrarily but are instead rooted in the literature. For instance, RQ1 is based on Hsu, Taylor & Wang (2016) who used Japanese yen, German mark/euro, U.K. pound, and Swiss franc as base currency in their study and evaluated the profitability of technical trading rules. Likewise, RQ2 is variant of research question posed in Abbey & Doukas (2012). In Abbey & Doukas (2012) the authors examined if technical trading rules can be profitable for individual traders. In the similar manner, RQ5 is studied by a number of researchers including Hsu, Taylor & Wang (2016) and .

Data
We consider the daily closing prices of the following currencies against dollar; i Bitcoin (BTC) ii Euro iii Yen A single data point represents the amount of currency that can be purchased by spending 1 US. The BTC data is obtained from coindesk website (http://www.coindesk.com) for a period of 8 years starting from 1 Jan 2011 to 31 Dec 2018. The main reason for the selection of the data set is based on the availability of the data. On many websites such as coindesk, USD-BTC data is only available from 18 July 2010, therefore, we select the starting date to be 1 Jan 2011, and in the process data set consists of complete 8 years. Euro and yen data is obtained from Yahoo! Finance (http://finance.yahoo.com). Table 1 reports various statistics for the data. For the sake of comparison, we take a holistic view of the whole data set by reporting the statistics for the 8 years (1 Jan 2011-31 Dec 2018).

Trading algorithms
A variety of trading algorithms are proposed in the literature (Mohr, Ahmad & Schmidt, 2014;Coakley, Marzano & Nankervis, 2016). In the following we describe a selected set of algorithms that are used in our study. The motivation behind the selection of the algorithms from the literature is rooted in the performance of the algorithms. Studies Iqbal, Ahmad & Schmidt, 2012;Iqbal, Ahmad & Shah, 2019) have shown that reservation algorithm of El-Yaniv et al. (2001) and Iqbal, Ahmad & Shah (2019) are the best performing algorithms. Further, in order to make the comparison meaningful, two widely used techniques from finance namely variable length moving average, and fixed length moving average are also considered.

Reservation price algorithms
Reservation price algorithm calculates a threshold price and generates a buy signal when the offered exchange rate is less than or equal to the threshold. A sell signal is generated when the price is at least threshold (Iqbal, Ahmad & Schmidt, 2012;Iqbal, Ahmad & Shah, 2019;Kao & Tate, 1999). A number of reservation price algorithms are presented in the literature (Mohr, Ahmad & Schmidt, 2014;Kao & Tate, 1999;Iqbal, Ahmad & Shah, 2019;El-Yaniv et al., 2001). In the following we present the selected set of reservation price algorithms considered for our study. El-Yaniv et al. (2001) assumed a priori information about the lower (minimum possible price m) and upper (maximum possible price M ) bound of prices, and presented a reservation price algorithm. Let e t be the current exchange price. Algorithm 1 provides formal description for El-Yaniv reservation price algorithm for generating buy and sell signals respectively.
Iqbal, Ahmad & Shah (2019) presented a modified version of the reservation price policy of El-Yaniv et al. (2001). The authors critiqued the assumption of fixed values of m and M and argued that inter-day price fluctuation is not arbitrary but is instead governed by inter-day price fluctuation function as shown in Eq (1). ( Note that e t is the exchange rate offered on day t , and γ ∈ 0,1. The formal description of algorithm is given in Algorithm 2. For detailed working of the algorithm, the reader is referred to Iqbal, Ahmad & Shah (2019). Kao & Tate (1999) presented a reservation price algorithm based on the perceived rank of the offered exchange rate. The perceived exchange rank is calculated based on the current A new exchange rate e t is observed.

4:
Compute achievable lower bound m t : rank x t of the offered exchange rate e t in all the exchange prices observed so far. The formal algorithm is presented in Algorithm 3. T represents the number of days in a trading period, L T (t ) and H T (t ) are the thresholds for buy and sell signals respectively and are computed as shown in Eqs.
(2) and (4) respectively; Generate a sell signal on the last trading day if there is an open buy signal even if the criterion for sell signal is not met.
Note that P T (t ) is the expected difference between the buy and sell prices if the optimal strategy is followed at t , and is calculated as shown in Eq. (3).
Note that R T is the expected final rank of e t for selling, if an optimal strategy is followed starting from time t , and is calculated as given in Eq. (5).

Moving average based rules
Moving average (MA) rule is the simplest and popular technical analysis trading rule. The basic idea of MA based rules is to generate buy and sell signals based on the short vs long-term moving averages. More specifically, a buy signal is generated when the short term moving average cuts the long term moving average from below. On the contrary, a sell signal is generated when the short-term moving average cuts the long-term moving average from above. However, in a market the crossing between short-term and long-term moving averages can occur on multiple instances in a short period, resulting in a large number of buy and sell signals (Zhu et al., 2015). The resulting large number of signals are hardly profitable and can force a large transaction fee as well. To avoid this, a minimum threshold called band is introduced. The band introduces a specific percentage difference between the short and long term moving averages in order to generate buy and sell signals.
In the literature two variants of the moving averages, called Variable Length Moving Average (VLMA) and Fixed Length Moving Average (FLMA) are used (Brock, Lakonishok & LeBaron, 1992;Gunasekarage & Power, 2001;Zhu et al., 2015). Let A S be the short term moving average, A L be the long term moving average, and B the band value. Algorithm 4 describes variable length moving average strategy for buy and sell signals.
In VLMA a buy signal is generated when the short term moving average cuts the long term moving average (taking into account the band value) from below, i.e., A S > (1 + B)A L . where short term average is taken over a period of 5 days, long term over a period of 30 days, and the band value is 2%. FLMA works on the same principle as stated in Algorithm 4. However, FLMA differs from the VLMA by introducing a holding period, i.e., once a signal is generated then the position must be held for a fixed number of days. Any signal generated during the holding period is ignored.

Buy and hold strategy
Buy and hold (BH ) is widely used in the literature as a benchmark strategy (Mohr, Ahmad & Schmidt, 2014;Chang, Jong & Wang, 2017;Baur et al., 2018), and is therefore used in our study as well. In BH an investor executes the buy transaction on the first day of the investment period and holds the position until the last day T . On the last day, a sell transaction is executed to complete the trading. The formal description of buy and sell signals of BH algorithm is given in Algorithm 5.

Algorithm 5 Buy and Hold (BH )
Require: e 1 ,e T 1: Buy on the first offered exchange rate e 1 2: Sell on the last offered exchange rate e T We test the profitability of the algorithms for various parameters and for various durations. We consider short term moving averages over 5 and 10 days, long term moving averages over 15, and 30 days, and band values 0.01 and 0.02 (Brock, Lakonishok & LeBaron, 1992;Fang, Jacobsen & Qin, 2014). Thus we produce a total of 8 trading rules, 4 each for VLMA and FLMA. Likewise, we consider 15 and 30 days durations for Algorithms 1, 2, 3 and 5. Thus we have a total of 16 variants of algorithms to evaluate. Table 2 presents a summary of the selected algorithms and their variants.

Evaluation criterion
We use Geometric Average Trading Period Return (GPR) as our evaluation criterion. GPR is used as an evaluation criterion in a number of works such as Schmidt, Mohr & Kersch  Initially we do not consider any transaction fee and report our findings based on zero transaction fee. In 'How the transaction fee effect the profitablity of algorithms?', we assess the impact of the transaction fee on the returns by introducing various values of transaction fees. The transaction fees are based on coinbase-one of the popular online services dealing in buying, selling and storage of bitcoins. Coinbase charges a minimum of 1.49% transaction fee on all transactions. However, the exact value varies based on the mode of payment. For instance, for payment via credit card the transaction fee is 3.99%. We consider a set of transaction fees TF = {0,2.0,4.0}. We compare the geometric average period returns of the 16 strategies (see Table 2). It is also important to mention that returns are only calculated for trading periods when at least one buy transaction is followed by a sell transaction. For situations, where only buy or only sell signals are generated, no returns are taken into account.

RESULTS AND DISCUSSIONS
In the following, we present our results from various perspectives such as the geometric average trading period returns, the number of buy/sell signals generated and the impact of the transaction fee.

Which asset is the most profitable in terms of geometric average period return?
We calculate geometric average trading period return for each trading rule based on Eq. (6) and report our findings as shown in Table 3. It must be noted that we do not consider any transaction fee in this case. The effect of the transaction fee is discussed later in 'How the transaction fee effect the profitablity of algorithms?' It can be seen from the resultant table that the average GPR of the selected assets are 1.016, 1.012, and 1.03 for BTC, Euro and Yen respectively. Although the difference between GPR is not significant, Yen achieved a higher return than BTC, and Euro. A further analysis of the data reflects that the returns are strategy dependent as well. For instance, RP * (30) achieved an GPR of 1.101 over BTC which is the highest returns among all the assets/strategies. Another interesting observation is the number of resultant positive and negative returns. Note that an GPR of at least 1 is termed as a positive return. For BTC, out of 16 strategies, 11 are positive. For Euro and Yen, the corresponding number of positive returns strategies are 16 and 15 respectively. Comparing the performance of reservation price algorithms (RP, RP * , KT ), and moving average based strategies (VLMA, FLMA) with BH , we found that for BTC, the returns of all algorithms are superior than corresponding BH strategies. The same trend is observed

Which strategy is the most profitable for each of the assets?
To answer the question, we analyze Table 3, and identify the best performing algorithm for each asset. We also consider the trading period length, and summarize the results in Table 4. We observed that RP * is the best algorithm for BTC achieving a GPR of 1.075 and 1.101 for trading period of length 15 and 30 respectively. For Euro, the corresponding algorithms are VLMA(5,15,0.02) and VLMA(10,30,0.02) resulting in an average GPR of 1.0432 and 1.021 respectively. FLMA(5,15,0.02) and FLMA(10,30,0.02) are the best performing algorithms for Yen with average GPR of 1.0953 and 1.0952 respectively. It is interesting to note that for each asset, a unique algorithm is adjudicated as the best performing algorithm. Further, analysis reveals that KT and BH are the worst performing algorithms for all the three data sets. For BTC, the two algorithms' returns are negative (< 1). For Euro, the returns of KT and BH are positive (though worst among all), and for Yen the returns are positive except for KT (30) which is marginally less than 1. On average, VLMA(10,30,0.2) is the best performing algorithm over all asset by achieving an average GPR of 1.052 which is closely followed by FLMA (10,30,0.02). It is interesting to point out that although RP and RP * assumes apriori information about the lower and upper bounds of future exchange rates, their average performance is inferior to that of VLMA and FLMA.
In order to ensure that the performance of algorithms on BTC is not an anomaly, a statistical t -test (paired sample t -test) was performed with confidence level of 95% (p ≤ 0.05). The tests were performed on the returns of algorithms for BTC considering 15 and 30 days trading duration. Tables 5 and 6 summarizes the results of paired t -test for the returns of BTC on various algorithms for 15 and 30 days trading periods. Recall from Table 3 that RP * is the best performing algorithm for BTC. Table 5 confirms that with 95% confidence the improved performance of RP * over all algorithms (except VLMA(5,15,0.02),and FLMA(5,15,0.02)) is not by chance. For VLMA (5,15,0.02),and FLMA(5,15,0.02) the confidence level is still significant ( 93% and 94%). Other than RP * , and RP no other algorithm exhibits a significant confidence in the returns over BTC. However, except for FLMA (5,15,0.01) and KT (15) all other algorithms have shown the potential to beat the market, i.e., the returns are better (and statistically significant) than BH strategy. For 30 days trading period, the returns of moving average based strategies are statistically significant than BH only (see Table 6), whereas RP * achieves statistically significant returns than RP, KT , and BH only.

How the number of buy and sell signals vary for BTC?
We record the number of buy and sell signals, as well as the number of completed transactions. A transaction is completed when for a buy signal the corresponding sell transaction occurs. Figure 1 summarizes the number of buy, sell and completed transactions. We observed that considering 15 days trading period for BTC, VLMA and FLMA based strategies resulted in 6% completed transactions. VLMA generates 2% more buy and sell signals than FLMA. This is logical as VLMA based strategies do not have any holding period and are free to generate a signal if the corresponding criterion is met. For reservation price algorithms, the number of completed transactions are in the range of 27 − 32%. Buy and hold has the highest number of completed transactions as it does not generate buy and sell signals based on some predefined criterion, but instead buys on the first trading day and sells on the last trading day irrespective of the offered exchange rate. For trading period of length 30 days, the same trend is observed for VLMA and FLMA based strategies.
Our analysis of the data reveals that for VLMA on average 96% of the buy transactions remains open whereas the corresponding number for the sell signal is 94%. Likewise, the percentage of open buy and sell signals for FLMA are 22% and 19% only. For reservation price algorithms, the number of completed transactions are reduced to 14 − 20%. What are the number of positive and negative returned transactions for BTC?
We investigate completed transactions from the perspective of positive vs negative returns for BTC. We define a transaction to yield positive returns if the sell price is higher than the buy price, i.e., r j > 1 where r j represents the returns of the trading period j.
For 15 days trading period, we observe that the VLMA and FLMA based strategies have higher percentage (> 50%) of negative returned transactions. For the reservation price policy, KT has more negative transactions (> 50%) whereas RP and RP * have higher positive transactions. RP has 66.8%, and RP * has 72 positive returned transactions. BH has 45% positive returned transactions. The worst rate of positive returned transaction is observed for KT (40%).
For trading duration of 30 days, rather surprisingly, the percentage of positive returned transaction increased slightly for VLMA, FLMA and KT , whereas a reduction is observed for RP and RP * . Figure 2 is a graphical summary of the positive and negative returned transaction for BTC.

How the transaction fee effect the profitablity of algorithms?
Transaction fee can be a vital factor in the profitability of any trading algorithm. We consider a transaction fee TF = {0%,2%,4%} and calculate GPR to find the effect on the profitability. Figure 3 is a graphical representation of the effect of transaction fee on GPR of algorithms for BTC. We observed an average reduction of 3.9% and 7.6% in the GPR of algorithms when transaction fee of 2% and 4% are levied. Introducing a transaction fee of 2% reduced the positive returned strategies from 11 to 5 only, which are further reduced to 2 (RP and RP * ) when the transaction fee is increased to 4%. For Euro, the profitability of algorithm is severely reduced from 16 to 0 strategies when the transaction fee of 4% is introduced. Rather interestingly, for Yen the introduction of transaction fee reduces the number of profitable strategies from 15 to 4 after introduction of 2% transaction fee. However, there is no change in the number of profitable strategies when the transaction fee is increased to 4%. For Yen, the four profitable strategies are VLMA (5,15,0.02), FLMA (5,15,0.02), VLMA (10,30,0.02), FLMA (10,30,0.02). This also reflects that for variable length moving average strategies to be profitable the band value is vital. For smaller band values, the strategies might not be profitable.

CONCLUSION
We evaluated the short term profitability of BTC over a set of reservation price and moving average based algorithms against the euro and the yen for a period of 8 years. Based on the average GPR, BTC seems less profitable venture than the yen; however, a deeper analysis revealed that the answer the profitability is strategy dependent as well. RP * achieved an average GPR of 10% for a trading period of 30 days, which is the maximum return obtained by any trading algorithm among the three assets. This confirmed BTC as an attractive investment opportunity for a short term investment. Our analysis also revealed that RP and RP * are the best performing algorithms on BTC, whereas moving average based algorithms return higher profits for the euro and the yen. It is also shown that the selected set of algorithms beat the buy and hold approach except on the yen where the returns of KT are less than that of buy and hold. Further, we highlighted that the returns of all the selected algorithms became negative except for RP and RP * when a transaction fee of 2% was introduced. Increasing the transaction fee to 4% resulted in positive returns for RP and RP * on 30 days investment horizon. For all other algorithms and their variants the returns were negative for a transaction fee of 4%.
To the best of our knowledge, this study is the first of its kind to evaluate the profitability of BTC using a set of trading algorithms and against fiat currencies. Future work can include finding an optimized portfolio of fiat and crypto-currencies for short and long term investment.

ADDITIONAL INFORMATION AND DECLARATIONS Funding
The authors received no funding for this work.