PPGAPPGA
Interativo
PT 01 / 12
Doctoral thesis · PPGA Mackenzie · 2023

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.

Author: Cristiane Orquisa Fantin Advisor: Prof. Dr. Eli Hadad Junior Program: Graduate Program in Business Administration (PPGA) · Mackenzie Presbyterian University
This page presents research. It is not investment advice.
Each cube: an LSTM network in the final group Chart 20 of the thesis
Closest UN Sustainable Development Goal
scroll
02 Try it

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.

You · squared error0
“Same as last” · squared error0

03 The contenders

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.

04 Essays 1 and 2 · two reviews

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.

05 Essays 1 and 2 · what the articles conclude

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

100% confirmed their goal
Category 9 of the review. And 100% say they bring new conclusions (category 8).

Essay 2 · 99 articles on LSTM

57%42%
beat the models they were compared with“promising” resultsremainder, 1% (our calculation)
Our reading
When almost everyone says it worked, what matters is against whom each model was compared. In the MLP review, only 3 of the 26 articles (12%) mention the random walk hypothesis, the idea that prices move by chance and so the best guess is to repeat the last one. The thesis comes back to this yardstick in the fourth essay (screen 10).
06 Essay 3 · daily closing prices

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.

2,295 days to learn
764 test
75% of the 3,059 daily observations25% to test

Prices went in “in levels”, as they were, with no transformation. Chart 18 and sections 4.2 and 4.3 of the thesis.

kept in the studyremoved (not traded every day)
07 Essay 3 · the configurations

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.

Layer 2
Layer 3

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.

08 The criterion · Model Confidence Set

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).

average error, LSTMaverage error, MLP⊢⊣ range of chanceworst of the round
09 Essay 3 · the result · Chart 20

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”.

10 Essay 4 · Chart 21

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 forecast is not a profit. The thesis did not simulate buying and selling with these forecasts, nor trading costs. Nothing here is investment advice.
11 The unexpected · Graphs 01 to 03

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.

Our reading
In the thesis’s three graphs, the two lines rise and fall in the same minute, separated by an almost constant distance, and they show only the last 73 or so minutes of the 32 months. The thesis does not say what data each forecast was made with. To know whether a network forecasts, the yardstick on the previous screen counts, not how the graph looks.
price (made up)“same as last”line in the same minute, shifted
12 In practice, limits and credits

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

How to cite
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.