 Open Access
 Authors : Rishima Mathur , Tanvi Takavane , Trisha Shah , Ravikant Suryawanshi
 Paper ID : IJERTV11IS050378
 Volume & Issue : Volume 11, Issue 05 (May 2022)
 Published (First Online): 03062022
 ISSN (Online) : 22780181
 Publisher Name : IJERT
 License: This work is licensed under a Creative Commons Attribution 4.0 International License
Stocks and Cryptocurrency Price Prediction using Long Short Term Memory
Prof. Ravikant Suryawanshi
Department of Electronics and Telecommunication MKSSSs Cummins College of Engineering
Pune, India
Trisha Shah
Department of Electronics and Telecommunication MKSSSs Cummins College of Engineering
Pune, India
Tanvi Takavane
Department of Electronics and Telecommunication MKSSSs Cummins College of Engineering
Pune, India
Rishima Mathur
Department of Electronics and Telecommunication MKSSSs Cummins College of Engineering
Pune, India
AbstractStocks describe the ownership certificate of a company. Units of Stocks are called shares. Stocks can be bought and sold using the Demat account. Cryptocurrency is encrypted data that denotes units of currency. Cryptocurrency is a tradable digital asset developed using blockchain technology. Investments in stocks and cryptocurrency enable people to gain high returns but it also involves a risk factor. As the value of these assets varies every day; it makes it interesting to predict their price and analyze the data. The price of stocks and cryptocurrency can be predicted using LSTM, RNN, ARIMA, CNN, etc. We have used LSTM architecture to predict the prices and the accuracy results are computed using Root Mean Square Error. For Stocks, we achieved an average RMSE near about 0.029 and for the cryptocurrency of about 0.061.
KeywordsLong ShortTerm Memory (LSTM); Stocks; Cryptocurrency
I. INTRODUCTION
Nowadays millions of people invest in stocks and cryptocurrencies. Successful prediction in price will help to yield significant profits. The evolution of Deep Learning has made life easier.It allows to work with unstructured data, is costeffective, and simplifies advanced analytics. With this paper, we are presenting our work on price prediction of Stocks and Cryptocurrency and developed a web app for the same. We have worked with LSTM ( Long Short Term Memory) in our model for price prediction. Long short term memory (LSTM) is an improved subset of the RNN method that is used in the deep learning area. LSTM networks are a type of recurrent neural network capable of learning order dependence in sequence prediction problems. The steps involved in predicting price are creating a data frame, training, and testing, implementing of LSTM network, and prediction. We have developed a web app using Streamlit which is an opensource framework that usually goes well with the data science domain.
LSTM to study the trends in Bitcoin cryptocurrency.It normalizes and visualizes the trends.
The paper Deep Learning for Stock Market Prediction by M.Nabipour,P. Nayyeri,H. Jabani,A. Mosavi,E. Salwana,Shahab S studied and employed different machine learning algorithms for prediction.LSTM was found to fit the model more accurately than other machine learning algorithms.
The paper Ascertaining price formation in cryptocurrency markets with Deep Learning by Fan Fanga,Waichung Chung,Carmine Ventre, Michail Basios,Leslie Kanthan,Lingbo Li,Fan Wu uses a successful combination of an autoencoder and stepwise retraining method to overcome the degradation of predictive ability of live data due to nonstationary function of the order book.A constant accuracy of predicting the movement of the average price is 78%.

PROPOSED METHODOLOGY
The proposed methodology is shown in Fig 1. It shows the use of the LSTM (Long Short Term Memory) algorithm.
Our proposed methodology helps in predicting the price of Stocks and Cryptocurrency. This will help people to gain highreturns and invest more in the future.

Initially we start by importing all the necessary libraries.Our model is designed for two portfolios:

Stocks Dataset is uploaded, Dataframe is created, Datasetis split for training and testing,

LSTM architecture is developed and implemented and further open and close price is predicted and represented graphically. 2)Cryptocurrency Dataset is uploaded, Dataframe is created, Dataset is split for training and testing, LSTM architecture is developed and implemented and further open and close price is predicted and represented graphically.

