Bitcoin with Sourcecode
Bitcoin with Sourcecode
learning techniques. Due to its high volatility attribute, accurate price prediction is the
need of the hour for sound investment decision-making. At the offset, this study
categorizes Bitcoin price by daily and high-frequency price (5-min interval price). For
its daily and 5-min interval price prediction, a set of high-dimensional features and
statistical methods like Logistic Regression predict daily price with 64.84% accuracy
while complex machine learning algorithms like XGBoost predict 5-min interval price
with an accuracy level of 59.4%. This work on Bitcoin price prediction recognizes the
ii
TABLE OF CONTENTS
Title. Page.No
Chapter 1: Introduction 1
1.1 Bitcoin 2
1.2 Overview 3
1.3 Applications 5
2.1 Using the Bitcoin Transaction Graph to Predict the price 8 of Bitcoin
iii
4.2 Functional Requirements 15
28 Chapter 6: METHODOLOGY
6.3 Preprocessing 31
6.6 Prediction 33
6.7 Methods 33
6.7.3 XG boost 37
iv
6.7.5 LSTM 40
6.7.6 ANN 42
6.8 Python 43
6.8.1 Pandas 45
6.8.2 Numpy 45
6.8.3 matplotlib 46
6.8.4 seaborn 46
6.8.6 Keras 47
Chapter 7: RESULTS 51
7.1 Graph 52
7.10 LSTM 59
REFERENCES 50
v
LIST OF FIGURES
1.1 Bitcoin 2
7.1 Graph 52
vi
CHAPTER-1
INTRODUCTION
1
1.1 Bitcoin
Bitcoin is an open-source, peer-to-peer digital currency. Among many other things, what
makes Bitcoin unique is that it is the world’s first completely decentralized digital-payments
system. This may sound complicated, but the underlying concepts are not difficult to
understand. Crypto-currencies, such as Bitcoin, are one of the most controversial and complex
technological innovations in today’s financial system. From the past few years bitcoin is one
of the trending in the market more than the stocks. The value of a bitcoin (or BTC) has grown
and fluctuated greatly, from pennies in its early days to more than $260 at its peak in April
2013. The current market capitalization of the bitcoin economy is estimated to be more than
$1 billion.
2
1.2 Overview:
3
well as other cryptocurrencies, are in fact data treated like money. Users (called “miners”) send
and receive these cryptocurrencies (data) electronically from their computers in peer-to-peer
network systems to pay for things, if other parties are willing to accept such payments. Market
capitalization and the number of miners of 2957 crypto-currencies reached $221 billion (Bitcoin
$147) and 42 million in 2019.
The price of Bitcoin has drastically increased from $0.0008 to $10,168 per single coin from
being launched in January 2009 to February 2020. Hence, first and foremost, the Bitcoin and
other cryptocurrencies have become extremely popular due to increasing number of their
users and their huge gains. On the other hand, Bitcoin’s and other cryptocurrencies’ prices-
series, similar to other financial assets-series, exhibit chaotic fluctuations. Because of
asymmetric information problems in financial markets, increasing economic- political
uncertainties and changing behaviors of miners may make the prices of cryptocurrencies not
easily predictable for investors. Cryptocurrencies’ forecasting difficulties may well be higher
than those of other conventional assets; although they are so popular for investors, very little
is known about them, about how they work and how they are created (mined), since they are
not physical currencies. Accordingly, accurately forecasting their prices may minimize
potential lossesrisks for users.
This market is characterized by high volatility, no closed trading periods, relatively smaller
capitalization, and high market data availability. The financial feasibility of the
cryptocurrency market in relation to other markets has been documented and the algorithms
upon which the cryptocurrencies operate have been validated in other fields as well. The
cryptocurrency market seems to behave independently from the other financial markets, but
there is a strongly influenced by Asian economies. Part of the appeal behind this market is that
the technology used for mining cryptocurrency provides feasible alternative to more
traditional markets such as gold. These characteristics have attracted a considerable amount of
capital, however up to now there are few studies that have attempted to create profitable
trading strategies in the cryptocurrency market. Another point of interest in the cryptocurrency
market is the large-scale of available public sentiment data, particularly from social networks.
This data can presumably be used to infer future human behavior, and therefore could be used
to develop advantageous trading strategies as has been shown in recent attempts to detect
speculative bubbles in the cryptocurrency market using sentiment analysis.
The complexity of the task can be attributed to the multiple factors and uncertainties that
interact in the markets including economic and political conditions, as well as human behavior.
4
Being able to consistently predict the market price movements is quite difficult, but not
impossible. According to academic research, movements in the market prices are not random,
but behave in a highly non-linear and dynamic way. Previous studies have also shown that it is
not necessary to be able to foretell the exact value of the future price in order to make profit in
financial predictions. In reality, predicting the market direction as compared to its value can
result in higher profits.
1.3 Applications:
Lower Transaction Costs Because there is no third-party intermediary, Bitcoin transactions are
substantially cheaper and quicker than traditional payment networks. And because
transactions are cheaper, Bitcoin makes micropayments and other innovations possible.
Additionally, Bitcoin holds much promise as a way to lower transaction costs for small
businesses and global remittances, alleviate global poverty by improving access to capital,
protect individuals against capital controls and censorship, ensure financial privacy for
oppressed groups, and spur innovation (within and on top of the Bitcoin protocol). On the
other hand, Bitcoin’s decentralized nature also presents opportunities for crime. The challenge,
then, is to develop processes that diminish the opportunities for criminality while maintaining
the benefits that Bitcoin can provide.
Since Bitcoin facilitates direct transactions without a third party, it removes costly charges that
accompany credit card transactions. The Founders Fund, the venture capital fund headed by
Peter Thiel of PayPal and Facebook fame, recently invested $3 million in the
paymentprocessing company Bit Pay because of the service’s ability to lower the costs of
doing online commerce across borders. In fact, small businesses have already started to
accept bitcoin as a way to avoid the costs of doing business with credit card companies Others
have adopted the currency for its speed and efficiency in facilitating transactions. Bitcoin will
likely continue to lower transaction costs for businesses that accept it as more people adopt
the currency.
5
CHAPTER-2
LITERATURE SURVEY
6
LITERATURE SURVEY
2.1 Using the Bitcoin Transaction Graph to Predict the Price of Bitcoin
We consider the problem of planning the ISS cosmonaut training with different objectives. A
pre-defined set of minimum qualification levels should be distributed between the crew
members with minimum training time differences, training expenses or a maximum of the
training level with a limitation of the budget. First, a description of the cosmonaut training
process is given. Then four models are considered for the volume planning problem. The
objective of the first model is to minimize the differences between the total time of the
preparation of all crew members, the objective of the second one is to minimize the training
expenses with a limitation of the training level, and the objective of the third one is to
maximize the training level with a limited budget. The fourth model considers the problem as
an -partition problem. Then two models are considered for the calendar planning problem.
Bitcoin is the world’s leading cryptocurrency, allowing users to make transactions securely
and anonymously over the Internet. In recent years, The Bitcoin ecosystem has gained the
attention of consumers, businesses, investors and speculators alike. While there has been
significant research done to analyze the network topology of the Bitcoin network, limited
research has been performed to analyze the network’s influence on overall Bitcoin price. In
this paper, we investigate the predictive power of blockchain network-based features on the
future price of Bitcoin. As a result of blockchain-network based feature engineering and
machine learning optimization, we obtain up-down Bitcoin price movement classification
accuracy of roughly 55%.
For the volume planning problem, two algorithms are presented. The first one is a heuristic
with a complexity of ( ) operations.
2.3 Economic prediction using neural networks: the case of IBM daily stock
returns
A report is presented of some results of an ongoing project using neural network modeling and
learning techniques to search for and decode nonlinear regularities in asset price movements.
The author focuses on the case of IBM common stock daily returns. Having to deal with the
salient features of economic data highlights the role to be played by statistical inference and
requires modifications to standard learning techniques which may prove useful in other
contexts
2.4 Designing a neural network for forecasting financial and economic time
series
Artificial neural networks are universal and highly flexible function approximators first used
in the fields of cognitive science and engineering. In recent years, neural network applications
in finance for such tasks as pattern recognition, classification, and time series forecasting have
dramatically increased. However, the large number of parameters that must be selected to
develop a neural network forecasting model have meant that the design process still involves
much trial and error. The objective of this paper is to provide a practical introductory guide in
the design of a neural network for forecasting economic time series data. An eight-step
procedure to design a neural network forecasting model is explained including a discussion of
tradeoffs in parameter.
8
CHAPTER-3
SYSTEM ANALYSIS
9
3.1 EXISTING SYSTEM:
Although existing efforts on Cryptocurrency analysis and prediction are limited, a few studies
have been aiming to understand the Cryptocurrency time series and build statistical models to
reproduce and predict price dynamics. Madan etal collected bitcoins price with the time
interval of 0.5, 1and 2 hours, and combined it with the blockchain network, the underlying
technology of bitcoin. Their predictive model leverages random forests and binomial logistic
regression classifiers and the precision of the model is around 55% in predicting bitcoin’s
price. While an increasing number of people are making investments in Cryptocurrency, most
investors cannot get such profit for being inconsiderable to cryptocurrencies’ dynamics and
the critical factors that influence the trends of bitcoins.
⮚ Therefore, raising people’s awareness of vital factors can help us to be wise investors.
Although market prediction is demanding for its complex nature, the dynamics are predictable
and understandable to some degree.
⮚ By using random forests and binomial logistic regression We cannot predict the 100%
results
Among many features of bitcoin, the most impressive one is decentralization in that it can
remove the involvement of Traditional Financial sectors and monetary authorities effectively
due to its block chain network features. In the proposed system we are using ANN Algorithm
and LSTM to easily predict the time series of crypto currency prices.
We Use An ANN model to predict the price of Bitcoin one day into the future using five
different lengths of memory. While LSTM is intentionally designed to model the internal
memory flow and its impact on future prediction, therefore, both ANN and LSTM are suitable
for the crypto currencies price time series prediction
10
3.2.1 Advantages of Proposed System:
Bitcoin has introduced the controllable anonymity scheme, and this enhances users’ safety and
anonymity by using this technology, for instance, we can take advantage of this property of
blockchain to make identification cards, and it not only can protect our privacy but verify our
identity.
The feasibility of the project is analyzed in this phase and business proposal is put forth with a
very general plan for the project and some cost estimates. During system analysis the
feasibility study of the proposed system is to be carried out. This is to ensure that the proposed
system is not a burden to the company. For feasibility analysis, some understanding of the
major requirements for the system is essential
Three key considerations involved in the feasibility analysis are,
• Economical Feasibility
• Technical Feasibility
• Social Feasibility
1.Economical Feasibility
This study is carried out to check the economic impact that the system will have on the
organization. The amount of fund that the company can pour into there search and
development of the system is limited. The expenditures must be justified. Thus the developed
system as well within the budget and this was achieved because most of the technologies used
are freely available. Only the customized products had to be purchased.
2. Technical Feasibility
This study is carried out to check the technical feasibility, that is, the technical requirements of
the system. Any system developed must not have a high demand on the available technical
resources. This will lead to high demands on the available technical resources. This will lead
to high demands being placed on the client. The developed system must have a modest
requirement, as only minimal or null changes are required for implementing this system.
11
3. Social Feasibility
The aspect of study is to check the level of acceptance of the system by the user. This includes
the process of training the user to use the system efficiently. The user must not feel threatened
by the system, instead must accept it as a necessity. The level of acceptance by the users
solely depends on the methods that are employed to educate the user about the system and to
make him familiar with it. His level of confidence must be raised so that he is also able to
make some constructive criticism, which is welcomed, as he is the final user of the system.
12
CHAPTER-4
SOFTWARE REQUIREMENT
13
SPECIFICATION SOFTWARE REQUIREMENT
SPECIFICATION
4.1 Requirements Specification:
Requirement Specification provides a high secure storage to the web server efficiently.
Software requirements deal with software and hardware resources that need to be installed on
a server which
Provides optimal functioning for the application. These software and hardware requirements
need to be installed before the packages are installed. These are the most common set of
requirements defined by any operation system. These software and hardware requirements
provide a compatible support to the operation system in developing an application.
14
4.4 Technical Requirements
Software Requirements:
Operating System: Windows
Tool: Anaconda with Jupyter Notebook
Hardware Requirements:
Processor: Pentium IV/III
Hard disk: minimum 80 GB
RAM: minimum 2 GB
4.5.1Requirement Specification
• Software Requirements
For developing the application the following are the Software Requirements:
Python 3.9
Django
Windows 10 64 bit OS
• Hardware Requirements
For developing the application the following are the Hardware Requirements:
Processor: Intel i3
RAM: 4 GB
Space on Hard Disk: minimum 1 TB
15
CHAPTER-5
SYSTEM DESIGN
16
SYSTEM DESIGN
SYSTEM ARCHITECTURE:
1. The DFD is also called a bubble chart. It is a simple graphical formalism that can be
used to represent a system in terms of input data to the system, various processing
carried out on this data, and the output data is generated by this system.
2. User: The process starts with a user.
3. Unauthorized Check: The system checks if the user is unauthorized. It's unclear what
happens if the user is unauthorized based on this flowchart.
4. Trading: If the user is authorized, the process moves to a step labeled "Trading." It's
unclear what happens during this step.
5. Bitbucket: From "Trading" the flowchart goes to "Bitbucket." Bitbucket is a version
control system for IT projects, not typically part of a trading system.
6. Prediction: Next, the flowchart moves to "Prediction." It's possible this refers to some
kind of prediction made by the trading system, but there's no context provided to
understand how this prediction is made.
7. End Process: Finally, the flowchart ends at "End Process."
17
Fig 5.2
Fig 5.2.1
18
Fig 5.2.2
The goal is for UML to become a common language for creating models of object- oriented
computer software. In its current form UML is comprised of two major components: a
Metamodel and a notation. In the future, some form of method or process may also be added
to; or associated with, UML.
The UML represents a collection of best engineering practices that have proven successful in
the modeling of large and complex systems.
19
The UML is a very important part of developing objects-oriented software and the software
development process. The UML uses mostly graphical notations to express the design of
software projects.
A use case diagram in the Unified Modeling Language (UML) is a type of behavioral diagram
defined by and created from a Use-case analysis. Its purpose is to present a graphical
overview of the functionality provided by a system in terms of actors, their goals (represented
as use cases), and any dependencies between those use cases. The main purpose of a use case
diagram is to show what system functions are performed for which actor. Roles of the actors
in the system can be depicted.
Actors:
• User: This is the central actor who interacts with the system in various ways.
Administrator: This role manages users and other system functions, but isn't
directly involved in price prediction.
• Bank: This external system interacts with the user's bank account.
Use Cases:
• User Management: This allows the administrator to add, update or delete users.
• App Management: This allows management of the application itself, possibly
including settings or updates.
• Provide Login: This use case allows users to log in to the system.
• Check Login: This use case verifies the user's login credentials.
• Buy Bitcoin: This allows users to purchase bitcoin.
• Sell Bitcoin: This allows users to sell bitcoin.
• Price Monitor: This allows users to monitor the current price of bitcoin.
• Historical Data: This allows users to access historical data on bitcoin prices.
• Currency Conversion: This allows users to convert between different currencies.
20
• Notification Alerts: This allows users to set alerts for specific price movements or
other events.
• Risk Management: This may involve features to help users manage the risk
associated with bitcoin price movements.
• Price Prediction: This use case allows users to access price predictions for bitcoin.
21
5.3.2 Class Diagram
The Class Diagram is a foundational component of our Bitcoin price prediction report,
providing a structural representation of the system's architecture and the organization of
classes or objects within it. This diagram elucidates the key classes, their attributes, and the
associations between them, enabling stakeholders to comprehend the system's underlying
structure.
• User: This class represents a user of the money transfer system. It likely has attributes
such as an email address and user ID.
• Pin Transfer Service: This class seems to handle transfers using a PIN for verification.
It has methods for accepting a transaction, rejecting a transaction, and requesting a transaction.
It also has attributes that might be related to transaction data and external wallet keys.
• Btc Transfer Service: This class likely handles Bitcoin transfers. It has similar
methods to Pin Transfer Service for accepting, rejecting, and requesting transactions. It also
has attributes related to user IDs, transaction amounts, statuses, and wallet addresses.
Transaction Service: This class seems to be responsible for processing transactions, possibly
acting as a central service for both fiat and Bitcoin transfers. It has a method for processing
transactions and attributes related to user IDs, transaction statuses, and amounts.
Transaction: This class represents a transaction happening in the system. It has attributes
related to amounts (fiat and Bitcoin potentially), user IDs, and statuses.
• Offer Buy: This class might be related to buying Bitcoin. It has attributes such as user
ID, amount, price, and status.
• Offer Sell: This class might be related to selling Bitcoin. It has similar attributes to
Offer Buy.
• Incoming Transfer PLN and Incoming Transfer BTC: These classes likely represent
incoming transfers in Polish Zloty (PLN) and Bitcoin respectively. They have attributes
related to user IDs, statuses, and potentially amounts.
• Outgoing Transfer PLN and Outgoing Transfer BTC: These classes likely represent
outgoing transfers in Polish Zloty (PLN) and Bitcoin respectively. They have similar
attributes to Incoming Transfer PLN and Incoming Transfer BTC.
22
Fig 5.3.2 Class Diagram
It shows the interactions between different parts of the system as it retrieves data, trains a
model, and displays a prediction to the user. Here's a breakdown of the steps:
23
Fig 5.3.3 Sequence Diagram
The Sequence Diagram is an invaluable component of our Bitcoin price prediction report,
offering a time-ordered visualization of the interactions between system elements, including
users, external data sources, and the prediction system itself. This diagram highlights the
dynamic nature of the prediction process, showcasing how information flows and decisions
are made in real-time.
The Activity Diagram plays a pivotal role in our Bitcoin price prediction report, serving as a
comprehensive depiction of the operational processes within the prediction system. This
visual representation showcases the sequence of activities, decision points, and the flow of
data from input to output, elucidating how the system generates Bitcoin price predictions.
Sequence of Activities:
24
1. Download Datasets: This initial step involves acquiring historical Bitcoin price data.
2. Scale the data by Max-Min Normalization and Preprocessing: The downloaded
data goes through preprocessing to ensure it's suitable for machine learning algorithms. This
includes normalization using a Min-Max scaling technique. Min-Max scaling transforms the
data to a range between 0 and 1, which can improve the training process for some algorithms.
3. Split Data into Two: The preprocessed data is divided into two sets: training data
(80%) and test data (20%).
4. Train Data (80%): The larger portion of the data is used to train the machine learning
model. The model learns to identify patterns and relationships within the data to make
predictions.
5. Design Model: Here, a machine learning model is chosen and configured for Bitcoin
price prediction. The diagram doesn't specify the model type, but common choices include
linear regression, support vector machines (SVM), or neural networks like LSTMs.
6. Bitcoin Price Prediction: Once trained, the model is used to predict future Bitcoin
prices based on the patterns it learned from the training data. 7. End: The activity diagram
concludes after the price prediction.
25
CHAPTER-6
METHODOLOGY
26
6.1 Data Set
In this data set contains table with rows for each day (or hour). In each row, information like
the opening and closing price of Bitcoin, how high and low it went that day, and how much
Bitcoin was traded.
Structure:
The data is typically stored in a tabular format, like a CSV file or a database table. Each row
represents a specific time frame (e.g., day, hour), and each column represents a feature (e.g.,
closing price, RSI).
Bitcoin price data is inherently time-series data, meaning the order of data points matters.
This is important for algorithms that analyze trends and patterns over time.
27
Normalization and Feature Engineering:
Data may need to be normalized (scaled to a common range) to ensure different features
contribute equally to the model. Feature engineering might involve creating new features
based on existing ones to improve model performance.
Fig 6.2
28
6.3 Preprocessing
In this section of the report will load in the data, check for cleanliness, and then trim and clean
given dataset for analysis
During training, we use past Bitcoin data to teach our model how prices have behaved in the
past. We split this data into two parts: training data and validation data. The training data
teaches the model patterns in the Bitcoin price movements. We use different techniques like
regression, support vector machines, or neural networks to train the model.
After training, we test the model using the validation data, which it hasn't seen before. This
helps us see how well the model can predict prices it hasn't encountered. We measure its
performance using metrics like mean squared error or accuracy, depending on what we're
predicting. The aim is to find the model that works best with new, unseen data.
29
Fig 6.3 Training data
The prediction of Price of bitcoin, ML algorithm prediction model is effective because of the
30
6.6 Prediction
Various evaluation metrics are used to assess the performance of the predictive model, depending
on the nature of the prediction task
6.7 METHODS:
31
Here are the step-by-step instructions for using logistic regression to predict Bitcoin price:
Step 1: Data Collection Gather historical data related to Bitcoin prices, as well as relevant
features or predictors. This dataset should include Bitcoin price as the target variable and
other variables that might influence the price, such as trading volumes, market sentiment, or
external factors like news sentiment.
Step 2: Data Preprocessing Clean and preprocess the data. This includes handling missing
values, removing outliers, and normalizing or scaling numerical features to ensure they are on
a similar scale. You should also encode categorical variables if there are any.
Step 3: Data Splitting Divide the dataset into two parts: a training set and a testing set. The
training set is used to train the logistic regression model, and the testing set is used to evaluate
its performance. A common split is 80% for training and 20% for testing, but this can vary
based on the dataset size and specific requirements.
Step 4: Model Selection Choose logistic regression as the algorithm for predicting Bitcoin
prices. This is a supervised learning algorithm, and you'll be using it for regression, not
classification. Logistic regression predicts the probability of an event occurring, so you'll need
to adapt it for regression by changing the output to predict continuous price values.
Step 5: Model Training Train the logistic regression model using the training dataset. The
model will learn the relationship between the predictor variables and Bitcoin price. In the case
of regression, you'll need to use a variation of logistic regression known as linear regression.
Step 6: Model Evaluation Use the testing dataset to evaluate the model's performance.
Common regression metrics to evaluate the model include Mean Absolute Error (MAE),
Mean Squared Error (MSE), and Root Mean Squared Error (RMSE). These metrics will give
you an idea of how well the model is predicting Bitcoin prices.
Step 9: Model Deployment (Optional) If you intend to use the model in a real-world setting,
you may need to deploy it to a production environment. This involves creating an interface for
users to input data and receive predictions. It may also involve continuous monitoring and
updating of the model to ensure its accuracy.
Step10: Ongoing Monitoring and Maintenance Continuously monitor the model' performance
and update it as needed. The cryptocurrency market is highly dynamic, and factors influencing
Bitcoin price can change rapidly. Regularly retrain the model with new data to adapt to these
changes and maintain its accuracy.
In binary classification tasks, logistic regression calculates the probability that a given input
belongs to a certain class (in this case, whether the Bitcoin price will increase or decrease).
Implementation in the Code:
Logistic Regression is imported from sklearn.linear_model.
The model is instantiated using LogisticRegression().
It's trained on the training data (features X_train and labels Y_train) using the fit() method.
Predictions are made on both the training and validation sets using the predict_proba() method
to get probabilities for each class.
Evaluation metrics (ROC AUC score) are computed to assess the model's performance.
SVM chooses the extreme points/vectors that help in creating the hyperplane. These extreme
cases are called support vectors, and hence the algorithm is termed as Support Vector Machine.
33
Consider the below diagram in which there are two different categories that are classified
using a decision boundary or hyperplane.
Here are the step-by-step instructions for using support vector to predict Bitcoin price
Prediction.
Data Collection: Gather historical Bitcoin price data, which includes features like date, trading
volume, and other relevant indicators that can affect the price. You can obtain this data from
cryptocurrency exchanges or financial data providers.
Data Preprocessing:
1. 1.Clean the data by handling missing values and outliers.
2. 2.Convert the date into a numerical format that SVM can understand. Typically, this
involves encoding dates as timestamps.
3. 3.Normalize or standardize the features to ensure all of them are on a similar scale, which
can improve SVM performance.
Data Splitting: Split the dataset into two parts - a training set and a test set. The training set is
used to train the SVM model, and the test set is used to evaluate its performance.
Feature Selection: Choose the most relevant features for prediction. Feature selection can
improve the model's performance and reduce overfitting.
Model Selection: Choose a regression-based SVM model. The choice of kernel function
(linear, radial basis function, polynomial, etc.) can significantly impact the model's
performance.
Model Training: Train the SVM model on the training data using the chosen kernel and
hyperparameters. The goal is to find the hyperplane that best fits the data while minimizing
errors.
Model Evaluation:
Test the model's performance on the test dataset using evaluation metrics such as Mean
Squared Error (MSE), Root Mean Squared Error (RMSE), Mean Absolute Error (MAE), or
others suitable for regression tasks.
34
Visualize the model's predictions and compare them to the actual prices to assess its accuracy.
Hyperparameter Tuning: Fine-tune the SVM hyperparameters, such as the regularization
parameter (C), kernel parameters (e.g., gamma for RBF kernel), and the choice of kernel
function. You can use techniques like cross-validation to find the best hyperparameters.
Model Deployment: Once you are satisfied with the model's performance, deploy it in a
production environment, if needed, to make real-time predictions.
Regular Updating: Bitcoin prices are highly volatile and can change rapidly. Therefore, it's
essential to regularly update your model with new data to keep it relevant and accurate.
Monitor and Maintain: Continuously monitor the model's performance and retrain it
periodically as new data becomes available. You may need to adjust hyperparameters or even
consider retraining the model from scratch as the market conditions change.
6.7.3 XG Boost:
XGBoost (Extreme Gradient Boosting) is a powerful machine learning algorithm that can be
used for predicting various types of data, including financial time series data like Bitcoin
prices.
Here's a step-by-step guide on how to use XGBoost to predict Bitcoin prices:
Data Collection: Obtain historical Bitcoin price data. You can use various sources such as
cryptocurrency exchanges, financial data providers, or APIs like Coinbase, Binance, or Alpha
Vantage. Ensure your dataset includes features like date, opening price, closing price, high
price, low price, and trading volume.
Data Preprocessing: Clean and preprocess the data to handle missing values, outliers, and
noisy data. You may also want to calculate additional features such as moving averages or
technical indicators that could help in predicting prices.
Data Splitting: Split your dataset into two parts: a training set and a testing set. The training
set is used to train the model, and the testing set is used to evaluate its performance.
35
Feature Engineering: Feature engineering involves selecting the most relevant features and
transforming them to better represent the underlying patterns in the data. XGBoost can handle
both numerical and categorical features.
2. Set hyperparameters for the XGBoost model. You can fine-tune these hyperparameters
through cross-validation.
3. Train the model
Model Evaluation: After training, you should evaluate the model's performance on the testing
set. You can use metrics like Mean Squared Error (MSE), Root Mean Squared Error (RMSE),
or other relevant metrics for regression problems.
Visualization and Analysis: Visualize the model's predictions compared to the actual Bitcoin
prices. You can also plot feature importance to understand which features had the most impact
on the model's predictions.
Predicting Future Prices: To predict future Bitcoin prices, you can use your trained model to
make predictions. You'll need to prepare new data with the same features used during training,
and then use the model. predict() function to obtain predictions.
36
dataset. Instead of relying on a single decision tree, the random forest collects the result from
each tree and expects the final output based on the majority votes of predictions.
Fig 6.4
Before understanding the working of the random forest algorithm in machine learning, we
must look into the ensemble learning technique. Ensemble simply means combining
multiple models. Thus a collection of models is used to make predictions rather than an
individual model.
Ensemble uses two types of methods:
Bagging
It creates a different training subset from sample training data with replacement & the final
output is based on majority voting. For example, Random Forest.
37
Boosting
It combines weak learners into strong learners by creating sequential models such that the
final model has the highest accuracy. For example, ADA BOOST, XG BOOST.
6.7.5 LSTM
LSTMs Long Short-Term Memory is a type of RNNs Recurrent Neural Network that can
detain long-term dependencies in sequential data. LSTMs are able to process and analyze
sequential data, such as time series, text, and speech. They use a memory cell and gates to
control the flow of information, allowing them to selectively retain or discard information as
needed and thus avoid the vanishing gradient problem that plagues traditional RNNs. LSTMs
are widely used in various applications such as natural language processing, speech
recognition, and time series forecasting.
The forget gate decides which information to discard from the memory cell. It is trained to
open when the information is no longer important and close when it is. The output gate is
responsible for deciding which information to use for the output of the LSTM. It is trained to
open when the information is important and close when it is not.
The gates in an LSTM are trained to open and close based on the input and the previous
hidden state. This allows the LSTM to selectively retain or discard information, making it
more effective at capturing long-term dependencies.
38
Structure of LSTM
An LSTM (Long Short-Term Memory) network is a type of RNN recurrent neural network
that is capable of handling and processing sequential data. The structure of an LSTM network
consists of a series of LSTM cells, each of which has a set of gates (input, output, and forget
gates) that control the flow of information into and out of the cell. The gates are used to
selectively forget or retain information from the previous time steps, allowing the LSTM to
maintain long-term dependencies in the input data.
The LSTM cell also has a memory cell that stores information from previous time steps and
uses it to influence the output of the cell at the current time step. The output of each LSTM
cell is passed to the next cell in the network, allowing the LSTM to process and analyze
sequential data over multiple time steps.
Applications of LSTM
Long Short-Term Memory (LSTM) is a highly effective Recurrent Neural Network (RNN)
that has been utilized in various applications. Here are a few well-known LSTM applications:
Language Simulation: Language support vector machines (LSTMs) have been utilized for
natural language processing tasks such as machine translation, language modeling, and text
summarization. By understanding the relationships between words in a sentence, they can be
trained to construct meaningful and grammatically correct sentences.
Voice Recognition: LSTMs have been utilized for speech recognition tasks such as speech to-
text-to-text-transcription and command recognition. They may be taught to recognize patterns
in speech and match them to the appropriate text.
Sentiment Analysis: LSTMs can be used to classify text sentiment as positive, negative, or
neutral by learning the relationships between words and their associated sentiments.
Time Series Prediction: LSTMs can be used to predict future values in a time series by
learning the relationships between past values and future values.
Video Analysis: LSTMs can be used to analyze video by learning the relationships between
frames and their associated actions, objects, and scenes.
39
6.7.6 ANN:
Artificial Neural Networks (ANNs) are a class of machine learning algorithms inspired by the
structure and function of the human brain. They consist of interconnected nodes, or neurons,
organized in layers: input layer, hidden layers, and output layer. ANNs are used in various
fields, including finance, for tasks such as prediction, classification, and pattern recognition.
Data Preparation: Gather historical Bitcoin price data and preprocess it by normalizing the
features and splitting it into training and testing sets.
Input Layer: The number of neurons in the input layer should correspond to the number of
input features.
Hidden Layers: Decide on the number of hidden layers and the number of neurons in each
hidden layer. Experimentation may be needed to find the optimal architecture.
Activation Functions: Choose appropriate activation functions for the neurons in the hidden
layers (e.g., ReLU, sigmoid, tanh) to introduce non-linearity into the model.
Output Layer: Typically, a single neuron in the output layer is used for regression tasks like
price prediction.
Training the Neural Network:
Forward Propagation: Pass the input data through the network to obtain predictions.
Loss Function: Define a loss function (e.g., Mean Squared Error) to measure the difference
between predicted and actual prices.
Backpropagation: Use an optimization algorithm (e.g., Stochastic Gradient Descent) to
minimize the loss function by adjusting the weights and biases of the network through
backpropagation.
Hyperparameter Tuning: Experiment with learning rate, batch size, and regularization
techniques to improve model performance and prevent overfitting.
40
Model Evaluation: Evaluate the trained model's performance using metrics such as Mean
Absolute Error (MAE), Mean Squared Error (MSE), or Root Mean Squared Error (RMSE) on
the testing dataset.
Prediction: Use the trained ANN to make predictions on future Bitcoin prices based on the
most recent data available.
Monitoring and Refinement: Continuously monitor the model's performance and refine it by
adjusting hyperparameters, modifying the network architecture, or adding new features to
improve prediction accuracy.
6.8 Python
Python is a widely used general-purpose, high level programming language. It was created by
Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was
designed with an emphasis on code readability, and its syntax allows programmers to express
their concepts in fewer lines of code.
Python is a programming language that lets you work quickly and integrate systems more
efficiently.
There are two major Python versions: Python 2 and Python 3. Both are quite different.
41
Simple
Robust:
• Exceptional handling features
• Memory management techniques in built
42
6.8.2 Numpy
NumPy is a Python library used for working with arrays.
It also has functions for working in domain of linear algebra, fourier transform, and matrices.
NumPy was created in 2005 by Travis Oliphant. It is an open source project and you can use it
freely.
NumPy stands for Numerical Python.
In Python we have lists that serve the purpose of arrays, but they are slow to process.
NumPy aims to provide an array object that is up to 50x faster than traditional Python lists.
The array object in NumPy is called ndarray, it provides a lot of supporting functions that make
working with ndarray very easy.
Arrays are very frequently used in data science, where speed and resources are very important.
NumPy is a Python library and is written partially in Python, but most of the parts that require
fast computation are written in C or C++.
6.8.3 matplotlib
Matplotlib is a low level graph plotting library in python that serves as a visualization utility.
Matplotlib was created by John D. Hunter.
Matplotlib is open source and we can use it freely.
Matplotlib is mostly written in python, a few segments are written in C, Objective-C and
Javascript for Platform compatibility.
6.8.4 seaborn
Seaborn is a Python data visualization library based on matplotlib. It provides a high-level
interface for drawing attractive and informative statistical graphics.
seaborn is a library for making statistical graphics in Python. It provides a high-level interface
to matplotlib and integrates closely with pandas data structures. Functions in the seaborn
library expose a declarative, dataset-oriented API that makes it easy to translate questions
about data into graphics that can answer them. When given a dataset and a specification of the
43
plot to make, seaborn automatically maps the data values to visual attributes such as color,
size, or style, internally computes statistical transformations, and decorates the plot with
informative axis labels and a legend. Many seaborn functions can generate figures with
multiple panels that elicit comparisons between conditional subsets of data or across different
pairings of variables in a dataset. seaborn is designed to be useful throughout the lifecycle of a
scientific project. By producing complete graphics from a single function call with minimal
arguments, seaborn facilitates rapid prototyping and exploratory data analysis. And by
offering extensive options for customization, along with exposing the underlying matplotlib
objects, it can be used to create polished, publication quality figures.
6.8.5 Tensor flow
TensorFlow is an open-source library for fast numerical computing.
It was created and is maintained by Google and was released under the Apache 2.0 open
source license. The API is nominally for the Python programming language, although there is
access to the underlying C++ API.
Unlike other numerical libraries intended for use in Deep Learning like Theano, TensorFlow
was designed for use both in research and development and in production systems, not least of
which is RankBrain in Google search and the fun DeepDream project.
It can run on single CPU systems and GPUs, as well as mobile devices and large-scale
distributed systems of hundreds of machines.
6.8.6 keras
Keras runs on top of open source machine libraries like TensorFlow, Theano or Cognitive
Toolkit (CNTK). Theano is a python library used for fast numerical computation tasks.
TensorFlow is the most famous symbolic math library used for creating neural networks and
deep learning models. TensorFlow is very flexible and the primary benefit is distributed
computing. CNTK is deep learning framework developed by Microsoft. It uses libraries such
as Python, C#, C++ or standalone machine learning toolkits. Theano and TensorFlow are very
powerful libraries but difficult to understand for creating neural networks.
Keras is based on minimal structure that provides a clean and easy way to create deep learning
models based on TensorFlow or Theano. Keras is designed to quickly define deep learning
models. Well, Keras is an optimal choice for deep learning applications.
44
Benefits
Keras is highly powerful and dynamic framework and comes up with the following
advantages
6.8.6.1 Larger community support.
6.8.6.2 Easy to test.
6.8.6.3 Keras neural networks are written in Python which makes things simpler.
6.8.6.4 Keras supports both convolution and recurrent networks.
6.8.6.5 Deep learning models are discrete components, so that, you can combine into many
ways.
df = pd.read_csv('bitcoin.csv') df.head()
df.info()
plt.subplots(figsize=(20,10)) for
i, col in enumerate(features):
plt.subplot(2,2,i+1)
sb.distplot(df[col])
plt.show()
plt.subplots(figsize=(20,10)) for
i, col in enumerate(features):
plt.subplot(2,2,i+1)
sb.boxplot(df[col])
plt.show()
df.head()
data_grouped = df.groupby('year').mean()
plt.subplots(figsize=(20,10)) for i, col in
enumerate(['Open', 'High', 'Low', 'Close']):
plt.subplot(2,2,i+1) data_grouped[col].plot.bar()
plt.show()
plt.pie(df['target'].value_counts().values,
labels=[0, 1], autopct='%1.1f%%') plt.show()
plt.figure(figsize=(10, 10))
print(f'{models[i]} : ')
print('Training Accuracy : ', metrics.roc_auc_score(Y_train,
models[i].predict_proba(X_train)[:,1]))
print('Validation Accuracy : ', metrics.roc_auc_score(Y_valid,
models[i].predict_proba(X_valid)[:,1]))
print()
Plt.show()
47
CHAPTER-7
RESULTS
48
Fig 7.1 Graph
This graph typically display the closing price for each 5-minute period, allowing traders and
investors to track the price changes over a brief time frame. Here's how you can interpret such
a graph:
X-Axis (Time): The horizontal axis represents time. Each tick or bar on the x-axis corresponds
to a 5-minute period. You'll see a sequence of these bars going from left to right, showing the
progression of time.
Y-Axis (Price in Dollars): The vertical axis represents the price of Bitcoin in dollars. The scale
on this axis shows the range of prices over the specified time frame.
49
Each 5-minute interval is often represented as a candlestick bar, which has four main
components:
1. Open Price: The first point on the bar's vertical line, often on the left side, represents
the opening price of Bitcoin at the beginning of that 5-minute interval.
2. Close Price: The second point on the bar's vertical line, often on the right side,
represents the closing price of Bitcoin at the end of that 5-minute interval.
3. High Price: The top point of the vertical line represents the highest price reached
during that 5-minute period.
4. Low Price: The bottom point of the vertical line represents the lowest price reached
during that 5-minute period.
50
4. Outliers, if present, indicate extreme price movements that fall outside the typical
range of Bitcoin prices during the 5-minute intervals.
5. The shape of the boxplot can also provide information about the skewness of the data.
A skewed distribution may have an asymmetrical boxplot.
Pie chart visualizes the distribution of the 'target' variable. The pie chart will show the
distribution of 0s and 1s in the 'target' column, which represents whether the price increased or
not based on your defined criteria. It can provide a visual representation of the proportion of
price increases (1s) and non-increases (0s) in your dataset.
51
Fig 7.5 Heatmap
The heatmap will visualize the highly correlated features in the Data Frame. Each cell in the
heatmap will contain a True or False value, indicating whether the correlation between two
features exceeds 0.9. If True, it means the features are highly correlated. The annotations in
the cells will provide the exact correlation values between these highly correlated features,
helping you identify and understand their relationships. This visualization can be valuable for
feature selection and identifying multicollinearity in the dataset.
52
Fig 7.6 bar plots
It is a 2x2 grid of bar plots, where each subplot shows the average values of one of the price
metrics ('Open,' 'High,' 'Low,' or 'Close') for each year. This visualization helps you compare
and analyze the yearly trends of these metrics in your data. It can be particularly useful for
identifying trends, seasonality, or patterns over different years for these financial metrics.
53
A confusion matrix is a table that is used to visualize the performance of an algorithm. In
classification tasks, the confusion matrix shows the number of correct and incorrect
predictions made by the model.
The rows of the matrix represent the actual classes, and the columns represent the predicted
classes. So, for example, the value in the top-left corner (17) represents the number of
instances where the actual class was 1, and the predicted class was also 1. These are called
true positives (TP).
Conversely, the value in the bottom right corner (40) represents the number of instances where
the actual class was 0, but the model predicted 1. These are called false positives (FP).
54
also only 60 instances where the model correctly classified an instance as class 0 (Actual 0,
Predicted 0).
• Incorrect Predictions: There seems to be a significant number of incorrect
predictions. The model predicted a lot of class 1 instances that were actually class 0 (63) and
vice versa (50).
55
predictions based on the lighter colored areas of the matrix. o Top right corner (30):
Represents the number of instances where the actual class was 1, but the model predicted 0.
These are called false negatives (FN). o Bottom left corner (29): Represents the number
of instances where the actual class was 0, but the model predicted 1. These are called false
positives (FP).
LSTM:
Fig.7.10 LSTM
Bitcoin price prediction using Long Short-Term Memory (LSTM), a type of artificial neural
network.
The x-axis of the graph is labeled "Date" and it shows dates ranging from roughly January
2021 to May 2023. The y-axis is labeled "Price" and it shows Bitcoin price in a range of
10,000 to 70,000.
There are four lines on the graph. The two solid lines represent the actual Bitcoin price. The
blue line shows the "Actual Train" price and the green line shows the "Actual Test" price. The
two dashed lines represent the predicted Bitcoin price. The orange line shows the "Predicted
Train" price and the purple line shows the "Predicted Test" price.
56
It appears that the LSTM model was trained on a set of historical Bitcoin prices. The blue line
("Actual Train") shows the real price compared to the model's prediction on the training data
("Predicted Train" - dashed orange line). The green line ("Actual Test") shows the real price
compared to the model's prediction on a separate test data set ("Predicted Test" - dashed
purple line).
By comparing the actual and predicted prices, we can see how well the LSTM model
performed at predicting the price of Bitcoin. It appears that the model performed well on the
training data set (blue and orange lines are very close together), but did not perform as well on
the test data set (green and purple lines are further apart). This suggests that the model may be
overfitting the training data.
Overall, the graph shows that an LSTM model can be used to predict the price of Bitcoin, but
it is important to be aware of the limitations of such models.
57
CHAPTER-8
CONCLUSION AND FUTURE SCOPE
58
Cryptocurrency, such as Bitcoin, has established itself as the leading role of decentralization.
There are many cryptocurrencies sprang up after Bitcoin such as Ethereum and Ripple.
Because of the significant uncertainty in its prices, many people hold them as a means of
speculation. Therefore, it is critically important to understand the internal features and
predictability of those cryptocurrencies. In this study, we use two distinct artificial intelligence
frameworks, namely, fully connected Artificial Neural Network (ANN) and Long Short-
TermMemory (LSTM) to analyze and predict the price dynamics of Bitcoin, Ethereum, and
Ripple. We showed that the ANN and LSTM models are comparable and both reasonably well
enough in price prediction, although the internal structures are different. Then we further
analyze the influence of historical memory on model prediction. We find that ANN tends to
rely more on long- term history while LSTM tends to rely more on short-term dynamics,
which indicates the efficiency of LSTM to utilize useful information hidden in historical
memory is stronger than ANN. However, given enough historical information ANN can
achieve a similar accuracy, compared with LSTM. This study provides a unique
demonstration that Cryptocurrency market price is predictable. However, the explanation of
the predictability could vary depending on the nature of the involved machine-learning model.
In this project, there's a lot of potential for growth. First, we can look at adding more factors
that might affect Bitcoin's price, like checking how people talk about it on social media or in
the news. Then, we need to make sure our models are working well by trying out different
ways to measure how accurate they are and adjusting their settings to make them better. We
could also combine different models together to make them stronger. Since Bitcoin's price
changes over time, we should use methods that can understand these patterns better. It might
also be worth exploring more advanced types of computer learning to see if they can help us
predict Bitcoin's price even more accurately. Sometimes, the data we have isn't balanced, so
we need to figure out ways to handle that to make our models more reliable. Once our models
are good enough, we need to think about how we can use them in the real world and make
sure they keep working well even as things change. It's also important to explain why our
models make the decisions they do, so people can trust them more. Lastly, we need to keep
good records of everything we do and work with others to get feedback and make our project
even better.
59
REFERENCES
1. Greaves, A., & Au, B. (2015). Using the bitcoin transaction graph to predict the
price of bitcoin. No Data.
3. Shah, D., & Zhang, K. (2014, September). Bayesian regression and Bitcoin. In
5. Adebiyi AA, Ayo C K, Adebiyi MO, Otoitid SO. Stock price prediction using a
neural network with hybridized market indicators. Journal of Emerging Trends
in Computing and Information Sciences, 2012, 3(1):1-9
6. Adebiyi AA, Ayo C K, Adebiyi MO, Otoitid SO. Stock price prediction using a
neural network with hybridized market indicators. Journal of Emerging Trends
in Computing and Information Sciences, 2012, 3(1):1-9
60
7. Ariya AA, Adewunmi AO, Ayo CK. Stock price prediction using the ARIMA
model. In Axim-AMSS 16th IEEE International Conference on Computer
Modeling and Simulation (Axim), 2014, pp. 106-112
8. Ron, D., & Shamir, A. (2013, April). Quantitative analysis of the full bitcoin
transaction graph. In the International Conference on Financial Cryptography
and Data Security (pp. 6-24). Springer, Berlin, Heidelberg.
9. H. White, “Economic prediction using neural networks: The case of IBM daily
stock returns,” in Neural Networks, 1988., IEEE International Conference on.
IEEE, 1988, pp. 451–458
10. Kaastra and M. Boyd, “Designing a neural network for forecasting financial
and economic time series,” Neurocomputing, vol. 10, no. 3, pp. 215–236, 1996.
11. H. White, “Economic prediction using neural networks: The case of ibm daily
stock returns,” in Neural Networks, 1988., IEEE International Conference on.
IEEE, 1988, pp. 451–458.
12. Cheung, Y. W., Chinn, M. D., & Pascual, A. G. (2005). Empirical exchange
rate models of the nineties: Are any fit to survive? Journal of international
money and finance, 24(7), 1150-1175.
13. Velankar Siddhi, Sakshi Valecha and Shreya Maji, "Bitcoin price prediction
using machine learning", 2018 20th International Conference on Advanced
Communication Technology (ICACT), 2018,
14. Chen Zheshi, Li Chunhong and Sun Wenjun, "Bitcoin price prediction using
machine learning: An approach to sample dimension engineering", Journal of
Computational and Applied Mathematics, vol. 365, pp. 112395, 2020,
61
15. Suhwan Ji, Jongmin Kim and Hyeonseung Im, "A comparative study of bitcoin
price prediction using deep learning", Mathematics, vol. 7.10, pp. 898, 2019,
18. Edwin Sin and Wang Lipo, "Bitcoin price prediction using ensembles of neural
networks", 2017 13th International conference on natural computation fuzzy
systems and knowledge discovery (ICNC-FSKD), 2017,
19. Aniruddha Dutta, Kumar Saket and Basu Meheli, "A gated recurrent unit
approach to bitcoin price prediction", Journal of Risk and Financial
Management, vol. 13.2, pp. 23, 2020,
20. Temesgen Awoke et al., "Bitcoin price prediction and analysis using deep
learning models", Communication Software and Networks, pp. 631640, 2021,
62
63