Can a neural network forecast a stock price?
The thesis set two neural networks, MLP and LSTM, to forecast the price of stocks on B3, the Brazilian exchange: with the daily closing prices of 31 companies and with minute-by-minute data. LSTM came out ahead for every stock; against the guess “same as last”, it won in two of three series. Explained in 12 screens.
Forecasting the next price is harder than it looks
Below are the last 30 minutes of an imaginary stock. Say where the price will be in the next minute. Your guess competes with the simplest one of all: “the next price equals the last one”, which economists call the random walk.
The scoreboard adds up the squared error, the same yardstick the thesis uses for the minute-by-minute data: missing by 4 cents weighs 16; missing by 2 weighs 4. The lowest total wins.
Random series. Prices are made up in each round; they are not data from the thesis.
Only one of the two neural networks has a memory
A neural network is a program that learns from examples: it receives the price history, compares what it forecast with what happened, and adjusts its “weights” to make smaller errors. The thesis compares two.
Simplified drawings based on Figures 23 and 24 and on the descriptions in sections 4.2 and 4.3 of the thesis.
Studies using the LSTM network multiplied after 2020
Before testing, the author searched the Web of Science, a large database of scientific articles, for studies that forecast stock prices with each network. Switch the network and touch each stage of the funnel.
In both reviews, almost every study says its model worked
The author classified what each article concluded. Before you look, a guess: of the 26 articles on the MLP network, how many said they reached their main goal?
Essay 1 · 26 articles on MLP
Essay 2 · 99 articles on LSTM
The thesis used 31 of the 50 largest companies on B3 and twelve years of closing prices
The author started from the 50 companies with the most fixed assets (machinery, buildings, land) and removed the 19 whose shares were not traded every day. That left 31, with the closing price from 4 January 2010 to 15 May 2022. Touch a stock.
Prices went in “in levels”, as they were, with no transformation. Chart 18 and sections 4.2 and 4.3 of the thesis.
Each stock got 50 models, 25 network shapes for each type
Every network has three layers. The first has one neuron; the second and third, 1 to 5 each. That makes 25 shapes, tested in MLP and in LSTM: 50 models per stock, or 1,550 across the 31 stocks (our calculation). Build a shape.
The author chose small networks to avoid overfitting: a model that memorises the training data and fails when forecasting. Learning rate of 0.05 and 300 training rounds (epochs). Chart 19 of the thesis.
The final test keeps only the models that cannot be told apart from the best
Forecast errors vary by chance. So as not to reward models that were just lucky, the thesis uses the Model Confidence Set: a test asks whether the remaining models make the same error; if not, the worst one is removed; and so on, until a group remains that cannot be separated.
Run the test, one round at a time.
Illustration with made-up numbers. In essay 3, the thesis does not publish each model’s error; it shows only which models stayed in each stock’s final group (next screen).
With daily closing prices, only LSTM models stayed in the final group
The test discarded every MLP model, for every stock. 50 LSTM models remained: for 21 stocks, just one; for the others, 2 to 4 tied shapes, with the same errors. For the author, this shows the superior learning ability of LSTM.
The chart lists 32 tickers: CSNA3 appears in the result, although Chart 18 lists it among the excluded ones, and Santander appears as “ANB11” (SANB11). We show it as printed. The thesis does not publish the size of the errors, nor does it compare, in this essay, with “same as last”.
Minute by minute, the best network made smaller errors than “same as last” in two of the three series
The fourth essay used only LSTM, with the price every minute from April 2019 to December 2021 (273,673 observations) in three series: Petrobras common (PETR3), the Ibovespa stock index, and IRB Brasil (IRBR3). Here there is a yardstick: the error of “same as last”.
Bar = how many times the model’s mean squared error is that of “same as last” (red line), on a logarithmic scale (each mark is 10 times the previous one). Left means smaller error; right, larger. Striped: off the scale. Our calculations from Chart 21. The thesis does not describe what distinguishes models M1 to M7.
A line that hugs the price does not prove the forecast works
The thesis concludes that the network has “relevant adherence” because, in the graphs, the forecast line follows the actual one. See what happens to the simplest guess in a graph like that. Switch the layer.
What this research does not say
For investors
The thesis compares forecast errors; it did not test making money with them. This is not investment advice.
For model developers
With daily closing prices, LSTM came out ahead of MLP for every stock. The author suggests testing other deep learning networks and other stocks.
For researchers
Gaps from the reviews: data from Latin America and Africa, opening, high and low prices and volume, and other training methods.
- Who won, but not by how much. In essay 3, the thesis shows only who stayed in the final group, without the errors and without the comparison with “same as last”. · our note
- A forecast is not a profit. There was no simulation of buying and selling, no trading costs and no test on a new period. · our note
- How each forecast was made. The thesis does not describe models M1 to M7, nor what information each minute was forecast with. · our note
- Few series minute by minute. Two stocks and one index; for one of them, IRB Brasil, “same as last” made smaller errors. · our note
- Reviews in a single database. The results depend on the search criteria and on the Web of Science articles. · according to the author
Credits
FANTIN, Cristiane Orquisa. Projeção de preços de ações com redes neurais artificiais multi layer perceptron e long short term memory. Doctoral thesis (Business Administration), Mackenzie Presbyterian University, São Paulo, 2023. Advisor: Prof. Dr. Eli Hadad Junior.
A thesis in four essays: two bibliometric and systematic reviews in the Web of Science (R, Biblioshiny, VOSviewer) and two studies with neural networks on B3 stocks, with models selected by the Model Confidence Set. No funding declared in the document. This version simplifies the work for a general audience.