Keywords

1 Introduction

Stock market predictions is a difficult task for stock fund managers and financial analysts due to unstable stock data which is noisy and nonlinear. The variation in policies such as economic, macroeconomic data, political uncertainty, and government policy are affected in the direction of the stock market. This impact may be reflected in stock prices and the market may be volatile. For a day trader to gain more profits, it is significant to know how to identify the quality of stocks for intraday trading. Most of the traders are not able to gain profits because they fail to select appropriate stocks to trade during the day. Hence there is a need for the short-term daily trading framework is to predict stock price. This will help investors and traders to gain the profit from the day trade. In this paper, we have proposed the recurrent neural network (RNN) with long short term memory (LSTM) to forecast future stock returns.

The related works are described in Table 1. Extensive literature suggested that most of the stock returns work is based on artificial neural network, fuzzy, simulation-based and genetic algorithm. In this paper, the recurrent neural network with LSTM is studied to forecast future stock returns. It has the ability to keep the memory of historical stock returns in order to forecast future stock return output.

Table 1. Related work

2 Related Work

Existing trading rules were not gainful for future periods when the market condition changes dynamically. Chourmouziadis and Chatzoglou [2] proposed short-term technical trading strategy by considering the daily price of the stock using fuzzy systems.

An automatic way of buying and selling financial securities without the help of portfolio managers has been discussed. The combination of technical trading indicators like moving average, alpha, beta and volatility of the stock over a period of time has been proposed [1]. Nakano et al. [7] proposed a method in which non-linear financial time-series data are considered and machine learning techniques were used for predicting stock prices. Mousavi et al. [6] proposed generalized Exponential Moving Average technical indicator model to predict the stock prices. The future performance of stock indices has been studied using fuzzy time series modeling [11]. Return and risk are important objectives for managing a portfolio. Macedo et al. [5] proposed a model to enhance technical trading rule indicator based on Moving average convergence/divergence, Relative Strength Index, Bollinger Bands and Contrarian Bollinger Bands. Artificial Neural Network(ANN) has been widely used in predicting stock for financial markets. Zhang and Wu [16] proposed back propagation ANN to predict stock prices and indices.

Technical indicators like moving average, moving average convergence and divergence, relative strength index and commodity channel index have been used to predict the stock price [14]. Performing feature extraction could help to reduce the redundant features, which can reduce the measurements, storage requirements and the running time of classifiers. It also avoids the curse of dimensionality and improves prediction performance as well as facilitate data visualization and understanding [13]. Ticknor [12] proposed artificial neural network approach to improve the prediction performance. Preis et al. [9] hypothesized that investors may use a Google hits ratio of pages are used to take the decision to predict stock price. Macroeconomic factors are believed to influence stock market movements. Machine learning methods, which are data-driven and assumption-free have become more popular in stock market prediction [15].

3 Data Specification

In this paper, stock data are collected from http://www.nseindia.com. The data contain information about stock such as stock day open price, day low price, day high price and day close price. We have considered CIPLA stock, ITC stock, TCS stock, ONGC stock and Nifty index for the experiment. The dataset range is obtained from the year 2009 to 2018.

4 Proposed Work

The proposed workflow of stock return forecasting is described in Fig. 1. The stock data are collected from Indian stock exchange, i.e., national stock exchange (NSE). The stock returns are calculated based on stock closing prices. Let \(C^s\)= \(C^s_t\) be defined as the closing price of stock s at time t and simple returns of stock over n period are given in Eq. 1. We standardize the stock returns by subtracting the mean and dividing them by the standard deviation. These stock returns are given as input to the recurrent neural network.

Fig. 1.
figure 1

Overall proposed work.

$$\begin{aligned} {Return^{sn}_t}= \frac{C^s_t}{C^s_t}_{n}-1 \end{aligned}$$
(1)

RNN with LSTM. The proposed model that takes stock return as input data from the recent past and predicts the stock returns for the next 24 h in the future. Existing literature suggested that RNN is not able to hold long-term dependencies in stock returns [4, 8]. Therefore LSTM has been proposing to capture long-term dependencies in stock returns. The LSTM organized as a cell, each cell has an internal state variable that passes information from one cell to another cell. A sigmoid layer of forget gate takes the previous output at \(t-1\) and the present input at time t and performed concatenation operation. The output of this layer lies between 0 and 1 and it is shown in Fig. 2. If \(ft=0\) then the internal state variable is completely forgotten, and \(ft=1\) it will be passed through one cell to another.

Fig. 2.
figure 2

RNN with LSTM framework for stock return forecasting [4, 8].

The forget gate and input gate are given Eqs. 2, 3, 4, 5, 6 and 7.

$$\begin{aligned} \text {f}_t = \sigma (W_f.[({h_t}_{-1}-x_t]+b_f) \end{aligned}$$
(2)
$$\begin{aligned} \text {i}_t = \sigma (W_i.[{h_t}_{-1}-x_t]+b_i) \end{aligned}$$
(3)
$$\begin{aligned} \text {C}_t = tanh (W_c.[{h_t}_{-1}-x_t]+b_c) \end{aligned}$$
(4)
$$\begin{aligned} \text {C}_t = f_t .{C_t}_{-1}+ I_t . C_t \end{aligned}$$
(5)
$$\begin{aligned} \text {O}_t = \sigma (W_o.[{h_t}_{-1}-x_t]+b_o) \end{aligned}$$
(6)
$$\begin{aligned} \text {h}_t = O_t.tanh C_t \end{aligned}$$
(7)

5 Experimental Results and Discussion

NSE datasets consist of 2400 rows, we have split 70% data for training and 30% for validation. The RNN model built in three layers, and we have considered the rectifier unit as the activation function. The experiment is carried out in R Studio platform. Decreasing in training rate and increasing validation rate suggests that the model is overfitting and it is described in Fig. 3. Therefore, we have added dropout function to RNN layers that avoid the overfitting problem and it is described in Fig. 4.

Fig. 3.
figure 3

Overfitting.

Fig. 4.
figure 4

Adding dropout function to RNN.

MAE and RMSE is used to evaluate the performance of the prediction model and it is described in Eqs. 8, 9. The proposed model outperforms compared to with feed forward artificial neural network(ANN) and it is shown in Table 2.

$$\begin{aligned} MAE= \frac{1}{n}\sum _{t=1}^{n}|e_t| \end{aligned}$$
(8)
$$\begin{aligned} RMSE= \sqrt{\frac{1}{n}\sum _{t=1}^{n}e_t^2} \end{aligned}$$
(9)
Table 2. Result comparison.

6 Conclusion

Stock price movements forecasting is challenging task for day traders to yield more returns. Recurrent neural network with LSTM is a state-of-the-art method for sequence learning. They are less commonly applied to stock return predictions. The first the recurrent neural network with LSTM is studied to forecast the future stock returns. Second, considered a recurrent dropout in RNN layers to avoid overfitting in the model. The future work can be time series forecasting of stock prices by combining technical and fundamental analysis of stocks.