Intelligent method to cryptocurrency price variation forecasting

: Nowadays, accurate prediction of cryptocurrency price variation based on their important role in the world economy is an important and challenging issue. In this study, various parameters that affect the cryptocurrency value have been considered. For the first phase, four major price features of digital currencies have been analysed to determine the effect of each feature on the volatility prediction of future days. This study aims to understand and identify daily trends in the cryptocurrency market while gaining insight into optimal features surrounding their price. For the second phase, the price variation has been predicted with the highest possible accuracy with a new intelligent method. The proposed method consists of a neural network-based prediction algorithm and particle swarm optimisation. The obtained results show the capbility of the proposed method.


Introduction
Cryptocurrency is a medium of exchange that benefits from cryptography to secure transactions and control the generation of new units (of the same currency) [1][2][3]. Cryptocurrencies are classified as digital currencies. Bitcoin was introduced as the first decentralised cryptocurrency in 2009. Ever since then many cryptocurrencies have been developed as alternatives to Bitcoin [4,5]. A cryptocurrency is a form of electronic money. Most digital currencies have been developed to enhance security, eliminate intermediaries and ensure anonymity. Digital currencies use cryptography for transfer on the Internet.
The cryptography of these currencies cannot be hacked and tracked down. Cryptography was first used in the Second World War to transfer military messages and commands. In the digital age, mathematics and computer sciences have been employed to secure communications, information transfer and fund transfer. Known as the first digital currency, Bitcoin was introduced in 2009, now dominating the world of digital currencies. Many other digital currencies have been developed and introduced in recent years. Currently, nearly 2000 digital currencies are exchanged in global markets [6]. Bitcoin is now considered the most famous cryptocurrency. Each Bitcoin is a sequence of numbers with a specific feature [7].
If these numbers are put into a known operator, the output will be a relatively round number. Exchanging cryptocurrencies depend on national and international laws that can formalise and validate it. However, global statistics indicate undeniable advances in the use of cryptocurrencies as a means of an exchange over a short period of time (less than a decade). Developed in 2015, Ethereum is another famous digital currency. Ethereum uses its own blockchain; thus, it is also known as the second blockchain-based currency. Ripple is another famous decentralised platform that was developed in 2012 to conduct high-capacity transactions [8]. Litecoin was developed in 2013 by making certain changes to Bitcoin such as faster transactions and easier extraction.

Previous works
Digital currencies benefit from decentralised technology and enable users to make secure payments and save money without any need for registration or any help from banks and intermediary organisations. Most of the digital currencies run on a distributed database named the blockchain. Most of their units (except for tokens) are generated through a process known as extraction or mining. Predicting Fluctuations in Cryptocurrency Transactions Based on User Comments and Replies is the name of a study conducted in the University of South Korea in 2016 to analyse the volatility rates of three digital currencies. All of the previous studies focused on Bitcoin because there was a plethora of relevant data so that there was no need for modelling in practice [9][10][11][12].
This study aimed to analyse social networks and user comments to determine the factors affecting price volatility and extract a formula to predict volatility in prices of digital currencies. According to the author, the proposed method can be applied to different digital currencies such as Bitcoin, Ripple and Ethereum at an approximate precision of 74% [3]. In another study entitled When Bitcoin Encounters Information in an Online Forum: Using Text Mining to Analyse User Opinions and Predict Value Fluctuation conducted at the University of South Korea in 2017, user comments on online forums were taken into account to predict the final price. Unlike other studies conducting simple analyses [13,14], this study tried to analyse all of the comments for the prediction of price and market volatility. The study was carried out using data on forum comments over 32 months from December 2013 to September 2016.
In this work, the keywords were first extracted from user comments. Then it was decided to validate how those words and rates of transactions were related to the Bitcoin price. Finally, a model was developed through deep learning to predict the Bitcoin price. The best result of the proposed model was nearly 80.39%, pertaining to the Bitcoin price, obtained from a three-layered neural network with the data of 12 days of training [15].

Data collection
In this study, data were collected from reference websites on digital currencies such as Bitfinix and Coinmarketcap, each of which included the required research data that was collected and integrated to form the primary research database. In this study, the research subject was the mother of all digital currencies, i.e. Bitcoin. At first, the research period was one year (365 days), which was eventually expanded to include the past five years. Moreover, some of the extracted data had null or incorrect values for some features in certain periods of time. The noisy data were deleted through data filtering operations.

Feature selection
Considering the diversity of features in digital currencies and extensiveness of this area, the analysis of each feature can be turned into a thesis. In fact, most of the previous papers have addressed these features in different aspects. This study tried to analyse four major price features of digital currencies to determine the effect of each feature on the volatility prediction of future days (shown in Table 1).

Data normalisation
After entering data into MATLAB, each variable was first divided by its maximum to normalise data because the numerical values of data were very large or very small. Therefore, all of the data were converted to a value between zero and one. Close_normal = (close − min(close)) . /max(close)−min(close)); (1) equation (1) was then repeated for other variables with their maximums.

Forming M and target matrices
Before executing the neural network, certain preparations were necessary to determine and generate the appropriate database for training and prediction.
equation (2) was also executed for other variables that are mentioned in Table 1 with relevant maximums. Furthermore, the M vector is created through the following strategy as shown in Fig. 1.
The M matrix is created from all the variables in the database and the number of columns is similar to the target vector equal to TS and the number of rows is equal to the number of variables in the database (there are six variables in this study). Multiplying the value of BS that formed the matrix of TS × BS. The matrix is constructed and created in the same way to estimate all the features and will be the input to the neural network. It should be noted that after several steps of optimisation and modification of TS and BS values, the best values for these two variables were determined as 1 and 2, respectively.

