- Home
- -
-
Stock Price Prediction
In 2012, some scholars from Stanford published an article saying that they could use the Recurrent Neural Networks (RNN) to predict the stock price. I knew that RNN models could make powerful time-series predictions because of long short-term memory (LSTM). While I didn't expect that it could be used to
predict the stock price, so I tried it myself, and I also got a very accurate model.
Data Preprocessing
The first step is to pick a stock and get the information on this stock. I chose to use Google as my example stock. Then I used the stock price from day 1 to day 999 as my training feature dataset and the stock price from day 2 to day 1000 as my training label dataset. The rest days from day 1001 to day 1259 are my testing dataset. Feature scaling is necessary for neural networks, so I applied normalization in the last step of
the data preprocessing.
Model
The model building part is very similar to the ANN or CNN model. I just had to change several parts of it.
I chose to use 'tanh' as my last activation function, 'rmsprop' as my optimizer, and 'mean_squared_error' as my loss function.
Result
I plotted my result. The left part is the training dataset and the right part is the
testing dataset. My model is very accurate and the RMSE is 0.03. It looks like I
could easily predict the stock price and I'm going to be rich.
Final Thoughts
The reality is that I couldn't predict the stock price.
A real prediction should be a line that on the left side of the real stock price line so that I could predict the stock price for tomorrow.
However, the RNN model only changed a bit of today's stock price by using its
short-term memory. Overall, the RNN model cannot be used to predict the stock is not applicable, but
it can be used to predict some business problems that have certain patterns.
Software used: Python, Pycharm
Packages used: Tensorflow, Keras,
Wechat ID:
jasonfangmagic