0% found this document useful (0 votes)
16 views7 pages

Final Papre LSTM BiLSTM

Uploaded by

Anuj Rawat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

Final Papre LSTM BiLSTM

Uploaded by

Anuj Rawat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

An Advance Approach For Nifty50 Index

Prediction Using Machine Learning


Upendra Singh
(Department of computer science and engineering.
Graphic Era Deemed to be Univ.)
Dehradun, India [email protected]
Vikash Tripathi
(Department of computer science and engineering.
Graphic Era Deemed to be Univ.)
Dehradun, India [email protected]

Bhaskar Pant
(Department of computer science and engineering.
Graphic Era Deemed to be Univ.)
Dehradun, India [email protected]
Anuj singh
(Department of computer science.
Graphic Era Deemed to be Univ.)
Dehradun, India [email protected]
Abstract— Since stock markets are very generally acknowledged a lot of consideration in recent
dynamic, complicated, volatile and nonlinear, times, owing to their ability to recognize subtle trends and
stock market forecasting requires extensive structures in the data, such as non-linearity and sheer
research using the latest methods and complexity in time series forecasting. As a result, they
technologies. Various strategies have been have been widely implemented in many disciplines and are
developed to predict stock price changes, used to predict the weather, the stock market, etc. LSTM
including machine learning, deep learning, and has been effectively applied to time-series forecasting. We
classical data analysis. For learning the want to investigate how Bi-directional LSTM networks
fluctuation pattern of stock prices, we proposed may be used to predict stock prices. The accuracy of the
and evaluated a time series prediction model. proposed approach is then computed in comparison to the
Recurrent neural networks are well suited for existing methods additionally, data mining technologies
stock price prediction; they use time series data aid in the prediction of future trends and behaviors,
and can store prior information in the hidden assisting businesses in making knowledge-driven decisions
layer. We apply LSTM with minimal memory [15] [26]. Investors could see substantial rewards from a
within the recurrent neural network to obtain reliable stock market forecast. Using machine learning,
long-term confidence by solving the gradient which generates market values that are close to the actual
vanishing problem. To predict stock market values, we can predict the stock market with a high degree
values, we proposed the Bi-LSTM (bidirectional of accuracy. The use of machine learning in stock market
LSTM), in which the hidden layer is added in the forecasting serves as evidence of its efficacy and
opposite direction from the data flow. We take precision [5] [14]. The data set used for machine learning
stock price, open, close, high, low and traded is a crucial component. The data set should be as accurate
volume of Nifty50 index as input and use as possible because even minor changes in the data could
Tensorflow in this experiment to train the have a big impact on the output. We acquired the data set
proposed stock price prediction model. We for our experiment from the National Stock
analyze various valuation metrics like MAE, MSE Exchange(NSE) website. Multiple time scale features can
and RMSE. We found that the Bi-LSTM model be learned using a hybrid end-to-end neural network to
has a lower error rate than the LSTM model. We forecast stock values. Deep neural networks may map
also calculated the R2Score and R2adjusted,
non-linear functions and are non-linear function
which is much closer to 1 for the Bi-LSTM model
approximations. Through a process of self-learning, they
than for the LSTM model. For the training and
can hold memories and can identify hidden patterns as
testing models in this paper, we used LSTM and
well the underlying dy- namics present within data. The
bidirectional LSTM using the "adam" optimizer.
amount and degree of non- uniformity in the stock market
The purpose of this paper is to predict the
data are huge. To handle this dynamic data a system is
behavior of NSE-Nifty50 index by showing plots
required, that can recognize trends and fluctuations. Due to
with bidirectional LSTM and normal LSTM. As a
the considerable financial advantages, stock price
result of our experiment, we found that
bidirectional recurrent neural LSTM network has forecasting has drawn scholars’ attention for a long time.
better performance than unidirectional LSTM. The network created by [25]is the most often used system
Keywords-LSTM,bidirectional-LSTM, open,close, among the several types of approaches that have so far
volume,adam been used. Most ANNs are impacted by the over-fitting
I. I NTRODUCTION issue. A solution to get over this over-fitting problem [3] is
discussed. Additionally, various machine learning models
Time series prediction is the most popular data science are also employed, including a radial basis function, a
technique in the fields of business, economics, food single- layer perceptron, a multi-layer perceptron, and a
management, share market, industry, and inventory support vector machine. The multi-layer perceptron
planning. Time series data can be efficiently predicted performed the best [24]. Various applications for time
using several methods, including univariate autoregressive, series forecasting also made use of the LSTM model.
univariate moving average, simple exponential smoothing, Using the LSTM model, [22] have developed a model that
and ANOVA (analysis of variance). The Integrated Moving can predict the number of parking spaces. For the
Average (ARIMA [6]). which takes the differencing prediction of the future trajectory of nearby cars, [18] used
component into account in the model, is employed more an encoder-decoder LSTM model that took into account
frequently because ANOVA has various disadvantages, one the present trajectory of the vehicle. Traffic flow was
of which is that When the data comes from distributions forecasted by [13] using GRU and LSTM techniques. A
with longer tails than normal, it might not produce accurate flexible yet reliable statistical model was created [19] to
p-values. The ARIMA model has certain drawbacks predict the weather around an airport in Indonesia. Using
because it requires a lot of computer resources, performs single and multiple layers of LSTM, they also investigated
poorly for long-term forecasts, and cannot be used for how the weather affected takeoff and departure for flights.
seasonal time series [4] Recent developments in machine An architecture integrating LSTM and GRU is suggested
learning and deep learning algorithms have led to a novel in [23] to accurately predict the growth over the forecast
approach to solving such problems in which the period of the Host Machine. A framework given in [11]
relationship among the variables is expressed in a examined the efficiency and competency of LSTM to
multilayered structure. Deep learning algorithms have forecast economic time series. Akita et al analysis’s of
limitations of a traditional RNN are solved by this. To
concurrently access all of the historical data and anticipated
information from print articles[1] combined data to show future data, the BRNN deep learning model can be used.
how past events affected the stock market’s opening price. Regular RNN state neurons are divided into two groups i.e.
For the LSTM system to do accurate forecasting, their the forward layer and the backward layer [16].
given formula handled numerical data and written
information. Bi-LSTM was nevertheless used by [12] to
estimate energy load. Bi-LSTM and multilayer LSTM III. THE F RAMEWORK
were used to compare performance. BI-LSTM was used to In our model to forecast the NIFTY 50 index, LSTM
achieve better execution. Additionally, Bi-LSTM was and Bi-LSTM were used. Our objective is to implement
employed to predict the rate of traffic arrivals [10] to models which are based on time series data i.e. of the
forecast stock prices,combined CNN-sliding window and NIFT-50 index. We must refer to a few fundamental
LSTM techniques. Through their research, [9] presented procedures to develop the proposed neural network
that, the LSTM per- formed better than other regression models, including data-collection, prepossessing, feature
models. Furthermore, it has frequently been demonstrated extraction, building model, and training. At the last, we
as one of the best predictors of changes in stock price by used several evaluation metrics to produce and analyze
[8], [17]. [2] utilized LSTM and Bidirectional LSTM for the output.
stock price prediction, the metrics for errors shown by their
model were not up to the marks. We suggested a novel A. Data collection (original data):
strategy that makes use of the BI-LSTM method with Based on the stock’s past value, this study aims to
fewer errors and good R2 and R2adjusted which are closer evaluate the NIFTY- 50 index. The prediction model
to 1. For the Nifty50 index data in our model, we used needs past stock market data. Consequently, it is crucial
deep neural network methods like LSTM and Bi-LSTM. to ensure a trustworthy basis for the information that is
Then we compared the LSTM and Bi-LSTM with various significant and correct for the forecast. The NSE website
evaluation metrics. The Bi-LSTM was used to produce the served as our main data source. In this step, we collected
best results, according to a systematic investigation. daily prices for the NIFTY 50 index for the 12 years
from January 10, 2010, to January 10, 2022,from the
NSE. The dataset includes the everyday price of each
II. METHODOLOGY
stock, open price, close price, high and low, and volume.
“Hochreiter and Schmidhuber first suggested the The core transaction dataset consists of seven variables.
LSTM (fig.1) in 1997” [20], and it afterward gained a lot
of attention, especially for use in solving issues involving B. Data preprocessing:
time series prediction [7]. The default behavior of This crucial step will assist us to extract data from the
LSTMs, a particular type of RNN, is to recall input for NIFTY 50 dataset that will aid in our prediction. This
extended durations to learn long-term dependencies. For action entails:
each unit, there are three different kinds of gates namely, a) Data discretization: This technique allows us to
forget gate, input gate, and output gate. A modified convert the numeric attribute’s raw values into interim
addition to the LSTM model, points.
b) Data alteration: Data standardization is done earlier
the training procedure begins. We utilized the
StandardScaler class from the sklearn: preprocessing
public library to normalize the data between the range -1
and 1. Cleaning up the data entails removing redundant
information and adding any missing values. Data splitting:
To analyze the models, we separated the data set into
training and testing sets after being synthesized into a
Fig. 1. LSTM [15] clean dataset. We used 70% for training and 30% for
testing the model.
the Bi-LSTM is shown in fig.2. The model’s
C. Feature selection:
application for situations involving sequence
classification is enhanced by Bi-LSTM. Two LSTMs are Only the characteristics that must be supplied to the
used by Bi-LSTM in the training procedure shown in models are chosen. We select a date, open, high, low, close,
Fig.2. and volume for our study. Every time, we choose a fresh
collection of attributes for each model’s training and
testing sets. The purpose of our job is to examine historical
Fig. 2. stock data, which has a variety of properties, on stock
indexes. Each of them provides pertinent facts or
information that will aid in our ability to predict the stock
Instead of employing only one LSTM, use a bidirectional index. So choose multiple features of our neural network,
LSTM layer [16] Bidirectional Recurrent Neural Networks which generates the anticipated value, is its final
(BRNNs) have a simple theory that makes sense. The component. In this layer, the output value produced by the
neural networks’ outputs layer is contrasted with the
desired value. After training is finished, predictions on the
test set are obtained using the LSTM and BiLSTM models.
Following that, those models are assessed using the results
of the prediction. Therefore, we applied various metrics to
analyze the model’s performance.
E. Building Model:
D. Evaluation Metrics:
A prediction model’s accuracy can be estimated using Both the LSTM and BiLSTM models have two LSTM
a variety of evaluation metrics. We applied the following layers, each of which is followed by two dense layers and
metrics to the models in our experiment. a dropout layer. So, we’ll look at four of the activation
Mean Absolute Error: functions employed in deep learning models: sigmoid,
relu, tanh, and softmax. For each model’s output layer, the