Feature selection method
In this study, two consecutive filters were employed for data mining and reducing the size of training data.

Relative filter:
Given the fact that M had many elements, some of which are not useful and effective enough when training the neural network, it is better to employ a feature selection method first to eliminate fewer effective elements and then give the rest of M to the neural network for training. For this purpose, the concept of correlation was utilised to write the expected method in MATLAB.
In this method, each row of M is compared with that of target. If the resultant value is greater than TH1, it is selected as one row of final M. The value of TH1 is a threshold obtained through trial and error.
Equation (3) is used dynamically to determine TH1 TH1 = 0.4 * max (abs(correlation(m′, target′))); The value of TH1 is a threshold value obtained by trial and error, and in this study, the initial value of this variable was set at 0.4. If the threshold is correctly set, the final M matrix feature selection method should have about 40-50 rows at the end of the execution method, and the remaining rows with lower correlations should be eliminated.
Another important point is that the value set for TH1 is not definitive and it may be possible that in some issues including the problem discussed in this study, the data in the primary M matrix are all highly correlated with each other's and with the initial value selected for TH1 that were not deleted from M matrix. For this  reason, by changing the TH1 value to 0.97, the number of matrix rows has been reduced to 47.

Redundant filter:
Given the high correlation of data and insufficient elimination through the first filter, the second filter was executed. After execution, the second filter eliminated a large amount of primary data. In fact, only three rows out of the first 30 rows remained. In this filter, each row of data was compared to the next row. If the correlation of two rows is higher than the threshold TH2, one of them is eliminated. In this study, the threshold was considered to be 0.89 approximately.

Determining training and testing data
Given that the market closing price data in the bitcoin price database has been mostly upward in the first 4 years but declining in the fifth year, the training data should be selected in a way that include both upward and downward processes to let the network to train properly. Taking into account the above conditions, the 1000-1399 M columns was selected for the training data set and the 1400-1500 columns of M matrix were selected for the testing data set. Mean absolute percentage error (MAPE) and root mean square error (RMSE) were calculated to estimate market closing price volatility which showed significant improvement.
Equations (5) and (6) can be employed to calculate the MAPE and RMSE, respectively where At is the actual value, Ft is the forecasted value and n is the number of observations where Ft is the forecasted value, Ot is observed value and n is the number of observations.

Training and optimising the neural network with particle swarm optimisation (PSO)
According to the results of the neural network in the last steps of correction, TS and BS were obtained as 600 and 5, respectively. To improve the results, it was necessary to optimise the neural network with an optimisation technique. Thus, the genetic algorithm was integrated with the PSO and imperialist competitive algorithm. Finally, the PSO was selected as the research algorithm due to its good results. Considering the fact that the PSO benefits from a cost method based on which particles are moved in each step, the cost method was regarded as MAPE of the neural network so that particles could move in a new direction if the cost method showed a lower value in each step than the previous step. The cost function of the PSO algorithm at each stage receives the whole neural network as input and after calculating the MAPE decides for the next move. For this stage, the PSO algorithm in MATLAB was fully implemented and a raw neural network without training was produced and was trained at each step by the PSO algorithm to optimally approximate the weights and bias of the network.
In other words, at each step, the constituent particles of the PSO algorithm contain the weights and bias of the neural network and are optimised by this optimisation algorithm and re-injected into the primary neural network and the process of selecting weight and bias values in the neural network is completely overridden.
Otherwise, the particles would stay in their current position. To estimate each variable, M was given to the PSO if it was based on all features in the case when it included only the predicted variable. Furthermore, the PSO was analysed in three different states with different populations and periods. The results can be seen later in this study. Moreover, 2 was the best value determined for C1 and C2 through trial and error. Some of the resultant estimates were better than those of the backpropagation neural network. However, some other estimates were equal or even worse. They could be improved by increased population and the iteration period. Fig. 2 shows the general flowchart of the algorithm.

Results and discussion
In Table 2 comparison of results from the proposed algorithm in standard ANN by considering TH1 and TH2 with the proposed algorithm optimised with PSO is shown.
In Bitcoin Price Prediction Using Ensembles of Neural Networks, published by IEEE in 2017, the author tried to estimate the Bitcoin price for the next day based on 200 features of digital currencies. For this purpose, the author estimated the Bitcoin price of the next 50 days and determined the relevant profits consequently [16]. For profit determination in this study, it was assumed that if the algorithm predicted that the Bitcoin price would increase the next day, the initial capital would entirely be converted into Bitcoin. Otherwise, the entire Bitcoin asset would be sold and exchanged for dollars. To compare the results, the trading algorithm was implemented on the data obtained from the neural network in order to determine the gained profit over 50 days and 100 days. Table 3 shows the results.
Given the fact that the case study and the testing date of this study differ in dates, it turned out that the price was ascending in the research period. Naturally, higher profits were obtained. However, the price was descending in the research period. Consequently, lower profits would be obtained. In addition, the trading algorithm was tested only on the estimated data of the market opening price. If the estimated data of market closing price are also added to the profit analysis algorithm, i.e. when it is possible to conduct transactions twice a day, the profit will definitely increase (see Figs. 3-6).

Conclusion
Nowadays, increasing of cryptocurrencies' roles in the world economic processes can show the importance of digital currencies  variation prediction value. Various parameters can influence the cryptocurrency variation. In this study, the most important effective parameters have been considered. For the first phase, four major price features of digital currencies have been analysed to determine the effect of each feature on the volatility prediction of future days. For the second phase, the price variation has been predicted with the highest possible accuracy with a new intelligent method. The obtained results show the ability of the proposed method.