LITERATURE SURVEY
The paper Predicting Price of Cryptocurrency – A Deep Learning Approach by Samiksha Marne, Delisa Correia, Shweta Churi, and Joanne Gomes employs
Fig. 1. Methodology

LSTM Architecture
Fig. 2. LSTM Architecture
Fig 2 shows the architecture of a single LSTM cell.The recurrent neural network(RNN) uses backpropagation in timeto estimate the time series prediction which gives rise to exploding and vanishing gradients. This problem is solved by using a Long Short Term Memory(LSTM) algorithm that controls the flow of data through a cell using three gates: Forget gate, Input gate, and Output gate, which allows us to maintain constant error through each LSTM cell during backpropagation. Thus, the issue of vanishing and exploding gradients is solved using an LSTM architecture.

The Forget Gate:

It filters the information which LSTM does notrequire to make further predictions.

A sigmoid function is used which forces the valuebetween 0 and 1.

The previous cell output h(t1) and input to currentcell x(t) are input to the sigmoid.

The values that are close to zero are forgotten andvalues close to one are remembered. 2.The Input Gate:



A vector of previous cell output h(t1) and input to current cell x(t) is created using the tanh function.

This vector is multiplied by the sigmoid functionwhich acts as a filter.

This value is added to the cell state of the current cell.

The Output Gate:

A vector of the current cell state is created using thetanh function.

The vector is multiplied by a sigmoid function whichacts as a filter.

This value is given as the output of this cell and asthe hidden state of the next cell.


RESULTS
The LSTM model was implemented in Python using Google Collaboratory. A Keras tuner was used to fine tune the hyperparameters. The performance metrics used to evaluate the model are Mean Absolute Error, Mean Square Error, Root Mean Square Error, and R2 score.The website is developed using Streamlit and Ngrok is used to host the website.

Stock Prediction
The realtime data used for prediction is taken from yahoo finance. The five features of the dataset are open price, high price, low price, close price, and volume traded for that day.Fig. 3 shows a sample of Google Dataset.
Fig. 3. Sample of Google Stock Dataset
The dataset is then split into training and testing data. Table I shows the root mean square error value(RMSE) for different train and test ratios. It is found that the 8020 ratio shows theleast RMSE.
TABLE I. RMSE FOR DIFFERENT TRAIN TEST PERCENTAGES FOR GOOGLE STOCK
Train test split
RMSE
9010
0.0233
8020
0.0198
7030
0.0231
6040
0.0213
The dataset is then normalized and given to the LSTM model for training on train dataset and then the trained model is used to make predictions on the test dataset. Fig.
4 shows the learning curve for the stock prediction model. The LSTM model implemented has160 neurons,

dropouts,0.001 learning rate,adam optimizer, and linear activation function. These parameters were decided using the Keras tuner.
Fig. 4. Learning Curve of LSTM model for stocks
The performance metrics are then evaluated for the model. Table II shows the performance metrics for different stocks for8020 training testing split.
Stock
MAE
MSE
RMSE
R2 Score
Tesla
0.034
0.0022
0.047
96.03%
TCS
0.028
0.0016
0.040
97.73%
Google
0.014
0.00035
0.018
97.182%
Apple
0.016
0.00044
0.021
94.96%
Infosys
0.015
0.00039
0.019
95.77%
TABLE II. ERRORVALUES FOR DIFFERENT STOCKS
In table II MAE, MSE, RSME, and R2 value is calculated for Tesla, TCS, Google, Apple, and Infosys Stocks.
The explanation of these terms is given below

MAE MAE stands for Mean Absolute Error. It is a model evaluation metric that is used with regressionmodels.

MSE MSE is Mean Square Error. It is a risk function corresponding to an expected value of the squared loss. It measures the average of all the squares of errors.

RSME It is the Root Mean Square Error. It is the measure of how far the predicted errors are. It tells us how concentrated the data is around the line.

R2 It stands for R squared which refers to the coefficient of multiple determination for multipleregression.

