Content uploaded by Muhammad Ahmed Zaki
Author content
All content in this area was uploaded by Muhammad Ahmed Zaki on Feb 04, 2021
Content may be subject to copyright.
2nd International Conference on Computational Sciences and Technologies, 17-19 Dec 2020 (INCCST'20), MUET Jamshoro
ISBN-978-969-23372-1-2 56
Bitcoin Price Prediction App Using Deep Learning Algorithm
Kainat Mahar
Computer Systems Engineering
Mehran University of Engineering and
Technology, Jamshoro
Jamshoro, Pakistan
maharkainat@gmail.com
Sanam Narejo
Computer Systems Engineering
Mehran University of Engineering and
Technology, Jamshoro
Jamshoro, Pakistan
sanam.narejo@faculty.muet.edu.pk
Muhammad Ahmed Zaki
Computer Systems Engineering
Mehran University of Engineering and
Technology, Jamshoro
Jamshoro, Pakistan
ahmed_zaki64532@yahoo.com
Abstract—Bitcoin runs on a peer-to-peer basis and is a
decentralized cryptocurrency. It uses encryption and
anonymity for cryptography. Bitcoin is the top-ranking
cryptocurrency centered on the internet. The People most
encounter Bitcoin due to anonymity and transparency in the
system, among the widespread cryptocurrencies available on
the market. Bitcoin becomes popular because of its price
fluctuations. Cryptocurrency has emerged as a crucial
element in companies and stock sector opportunities in the
stock industry over the last decade. The accurate and
consistent forecast will help investors in cryptocurrency
make the right investment decisions and lead to future
higher income. Nevertheless, due to its chaotic and quite
complex existence, cryptocurrency price prediction is
considered a difficult job. Correspondingly, several
researchers have examined different factors that influence
the price of Bitcoin and the trends behind its fluctuation,
using a various machine learning algorithm. In this study,
the most powerful and commonly used deep learning
algorithm is implemented for forecasting bitcoin prices. The
real-time dataset is collected to the current date with the
Bitcoin value of Open, Close, Low, High, Volume to and
from price details. The purpose of this work is to use the
LSTM algorithm to extract the accurate price of Bitcoin. The
results obtained provide valuable evidence that LSTM can
solve this problem efficiently and effectively.
Keywords— Bitcoin, Prediction, Time-Series, Predictive
Model, Deep Learning, Long-Short Term Memory (LSTM),
Recurrent Neural Network (RNN), Real-time Data, Mean
Absolute Error (MAE), Accuracy
I. INTRODUCTION
Bitcoin is the collection of concepts and technologies
that form the foundation of an ecosystem of digital money.
Bitcoin is a revolutionary network for transfers and a new
kind of money. The decentralized network, Bitcoin enables
users to transact directly, peer to peer, without an
intermediary to handle the exchange of funds. In return for
products and services, the digital currency bitcoin has used
another currency. Bitcoin is conveniently portable,
divisible, and immutable, unlike conventional currencies
and properties.
By the end of 2017, when Bitcoin price increased most
significantly to 1600 US Dollars for 1 Bitcoin, the Bitcoin
had gained enormous popularity. Many experiments have
carried out using time series analysis to forecast the price
of Bitcoin. Predicting is the challenging aspect and it is one
of the greatest obstacle to human insight and every human
craves for it. Investors must forecast Bitcoin values.
Instead of being damaged by chance while making a
purchase when the value is high, Bitcoin users must be
observant in managing any price adjustments to profit. The
unpredictable price of Bitcoin can be predicted through
forecasting or forecasting the Bitcoin price in the
foreseeable future. Users can decide when to purchase
bitcoin with predictions.
This paper implements Long-Short Term Memory
(LSTM) Neural Network, from time-series data of
quantitative factors influencing Bitcoin prices to predict
the changes. The idea aims to introduce a framework adept
to processing data in real-time and providing investors
with a guide to assist to settle the plan in action. The
program will take the data from the real world and undergo
a series of data reshaping to make it ready to be fed into
the neural network model.
LSTM Neural Network architecture is a part of the
Deep Learning field. LSTM has feedback links, unlike
casual feedforward neural networks. It is capable of
processing not only single points (such as images) but also
whole data sequences (such a speech or video). For
instance, LSTM refers to tasks such as unsegmented
recognition of related handwriting, speech recognition, and
identification of anomalies in network traffic or IDSs
(Intrusion Detection System).
LSTMs solves the vanishing gradient issue that is
encountered during the training of RNN. LSTM neural
network is based on three gates; input gate, output gate and
forget gate. Over arbitrary time intervals, the cell recalls
values, these gates control the information incoming and
outgoing of a cell.
LSTM networks are well suited to make predictions
based on time series data as uncertainty can straggle,
Based on Time-Series data, LSTM networks are well
suited to classifying, processing, and making predictions,
as there can be lags of uncertainty, the length among the
main occurrence of time series data.
The inspiration for this project was taken from [14].
In the rest of the paper, in Section 2 Related Work is
discussed, following to this Section 3 defines Methodology
and in Section 4 shows the Results of conducted
experiment, Section 5 gives the Conclusion.
II. RELATED WORK
The high volatility feature of Bitcoin has attracted
many researchers from the field of economics, machine
learning, and cryptography. The various machine learning
algorithms are utilized for Bitcoin price prediction. [8]
discovered the influence of Bayesian Neural Network
(BNN) by evaluating the Bitcoin’s time series system.
Using Blockchain and macroeconomic variables the
forecasted Bitcoin prices and contrasted the prediction
success of BNN methods with linear regression methods
and SVRs. They notice that in terms of RMSE and MAPE
BNN model outperform other models for predicting the
57
Bitcoin log prices. Their SVR model indicates low
performance in training and testing stages. [9] investigate
the accuracy of the prediction of Bitcoin using a machine
learning algorithm and compare the performance with
ARIMA. The paper followed CRISP data mining
technology. The dataset of Bitcoin was collected for 3
years of timestamp. The closing price of Bitcoin was used
as an independent variable. The results showed that LSTM
achieved an accuracy of 52%, whereas RMSE achieves 8%
accuracy. The performance of ARIMA based on error was
significantly worse than neural network models. The
LSTM outperformed RNN marginally, not remarkably.
[10] presented the project on predicting the bitcoin price
using two deep learning technologies. Historical data was
collected from 2015. They filtered the data to get the
relevant features. CNN and RNN models were tested with
2-layers, 3-layers, and 4-layers approach. The result shows
that 4-layers outperformed 2-layers but not optimal for 3-
layers. The models were integrated on web pages designed
on the Django web framework. [5] proposed a model
called ConvLSTM which is a combination of
Convolutional Network and Recurrent Neural Network.
This model is based on the architecture of LSTM.
Historical data of a total of 10 stocks had been collected of
daily basis transaction. The proposed architecture was
compared with the pure LSTM. LSTM predicted better for
several stocks than the proposed architecture. However,
the proposed architecture was more stable and showed an
optimal error rate in multiple stocks. But the accuracy of
the proposed network still needs to be improved.
III. METHODOLOGY
The model is built using the sequential time series
algorithm LSTM of RNN. This paper implements the
LSTM neural network with dropout value of 0.2 and linear
activation function. This model uses Adam optimizer for
compilation and MSE as loss function.
Fig. 1 Workflow Diagram of Model
Dataset
The real-time dataset is taken from the website
cryptocompare. The table shows the description
parameters of the dataset.
TABLE 1. FEATURE DESCRIPTION OF DATASET
Features
Description
Open (O)
An open price of the currency in a market.
Close (C)
The nearest price to the market price of currency.
High (H)
The highest price of the currency in a market.
Low (L)
The lowest price of the currency in a market.
Volume
The volume of currency traded for that day.
For our project, we have targeted the close price of
Bitcoin. 80% of the dataset is for training and 20% for
testing.
A. Data Visualization
From figure 2, we can observe that from April 2019,
the price rapidly went up in July 2019 and has attained the
highest peak that is above 12000 USD. Then the curve
slowly goes down and, from January 2020 to April 2020,
there is a visible dip in the graph. The Lockdown period
has also affected the Bitcoin price. In April 2020, the price
again goes up. Since April, the price is continuously going
up with slight fluctuations.
Fig.2 Data Visualization
B. Normalization,
The next phase is to normalize the data. Normalization
is the process of rescaling original data without changing
its behavior or nature. Here Min-Max Normalization
technique is used.
1) Min-Max Normalization
On actual data, it performs linear transformation. It
maintains the relationship between the values of real
records. If the input values go past the range of
normalization in the future, an error known as an out-of-
bound-error can occur. [11]
C. Long Short Term Neural (LSTM) Network
Recurrent Neural Network is neural network with
directed graph sequence that links the output to the input.
That input connects the results of number point to the next
point in time, and tracks the neuron related information, so
that the next event results. The value is related to the
production value of earlier time points.
Long-Short Term Memory (LSTM) is a type of
Recurrent Neural network that can learn the data of long
sequences, a challenge that conventional RNNs are
struggling with, which is useful for some forms of
prediction that enable the network to maintain knowledge
over lengthy periods. LSTM is to mitigate the vanishing
and the exploding gradient problem.
A sequence of RNN modules has the shape of all
repeating neural networks. This repeating module would
have a simple structure with regular RNN, as in a layer of
tanh. Also, LSTMs have shape like this chain, but the
repetitive module has a different structure. Instead of a
single layer, there are four uniquely interacting.
58
Fig. 3 Repeating Module in an LSTM contains four interacting layers
1) Working of LSTM
Each of the memory cells in the LSTM network has
three types of gates- forget gate, input gate, and the output
gate.
The 1st Step of LSTM specifies what data to throw
away from the cell state. This decision is made by the
forget gate layer. One means retaining this information
and zero implies discarding this information.
ft = σ(Wf . [ht-1 . xt]+bf) (1)
Fig. 4 Forget Gate Layer
2nd Step decides what information to the store in the
cell state. It has two parts: the first input gate layer that
selects the value to update. Next, a new candidate value Ct
is created by adding the tanh layer in the state. Then, these
two values are combined to create an updated condition.
i
σ(Wi . [ht-1 . xt]+bi) (2)
c
σ(Wc . [ht-1 . xt]+bc) (3)
Fig. 5 Input Gate Layer
To update the old cell state, Ct-1 into new state Ct, the old
state is multiplied by ft the (it * ct) is added.
Ct = ft * Ct – 1 + it * ct (4)
Fig. 6 Updating Cell State
The third Step decides the output. A filtered
representation of the cell state is the basis of the output.
Next, what areas of the cell state are going to reveal is
determined by sigmoid. The cell state then positions tanh
and multiplies it by the production of the sigmoid gate that
generates the determined parts of the tanh.
ot = σ(Wo . [ht-1 . xt]+b0) (5)
ht = ot * tanh(Ct) (6)
Fig.7 Output Gate Layer
D. Evaluation Metric
Mean Absolute Error (MAE) is a metric for
performance measurement. MAE is more interpretable
metric which is the rationale for preferring MAE over
Root Mean Square Error(RMSE). RMSE in itself does not
depict an average error and is thus much more difficult to
comprehend. Since we want to describe a model quickly
to the non-technical audience, MAE seems like a better
alternative.
1) Mean Absolute Error (MAE)
Mean Absolute Error is a model evaluation metric
used with regression models. The mean absolute error of a
model concerning a test set is the mean of all values of
individual prediction errors over all instances in the test
set. Each prediction error is the difference between the
actual value and the predicted value for the occurrences.
[13]
E. Deployment
Model is deployed on an android platform. Deploying
models to android with TensorFlow mobile involves three
steps:
The Conversion of the trained model into
TensorFlow.
Adding TensorFlow Mobile as a dependency on
the Android App.
Developing Java code to perform inference in
application with the TensorFlow Model
TensorFlow has TensorFlow Mobile and TensorFlow
Lite libraries. The Lite version is extremely limited in
size, with just about 1 Mb of total dependence. Also, the
templates are better configured.
TensorFlow Lite supports converting TensorFlow
RNN models to the fused LSTM operations of
TensorFlow Lite. Fused operations optimize the efficiency
of the underlying kernel implementations and provide a
higher-level interface to define complex transformations
such as quantization.
Since TensorFlow has several variants of RNN APIs,
the most common approach has been two-fold:
Provide native support like Keras LSTM for
standard TensorFlow RNN APIs.
Provide the user-defined RNN implementations with
an interface to the conversion infrastructure to plug
in and convert to TensorFlow Lite. By using
Lingvo's LSTM Cell Simple and Layer Normalized
LSTM Cell Simple RNN interface.
IV. RESULTS AND DISCUSSIONS
The model is implemented using the LSTM
algorithm. It is the 3-stacked layer model with a linear
activation function each layer contains 500 neurons and a
59
dropout value of 0.2. The input data split into the first
80% for training and the last 20% for testing. The model
was trained on real-time data that keeps the record of 400
days from the latest date. The performance is measured
using MAE evaluation metrics, and loss is measure using
MSE. TABLE 2 MODEL SUMMARY
Model Summary
Layer (type)
Output Shape
Param #
lstm_1 (LSTM)
(None, 1, 500)
1004000
lstm_2 (LSTM)
(None, 1, 500)
2002000
lstm_2 (LSTM)
(None, 500)
2002000
dropout_1 (Dropout)
(None, 500)
0
activation_1 (Activation)
(None, 1)
0
dense_1 (Dense)
(None, 1)
501
Total params: 5,000,501,
Trainable params: 5,008,501
Non-trainable, params: 0
Figure 9 shows that from the 5th epoch, the loss
during training and testing of data reduced to zero.
Fig. 9 Train and Test Loss
Figure 10 represents Mean Absolute Error during
training and testing of data. From the given figure, we can
see, an error rate is reduced below 0.05 after five epochs
show good accuracy
Fig. 10 Mean Absolute Error
Figure 11 represents a graph that shows the
predicted values and actual values. As this model is using
a real-time dataset, the plot starts from the latest date and
gives a prediction for up to 100 next days. It is noticeable
that the predicted labels are accurate to actual labels and
showing 99% accuracy.
Fig.11 Predicted Graph
It is to observe that from the 70th day to the 80th
day, the bitcoin price reaches its maximum price that is
around 20k US Dollars.
After tuning the model, by setting the learning
rate of Adam optimizer to 0.01, activation sigmoid, mean
squared error as metrics, and categorical_crossentropy as
the loss, there seems a big difference in training and
testing validation also, it left a significant impact on the
prediction graph.
Fig. 12 Train and Test Loss
Fig. 13 Mean Squared Error
60
Fig. 14 Prediction Results
From the above figures, it can be assured that the
parameters which were selected before turns out best for
the model by giving a highly accurate prediction, whereas
the parameters which were set for experimental analysis
turn out to be too bad for the model.
V. CONCLUSION
Bitcoin is a decentralized cryptocurrency that
works on a peer-to-peer system. It uses cryptography
security and anonymity. Unlike traditional currencies,
bitcoins are entirely virtual. Just like a stock, the value of
Bitcoin varies. For forecasting of price, there are many
algorithms used on stock market value. The criteria
affecting Bitcoin are distinct. In order to make the best
investment decision, the valuation of Bitcoin must also be
expected. This paper is implemented on 3-Layer LSTM
Model using real-time data to predict the future price of
Bitcoin for the next 100 days from the current day. The
model gives an excellent prediction and an error rate
lower than 0.5. The concept was to incorporate a
framework that could analyze real-time data and provide
investors a sense of direction to aid in decision making.
REFERENCES
[1] A. M.Antonopoulos, Mastering in Bitcoin, O'Reilly Media,
2017.
[2] H. Jang, J. Lee, “An Empirical Study on Modeling and
Prediction of Bitcoin Prices with Bayesian Neural Networks
Based on Blockchain Information,” IEEE Access, no. 2018.
[3] K. Rathan, S. Venkat Sai, T. Sai Manikanta, “Crypto-
Currency price prediction using Decision Tree and
Regression Techniques,” Proceedings of the Third
International Conference on Trends in Electronics and
Informatics (ICOEI 2019), no. 2019.
[4] S. Roy, S. Nanjiba, A. Chakrabarty, “Bitcoin Price
Forecasting Using Time Series Analysis,” 2018 21st
International Conference of Computer and Information
Technology (ICCIT), no. December 2018, 2018.
[5] S. En-Gao, B. Sheng-Lin, W. Chuin-Mu, “Share Price Trend
Prediction Using CRNN with LSTM Structure,” 2018
International Symposium on Computer, Consumer and
Control (IS3C), no. 2018.
[6] K. Rathan, S. Venkat Sai, T. Sai Manikanta, “Crypto-
Currency price prediction using Decision Tree and
Regression Techniques,” Proceedings of the Third
International Conference on Trends in Electronics and
Informatics (ICOEI 2019), no. 2019.
[7] I. M. Wirawan, T. Widiyaningtyas, M. Maulana Hasan,
“Short Term Prediction on Bitcoin Price Using ARIMA
Method,” 2019 International Seminar on Application for
Technology of Information and Communication (iSematic),
no. 2019.
[8] H. Jang, J. Lee, “An Empirical Study on Modeling and
Prediction of Bitcoin Prices with Bayesian Neural Networks
Based on Blockchain Information,” IEEE Access, no. 2018.
[9] S. McNally, J. Roche, S. Caton, “Predicting the Price of
Bitcoin Using Machine Learning,” International Conference
on Advanced Communications Technology(ICACT), no.
2018.
[10] S. Yogeshwaran, M. Jeet Kaur, P. Maheshwari, “Project
Based Learning: Predicting Bitcoin Prices using Deep
Learning,” 2019 IEEE Global Engineering Education
Conference (EDUCON), no. 2019.
[11] admin. [Online]. Available:
https://kraj3.com.np/blog/2019/06/easy-explanation-of-
normalization-standardization-in-machine-learningusing-
python/.
[12] W. Chih-Hung, M. Yu-Feng, L. Chih-Chiang, “A New
Forecasting Framework for Bitcoin Price with LSTM,” 2018
IEEE International Conference on Data Mining Workshops
(ICDMW), 2018.
[13] C. Sammut, G.I. Webb, “Mean Absolute Error,”
Encyclopedia of Machine Learning. Springer, Boston, MA,
2011.
[14] M.Rizwan, S.Narejo, M.Javed, “Bitcoin Price Prediction
Using Deep Learning Algorithm,” 2019 13th International
Conference on Mathematics, Actual Science, Computer
Science and Statistics (MACS) ,Karachi, Pakistan, 2019.