Keywords

1 Introduction

It has always been a challenging task for market experts to predict a stock price. This prediction mainly comes before buying the stocks which is supposed to increase in term of price, and latter stocks are sold before the fall. Stock market prediction is mainly done in two ways. Firstly, fundamental analysis as in fundamental analysis mainly concentrates over the market, growth rate, expenditures, etc. information of some particular companies and mainly dependent on company’s policies. Second is the technical analysis method, which mainly focuses on the earlier chats and pattern to predict the growth of stocks. A few years back, this method was quite common in financial experts for grasping the nerves of stock market [1, 2]. But today with the progress of time, we have developed more efficient ways even in predicting the stock market likewise analysis of data by data scientists and involvement of computer scientists over these data using their machine learning methods. These methods improve the performance and accuracy of predictions. Moreover, deep learning would be an upgrade in predicting stock prices [3, 4]. Prediction in stock market can be a hard nut to crack, but with the support of data scientist, it can be eased up. It can be said, with data science beside stock market, prediction will just become a calculative move for the financial experts.

We have explored different kinds of deep learning techniques which result in improving the performance, reliability in prediction, and reduce the complexities of algorithms. The techniques are RNN and LSTM.

Gao et al. [5] has studied three different kind of machine learning models, namely convolutional neural network (CNN), multilayer perception (MLP), and long short-term memory (LSTM) and one attention-based neural network. In this paper, the focus is on predicting the next day stock price as per the historical dataset. There are seven variables that are taken into consideration as per input involves daily data, macroeconomic variables, and technical indicators. This paper showed that attention-based model has better performance compared to other alternative models, and it is able to explain the relationship among nonlinear time series which is a tough task due to low signal–noise ratio and huge noise in nonlinear series [5]. This paper did not explore combination of linear and nonlinear model using an exponential smoothing method to predict stock price.

Ghosh et al. [6] have studied the model that depends on long short-term memory (LSTM) that would be used to calculate the company’s net growth and helped to predict the future growth of the company. To train the model from the past data and to take futuristic decision on prediction, artificial neural network (ANN) played a vital role and used deep learning networks like recurrent neural network (RNN), convolutional neural network (CNN), etc., which works well with multivariate time series data. The main advantage in this paper is that long short-term memory (LSTM) which is particular type of recurrent neural network (RNN) is based fit for predicting future company's growth of different sector as per the past stock prices [6]. The weakness in this paper is that it has taken only one factor from dataset into consideration while predicting future stock price.

Khaled et al. [7] have studied the models that depend on deep recurrent neural network, i.e., GRU and LSTM. This paper uses deep recurrent neural network focused on GRU and LSTM which compared and evaluated a number of variants while training the models. It considered both unidirectional and bi-directional stacked architectures with multi-variate inputs while performing long-term and short-term forecasting, and stacked LSTM architecture is showing better forecasting performance for both long and short term [7]. The article did not explore other deep recurrent neural networks models like bi-directional LSTM, simple RNN, CNN, etc.

Menon et al. [8] have studied the Indian National Stock Exchange dataset for the financial domain problem, and he has done predictions for many companies with accurate estimation which is used in algorithmic trading. In this paper, a few discussions on these primitive classy models like GARCH, ARMA, ARIMA, and ARCH are been implemented through spark jobs for processing huge amount of data and forecast the result in faster and efficient way [8]. This paper did not explore deep recurrent neural network models and only focused on univariate models.

It is been proved that deep learning algorithms are able to recognize the existing patterns in the data and utilizing them with the use of soft computing process. Like other machine learning and statistical algorithms, deep learning architectures are efficient to find dependencies for both long and short term in the data and provide better predictions by linking those hidden relationships [9].

There are lot of opportunities to compare more variety of deep learning algorithms like different variant of LSTM and RNN model. Above all studies focused on specific type of use cases like linear or nonlinear. They have to try some new features of LSTM like bi-directional learning of neurons. They have not considered different variate of parameters like open, close, high, low, volume, etc., in their prediction approach. There is a huge gap in prediction result, depending on the features we choice for our training model process [10, 11].

2 Purpose of Our Study