The website results are shown below
Fig. 5. Selecting Stock to predict
Fig. 6. Google Stock dataset visualization
In the dashboard of stocks selection of a stock is available. Also, you can choose which price is to be predicted as shown in Fig. 5. Fig. 6 shows the plot ofopen and closed prices over the years.
Fig. 7. Visualization of predicted price of Google stock
Fig. 7 shows the plot of actual and predicted price of Gogglestock.


Cryptocurrency Prediction
The realtime data used for prediction is taken from yahoo finance. The five features of the dataset are open price, high price, low price, close price, and volume traded for that day.Fig. 5 shows a sample of the Bitcoin Dataset.
Fig. 8. Sample of Bitcoin Cryptocurrency Dataset
The dataset is then split into training and testing data. Table III shows the root mean square error value(RMSE) for different train and test ratios. It is found that the 8020 ratio shows the least RMSE.
TABLE III. RMSE FOR DIFFERENT TRAIN TEST PERCENTAGES FOR
BITCOIN
Train test split
RMSE
9010
0.067
8020
0.061
7030
0.063
6040
0.069
The dataset is then normalized and given to the LSTM model for training on train dataset and then the trained model is used to make predictions on the test dataset. Fig.
6 shows the learning curve for the cryptocurrency prediction model.The LSTM model implemented has 96 neurons, 0.1 dropouts,0.01 learning rate,adam optimizer, and linear activation function. These parameters were decided using the Keras tuner.
Fig. 9. Learning Curve of LSTM model for cryptocurrency
The performance metrics are then evaluated for the model. Table IV shows the performance metrics for different stocksfor an 8020 training testing split.
TABLE IV. ERRORVALUES FOR DIFFERENT CRYPTOCURRENCY
Cryptocurrency
MAE
MSE
RMSE
R2
Score
Bitcoin
0.0427
0.0036
0.060
97.77%
Ethereum
0.0431
0.0035
0.059
96.59%
Ripple
0.0421
0.0040
0.063
96.96%
In table IV MAE, MSE, RSME, and R2 value is calculated for Bitcoin,Ethereum and Ripple cryptocurrencies. The explanation of these terms is given below

MAE MAE stands for Mean Absolute Error. It is a model evaluation metric that is used with regressionmodels.

MSE MSE is Mean Square Error. It is a risk function corresponding to an expected value of the squared loss. It measures the average of all the squares of errors.

RSME It is the Root Mean Square Error. It is the measure of how far the predicted errors are. It tells us how concentrated the data is around the line.

R2 It stands for R squared which refers to the coefficient of multiple determination for multipleregression.
The website results are shown below
Fig. 10. Select cryptocurrency to predict
Fig. 11. Bitcoin dataset visualization
In the dashboard of cryptocurrency, selection of a cryptocurrency to be predicted. Also, you can choose which price is to be predicted as shown in Fig. 10. Fig. 11 shows theplot of open and closed prices over the years.
Fig. 12. Visualization of predicted price of bitcoin
Fig. 12 shows the plot of actual and predicted price of Bitcoindataset.


CONCLUSION & FUTURE SCOPE
The performance of the regression model is measured using three error metrics(MAE,MSE,RMSE) which give us the prediction errors.Lower the values , better is the model.These values are closer to zero so our models are good fit.R2 score determines the proportion of variance in the dependent variable that can be explained by the independent variable,higher the
R2 score, better the model.The R2 values are closer to 100 so our model explains almost all variability around its mean.Price prediction of stocks and cryptocurrency will open doors for more individuals to invest and increase their profits.
This software is a boon to the society which makes prediction easier.To develop an app predicting stocks + cryptoprice in future.A revenue based model can be implemented.
Recommendation systems which would enable users to makean informed decision.

REFERENCES


LEARNING, IOP Conference Series: Materials Science and Engineering,2020
[7] Abhinav Sagar, Cryptocurrency Price Prediction Using Deep Learning, 2019 [8] Gaurav Singhal, Introduction to LSTM Units inRNN, 2020