Predicting Stock Price with RNN

If you had fun doodling and building (and running the model to recognize doodling) on your mobile devices in the last chapter, you'll possibly also have fun when you make money in the stock market, or get serious when you don't. On the one hand, stock prices are time-series data, a sequence of discrete-time data, and the best deep learning method to deal with time series data is RNN, which we have used in the last two chapters. Aurélien Géron, in his best seller, Hands-On Machine Learning with Scikit-Learn and TensorFlow, suggested using RNN to "analyze time series data such as stock prices, and tell you when to buy or sell." On the other hand, others think the past performance of a stock cannot predict its future returns, and a randomly selected portfolio would do just as well as one carefully selected by experts. In fact, François Chollet, the author of Keras, a very popular high-level deep learning library running on top of TensorFlow and several other libraries, stated in his best seller, Deep Learning with Python, that using RNN with only public data to beat markets is "a very difficult endeavor, and you are likely to waste your time and resources with nothing to show for it."

So at the risk of "likely" wasting our time and resources, but with the certainty that we'll at least learn more about RNN and why it is possible or not to predict stock prices better than a random 50% strategy, we'll first give an overview of how to use RNN for stock price predictions, then discuss how to build an RNN model with the TensorFlow API to predict stock prices, and how to build an RNN LSTM model with the easier-to-use Keras API for stock price predictions. We'll test to see whether such models can beat a random buy-or-sell strategy. If we feel good about our models for improving our chances of beating the market, or just for the sake of know-how, we'll see how we can freeze and prepare the TensorFlow and Keras models to run on iOS and Android apps. If the model can improve our chances, then our mobile apps powered with the models may help us wherever and whenever we want to make a buy-or-sell decision. Feeling a little uncertain and excited? Welcome to the market.

In summary, we'll cover the following topics in this chapter: