Stock Price Prediction


Problem Statement ->

We implement a Recurrent Neural Network with multiple LSTM (Long Short Term Memory) layers, and use this to predict the stock. In this particular example, I am using a dataset with google price details, and so it will predict the google stock price. But the dataset, can be changed easily to predict any stock.

Improving model ->

  1. Getting more training data: we trained our model on the past 5 years of the Google Stock Price but it would be even better to train it on the past 10 years.

  2. Increasing the number of timesteps: the model remembered the stock prices from the 60 previous financial days to predict the stock price of the next day. That’s because we chose a number of 60 timesteps (3 months). You could try to increase the number of timesteps, by choosing for example 120 timesteps (6 months).

  3. Adding some other indicators: if you have the financial instinct that the stock price of some other companies might be correlated to the one of Google, you could add this other stock price as a new indicator in the training data.

  4. Adding more LSTM layers: we built a RNN with four LSTM layers but you could try with even more.

  5. Adding more neurons in the LSTM layers: we highlighted the fact that we needed a high number of neurons in the LSTM layers to respond better to the complexity of the problem and we chose to include 50 neurons in each of our 4 LSTM layers. You could try an architecture with even more neurons in each of the 4 (or more) LSTM layers.



Figure 2020-08-23 015436.png

Result

This is the plot of our predicted stock prices as compared to the real stock prices.

This is just a basic plot using “plt.plot”, but more complex plots can be formed using other visualization libraries. Here, we simply show the accuracy of our model.



Topics, Languages, Tools & more

Topics -

  • Recurrent Neural Networks (Stacked multiple LSTM layers).

  • Tensorflow, Keras, numPy, matplotlib, pandas, sklearn

  • Feature Scaling - Normalization of data

  • Adding multiple LSTM, output (Dense) layers.

  • Regression

  • Dropout regularization - to avoid overfitting

  • Optimization - ‘adam’ optimizer.

  • Plotting visualizations

Notebook/IDE - Spyder

** All linked code and dataset used, with comments can be found on Github.**


Previous
Previous

Movie Recommend System RBM

Next
Next

Python code bank