We want to explore more on the variant side along with different -deep learning models. Most of the studies are more focused on long short-term memory (LSTM) and gated recurrent unit (GRU). Simple LSTM may not perform better alone because it is one-directional training model having forget gate, input gate, and output gate, and GRU is also a LSTM without any output gate. So, we tried bi-directional LSTM that has high accuracy as compared with simple one-directional LSTM. Next level, we tried with simple RNN model which has again higher accuracy as compared with bi-directional LSTM [12,13,14].

After the model selection, we trained our model on two different types of dataset, first on dataset with close price series; thus, it is a univariate model and secondly dataset having series of high, volume and close price of the stock, thus it is a multivariate model.

For each model, i.e., LSTM, bi-directional LSTM, and RNN, we have studied with univariate and multivariate features with same set of training parameters like epochs, timesteps, neurons in each layer, learning rate and batch size. Finally, we found univariate RNN having highest accuracy followed by multivariate RNN.

3 Methodology

For our study, we have collected the historical dataset of Google.com, Inc. (GOOG) stock obtained from Kaggle. It has 5982 records of daily stock prices of the stock. Every record is having details of low, high, closing, and opening value of stocks along with the precise amount of stock sold on that particular day.

Before training the model, first we clean our dataset before processing by removing the noisy data and some redundant data like the records which are identical to previous record and records having volume 0. Then, we use Min–Max normalization that will convert the values into the range of 0–1.

After preprocessing the dataset, we will train our model using three different deep learning architectures such as LSTM, bi-directional LSTM, and RNN for our research. Finally, each model has been evaluated based on the test dataset and their respective R2 score, MSE (Mean Squared Error) and RMSE (Root Mean Squared Error) have been calculated.

4 Result and Discussion

Google dataset from Kaggle has been used for this analysis.

All models have been trained with the below parameters:

  1. (i)

    Batch size: 32,

  2. (ii)

    Time steps: 30,

  3. (iii)

    Neurons in each layer: 50 and 45, and

  4. (iv)

    Learning rate: 0.001.

As per the above parameters, the model is trained using the training dataset for 200 epochs and validation dataset is used to validate the model.

First of all, model has been divided into two categories based on number of fields taken into consideration for stock market analysis:

  1. 1.

    Univariate - > has “CLOSE” attribute

  2. 2.

    Multivariate - > has “CLOSE,” “HIGH,” and “VOLUME” attributes.

Then, for each variate, we have done analysis on three models:

  1. 1.

    LSTM, 2. bi-directional LSTM, 3. RNN.

Amazon (AMZN) dataset from Kaggle has been used for the comparison for the same parameters and models where RNN again proves to be better model compared to LSTM and bi-directional LSTM.

As per the above result, it is clear that univariate having higher R-squared scores when compare to multivariate and univariate RNN has highest R-squared score even multivariate RNN has better R-squared score as compared with others multivariate models. So, as per our analysis, we can conclude that RNN model is the better model for stock market analysis (Figs. 1, 2, 3, 4, 5 and 6).

Fig. 1
figure 1

Multivariate LSTM for google (left side) and Amazon (right side)

Fig. 2
figure 2

Multivariate bi-directional LSTM for google (left side) and Amazon (right side)

Fig. 3
figure 3

Multivariate RNN for google (left side) and amazon (right side)

Fig. 4
figure 4

Univariate LSTM for google (left side) and amazon (right side)

Fig. 5
figure 5

Univariate bi-directional LSTM for Google (left side) and Amazon (right side)

Fig. 6
figure 6

Univariate RNN for google (left side) and Amazon (right side)

5 Conclusions and Future Scope

We have proposed a recurrent neural network approach is the best fit to solve the stock price prediction problem. We have concluded that RNN model is the better model for stock market analysis either with univariate or multivariate and improves both efficiency and performance of the prediction of stock price. We proposed a multivariate deep learning-based method for the stock prices prediction (Tables 1 and 2).

Table 1 Result of all the models is mentioned below for Google dataset

The approaches we have used are consolidated after comparison with other models of stock price analysis. As a future scope, we can compare the predicted results with existing state-of-the-art methods, and also, we can figure it out the reason of the underperformance of simple unidirectional LSTM and bi-directional LSTM models of multivariate analysis.

Table 2 Result of all the models is mentioned below for Amazon dataset