Inspiration

Find stock patterns and make a profit at the right time!

We read about using a Recurrent Neural Network (RNN) to predict the Amazon stock price of the next day based on the historical prices. What if there are indicators (features) in the stock market that may lead or lag behind the stock prices. We do not know these indicators specifically, but let's assume they are among the 500 large companies stocks, i.e. some of these stocks prices lead the others (and so for S&P500). We would like to explore if the RNN model is able to find out how well we can predict the future S&P500 stock price, using the 500 stocks prices from history.

What it does

It takes in past stock prices and predicts prices in the future.

How we built it

A recurrent neural network (RNN) can be used to predict time-series data based on previous observations, as the current input and output are influenced by the previous inputs (states).

Our work is based on an online demo that predicts the Amazon stock price using recurrent neural network, with input features “open”, “high”, “low”, “close”, “adjclose” (adjusted closing price). We update the stock to Twitter and made sure that the framework worked the way it is designed to be. We also explored different hyperparameters such as batch size and epochs, which prepared us to the next step of the project. We presented 500 epochs and each has a batch size of 64 (see images attached).

Then, we worked on a completely data set – S&P500 and these 500 companies’ stocks. Instead of using “open”, “high”, “low”, “close”, “adjclose” as input features, we used these 500 companies’ stock prices as features to predict the future S&P500 stock. We used train-test-split to divide the data into a training set and a testing set, where we calculated the performance of the model using the testing data set. The model is a long short-term memory recurrent neural network with 2 hidden layers. We ran 50 epochs (due to time limit) and each has a batch size of 512. The “Adam” optimizer and a dropout rate of 20% is chosen, so that the loss function can be better optimized to a global minimum.

Challenges we ran into

The accuracy can vary a lot if the value of batch size is either too small or too large. We spent most time exploring the effect of changing the hyperparameters, but considering each run would take about 500 epochs to converge, we are either running out of time or the model is not optimally optimized.

Accomplishments that we're proud of

We are able to predict the future by analyzing the past.

What we learned

The accuracy of the Twitter stocks is 87%, meaning that 87% of the time, we can trust the model to decide if we should buy or sell the stocks. The accuracy of the S&P500 stocks is only slightly above 50%. We think it is because the model is not yet optimized (due to the small number of epochs). Given more time to run the model fitting, we might be able to further optimize the model and increase the accuracy of prediction.

What's next for Predicting Future Stock Price using Recurrent Neural Network

We'll keep exploring the choice of input features (e.g. look for more effective indicators) and the hyperparameters to improve the accuracy of predicting future stock prices.

Built With

Share this project:

Updates