A Recurrent Neural Network is a machine learning architecture for processing sequential data, see my article here: link. The applications of this architecture are amazing, for example we can generate a song from a note, generate a poetry, a story or even a C code!
Here is a list of various amazing applications of RNN:
- Video classification: link
- Image classification: link
- Image captioning: link
- Sentiment analysis: link
- Language translation: link
- Making music: link
- Writing poem: link
- Writing code: link
- Generating text: link
- FX trading: link
- Stock market prediction: link
- Speech recognition: link
- Text to speech: link
RNN application is about a sequence of data. That sequence of data can be the input or it can be the output. That sequence of data can be a sequence of numbers, a sequence of musical notes, a sequence of words, or a sequence of images.
If the sequence of data is the output, then it becomes a creation. For example:
- If the output is a sequence of notes, then the RNN is “writing music”.
- If the output is a sequence of words, then the RNN is “writing a story”.
- If the output is a sequence of share prices, then the RNN is “predicting share prices”.
- If the output is a sequence of voices, then the RNN is “speaking”.
- If the output is a sequence of colours, then the RNN is “painting”.
That is very powerful right? This is why AI in the last few years is really taking off. Because finally AI can create a song, a speech, a painting, a story, a poem, an article. Finally AI can predict a sequence of numbers. Not just one number but a series of numbers. That has very, very serious consequences. Imagine if that series of numbers is the temperature every hour in the next few days.
Imagine, if that series of numbers is stock prices in the next few weeks. Imagine if the prediction is accurate. It would turn the financial world upside down!
Three Categories of RNN
RNN applications can be categorised into 3:
- Classification
- Generation
- Encoder Decoder
Classification is about categorising a sequence of images or data into categories, for example:
- Classifying films into action, drama or documentary
- Classifying stock market movements into positive or negative trend
- Classifying text into news, scientific or story
In classification the output is a single number.
Generation is about making a sequence of data based on another data, for example:
- Making a sequence of musical notes e.g. a song.
- Making a sequence of words e.g. a poem, Python code or a story.
- Making a sequence of numbers e.g. predicting stock market.
For generation we need to have a “seed” i.e. data which the creation is based on. For example, when generating a sequence of words we need a word. When generating a sequence of musical notes we need a note.
Encoder Decoder consists of 2 parts. The first part (encoder) encodes the data into a vector. The second part (decoder) uses this vector to generate a sequence of data. For example: (image source: Greg Corrado)

The words in the incoming email is fed one by one as a sequence into an LSTM network, and encoded into a word vector representation. This vector (called thought vector) is then used to generate the reply, one word at a time. In the above example “Yes,” was generated first, and then that word is used to generate the second word “what’s”. Then these 2 words are used to generate the third word, and so on.
Using RNN to forecast stock prices
One of the popular techniques to forecast stock prices is RNN-based (the other is Reinforcement Learning). We can see the trend in Ref 1 below.
In a paper by Wenjie Lu, Jiazheng Li, Yifan Li, Aijun Sun, Jingyang Wang (see Ref 2 below), we can see that amongs the RNN based technique, the most accurate one is a combination of CNN and LSTM. The CNN is used to extract features in the stock price history, and LSTM is used to predict the future stock prices. The result is like this (Ref 2):

The stock price in this case is Shanghai Composite Index from 1/7/1991 to 31/8/2020. The last 500 days are used for test data, the rest as training data. They compared 6 methods: MLP, CNN, RNN, LSTM, CNN-RNN, CNN-LSTM and the result is as follows in terms of Mean Absolute Error (MAE):

Reference:
- Hu, Z.; Zhao, Y.; Khushi, M. A Survey of Forex and Stock Price Prediction Using Deep Learning. Appl. Syst. Innov. 2021, 4, 9. https://doi.org/10.3390/asi4010009.
- Wenjie Lu, Jiazheng Li, Yifan Li, Aijun Sun, Jingyang Wang, “A CNN-LSTM-Based Model to Forecast Stock Prices”, Complexity, vol. 2020, Article ID 6622927, 10 pages, 2020. https://doi.org/10.1155/2020/6622927.