Mean Squared Error: Fig. 3. Our Framework

selection of the activation function is crucial because it


determines the form of good predictions. Their primary
function is to transform an input signal into an output
signal for a node in our models.

Root Mean Squared Error:


F. Output generation:
A set of real values are used by our neural networks to
make predictions. One of the neurons in the output layer is
responsible for producing each output value. The output
layer rather than just one, like close price. Using several
DL approaches, we sought to identify the best-extracted
features with the lowest error after testing numerous sets of
features. This phase will assist us in accurately selecting
The R-squared (R2) coefficient of determination: the optimal model and forecasting stock index prices.

IV. E XPERIMENTAL F INDINGS AND ANALYSIS


For this experiment, we used Tensorflow as the
learning framework and the Python-based Keras library, a
high- level neural network API. An open-source platform
called Tensorflow provides several machine learning
techniques for performing numerical computations
Adjusted R squared (R2) : utilizing data flow graphs. To assure feature selection, we
first carry out our prediction using numerous
combinations of variables. The performance of machine
learning is impacted by the latter, as shown in the first
subsection.
A. Choosing Features and Results :
Table 1 displays the outcomes of our experiment using
LSTM and BiLSTM models using various four activation
functions. The comparison of several activation functions
is shown in Table 1. Among Relu, Sigmoid, and Softmax
acti- vation functions, the BiLSTM model using the tanh
activation function could obtain the lowest loss of 0.0010.
Using input random data samples, training and testing
are carried out in batches (batch size 64).

TABLE I (LISTM VS Bi-LSTM)

Activation Function LOSS-LSTM LOSS-BiLSTM


Relu .0018 .0011
Tanh .0016 .0010
Sigmoid .0034 .0011
Softmax .0067 .0120

TABLE II METRICS WITH LISTM

MAE MSE RMSE R2 R2Adjusted Fig. 4. Actual values vs Predicted values for next 30-days
0.034ts 0.001823ts) 0.04197ts 0.837ts 0.85263ts
0.028tr 0.001373tr 0.036947tr 0.979tr 0.98019tr

TABLE III METRICS WITH BI-LISTM

Bi LSTM
MAE MSE RMSE R2 R2Adjusted
.026ts .00107ts 03285ts .904ts .85317ts
.023tr .00086tr .02934tr .987tr .9866 tr

The number of data is equally impacted by various


Fig. 5. Validation loss with LSTM
batches. The batches train the network by determining
the input and its associated output. All batches go through
this procedure, and an epoch is a batch that has gone
through this process entirely. We looked at our models
using several evaluation indicators. For each model, we
assessed the MSE, RMSE, MAE, R2, and R2adjusted
predictive performance. The MSE, RMSE, and MAE are
closer to zero in our model. The better the model fits the
data, the closer the coefficient R2 and adjusted R2 are to
1. We evaluate the training sets of the LSTM model and
the BiLSTM model in our experiment using several
evaluation metrics. To estimate the model error, we
employed different feature sets with various numbers of
epochs. We examined MAE, MSE, RMSE, R2 score, and
Fig. 6. Original values vs Predicted values with LSTM
adjuted R2 score for LSTM and Bi-LSTM with 100
epochs, and it can be seen that the BILSTM model has
lower MAE, MSE, and RMSE than the LSTM model
(TABLE II and TABLE III ). Using our model we have
also predicted the next 30 days, as in fig.6 rise in the
market for the next 30 days, same we have confirmed the
actual values from the NSE web site and predicted values
from our model, figure 4.
B. Visualizations:
Using the following graphs, in figures 5, 6,7,8, and 9 Fig. 7. Next 30 days prediction for Nifty 50 index
LSTM and Bi-LSTM are compared for the NIFTY 50
close prices. W i t h their parameters
[3]M Suresh Babu, N Geethanjali, and B Satyanarayana. Clustering
approach to stock market prediction. International Journal of
Advanced Networking and Applications, 3(4):1281, 2012.
[4]World Bank. Market capitalization of listed domestic companies,
2020. [5]Melike Bildirici, O¨ zgu¨r O¨ mer Ersin, et al.
Nonlinearity, volatility and
fractional integration in daily oil prices: Smooth transition
autoregressive st–fi (ap) garch models. Romanian Journal of
Economic Forecasting, 3:108–135, 2014.
[6] George EP Box, Gwilym M Jenkins, Gregory C Reinsel, and Greta M
Ljung. Time series analysis: forecasting and control. John Wiley &
Sons, 2015.
[7] Roxana Buzatoiu. Long term forecasting of industrial electricity
Fig. 8. Validation loss with Bi- LSTM con- sumption data with gru, lstm and multiple linear regression,
2020.
[8] MS Checkley, D A n˜o´n Higo´n, and H Alles. The hasty
wisdom of the mob: How market sentiment predicts stock market
behavior. Expert Systems with applications, 77:256–263, 2017.

[9] Kai Chen, Yi Zhou, and Fangyan Dai. A lstm-based method for stock
returns prediction: A case study of china stock market. In 2015
IEEE
international conference on big data (big data), pages 2823–2824.
IEEE, 2015. ¨ mu¨r Ug˘ur. Multiresolution analysis of s&p500.

[10] Zhiyong Cui, Ruimin Ke, Ziyuan Pu, and Yinhai Wang. Deep
Fig. 9. Original values vs Predicted values with Bi-LSTM bidirec- tional and unidirectional lstm recurrent neural network for
network-wide traffic speed prediction. arXiv preprint
V C ONCLUSION AND F UTURE WORK arXiv:1801.02143, 2018.
[11] Luca Di Persio and Oleksandr Honchar. Artificial neural
Our experiment shows that Bi-LSMT has a great networks architectures for stock price prediction: Comparisons
and applica- tions. International journal of circuits, systems and
impact on the technology, especially for time series signal processing, 10(2016):403–413, 2016.
data. Bi-LSTM can achieve the highest accuracy than [12] Luca Di Persio and Oleksandr Honchar. Analysis of recurrent
other regression models for stock price prediction. neural networks for short-term energy load forecasting. In AIP
Conference Proceedings, volume 1906, page 190006. AIP
Moreover, we have seen that our predicted values for Publishing LLC, 2017.
the next 30 days are exactly the same as the actual [13] Rui Fu, Zuo Zhang, and Li Li. Using lstm and gru neural network
methods for traffic flow prediction. In 2016 31st Youth Academic
values of NIFTY 50 index. Bi-LSTM, unlike LSTM, Annual Conference of Chinese Association of Automation (YAC),
can be used to predict stock prices if the various pages 324–328.IEEE, 2016.
parameters are properly set. Setting the parameters is [14] Iebeling Kaastra and Milton Boyd. Designing a neural network
for fore- casting financial and economic time series.
crucial for building a predictive model, as they have a Neurocomputing, 10(3):215– 236, 1996.Deniz Kenan Kılıc¸ andtime
significant impact on prediction accuracy. Therefore, series. Annals of Operations Research, 260(1):197–216, 2018.
[15] Krishan Kumar, Sunny Behal, et al. Distributed denial of
the proper parameter setting is also required for LSTM service attackdetection using deep learning approaches. In 2021 8th
and Bi-LSTM models. It is important to change these International Conference on Computing for Sustainable Global
Development (INDI- ACom), pages 491–495. IEEE, 2021.
parameters before building a predictive model because [17] Amitava Mukherjee and Rudra Sen. Optimal design of shewhart–
the accuracy of a model is greatly affected by these lepage type schemes and its application in monitoring service
factors. Therefore, the LSTM and Bi-LSTM models quality. European Journal of Operational Research, 266(1):147–
167, 2018.
must also therefore also be properly adjusted. When [18] Seong Hyeon Park, ByeongDo Kim, Chang Mook Kang, Chung
comparing these two models with the same parameters, Choo Chung, and Jun Won Choi. Sequence-to-sequence
prediction of vehicle trajectory via lstm encoder-decoder
the Bi-LSTM model yields a lower MAE, MSE, and architecture. In 2018 IEEE Intelli- gent Vehicles Symposium (IV),
RMSE than the LSTM model. We also found that the pages 1672–1678. IEEE, 2018.
[19] Afan Galih Salman, Yaya Heryadi, Edi Abdurahman, and Wayan
R2 and adjusted R2 for the Bi-LSTM model is closer Su- parta. Single layer & multi-layer long short-term memory
to 1. Consequently, companies and individuals can use (lstm) model with intermediate variables for weather forecasting.
our proposed Bi-LSTM prediction model to anticipate Procedia Computer Science, 135:89–98, 2018.
[20] J u¨rgen Schmidhuber, Sepp Hochreiter, et al. Long short-term
the stock market. This can help investors increase their memory.Neural Comput, 9(8):1735–1780, 1997.
financial profits while maintaining a stable stock [21] Sreelekshmy Selvin, R Vinayakumar, EA Gopalakrishnan, Vijay
Krishna Menon, and KP Soman. Stock price prediction using
market environment. lstm, rnn and cnn- sliding window model. In 2017 international
conference on advances in computing, communications and
informatics (icacci), pages 1643–1647. IEEE, 2017.
REFERENCES [22] Wei Shao, Yu Zhang, Bin Guo, Kai Qin, Jeffrey Chan, and Flora
D Salim. Parking availability prediction with long short term
[1] Ryo Akita, Akira Yoshihara, Takashi Matsubara, and Kuniaki memory model. In International conference on green, pervasive,
Uehara. Deep learning for stock prediction using numerical and and cloud computing, pages 124–137. Springer, 2018.
textual informa- tion. In 2016 IEEE/ACIS 15th International [23] Md Nahid Hasan Shuvo, Mirza Mohd Shahriar Maswood, and
Conference on Computer and Information Science (ICIS), pages 1– Ab- dullah G Alharbi. Lsru: A novel deep learning based hybrid
6. IEEE, 2016. method to predict the workload of virtual machines in cloud
[2] Khaled A Althelaya, El-Sayed M El-Alfy, and Salahadin Mohammed.
data center. In 2020 IEEE Region 10 Symposium (TENSYMP),
Evaluation of bidirectional lstm for short-and long-term stock market pages 1604–1607. IEEE, 2020.
[24] Mehak Usmani, Syed Hasan Adil, Kamran Raza, and Syed Saad
prediction. In 2018 9th international conference on information and
communication systems (ICICS), pages 151–156. IEEE, 2018. Azhar Ali. Stock market prediction using machine learning
techniques. In 2016 3rd international conference on computer
and information sciences (ICCOINS), pages 322–327. IEEE,
2016.
[25] Shilpa Amit Verma, G Thampi, and Madhuri Rao. Inter-
comparison of artificial neural network algorithms for time series
forecasting: Predicting indian financial markets. International
Journal of Computer Applications, 162(2):1–13, 2017.
[26] Guisheng Zhang, Xindong Zhang, and Hongyinping Feng.
Forecasting financial time series using a methodology based on
autoregressive integrated moving average and taylor
expansion.Expert Systems, 33(5):501–516, 2016.

You might also like