
Predicting a stock's closing price with a neural network
- Article
- Finance
Stock markets are volatile and non-linear, which makes predicting them accurately close to impossible. That has not stopped people from trying, and with more computing power and better algorithms the programmed approaches have improved. A 2020 paper in Procedia Computer Science by Mehar Vijh, Deeksha Chandola, Vinay Anand Tikkiwal, and Arun Kumar compared two such approaches, an artificial neural network (ANN) and a random forest (RF), at predicting the next day’s closing price for five companies in different sectors.
The data and features
The authors took daily price histories for Nike, Goldman Sachs, Johnson & Johnson, Pfizer, and JPMorgan Chase from 2009 to 2019. From the open, high, low, and close of each day they derived six new variables to train on:
- the day’s high minus its low,
- the close minus the open,
- 7-day, 14-day, and 21-day moving averages of the price, and
- the standard deviation of the price over the past 7 days.
These capture recent range, direction, trend at three horizons, and recent volatility. The models were trained on these features to predict the following day’s close.
How the models were judged
Three error measures were applied to each model’s predictions: root mean square error (RMSE), mean absolute percentage error (MAPE), and mean bias error (MBE). Lower is better for all three. MAPE is the easiest to read across companies with very different share prices, since it is expressed as a percentage.
Results
The neural network came out ahead on RMSE, MAPE, and MBE for four of the five companies. The exception was Goldman Sachs, where the random forest did slightly better on MAPE (1.01 percent against 1.09 percent). Elsewhere the numbers were close but consistently favoured the ANN: Nike at 1.07 percent MAPE against 1.14, JPMorgan at 0.89 against 0.93, Johnson & Johnson at 0.70 against 0.75, and Pfizer at 0.77 against 0.80. The paper’s plots of predicted against actual closing prices show the ANN tracking the real series closely for all five stocks.
Reading the result carefully
An error of about one percent on the next day’s close sounds impressive, but the features are all built from recent prices, and tomorrow’s close is usually near today’s. The models were not fed anything about earnings, news, trading volume, or the wider economy. The authors say as much, suggesting that future work could bring in financial news, volume, profit and loss statements, and political events, possibly with deeper models, to get closer to genuinely useful forecasts. Read that way, the paper is a clean baseline for what price history alone can do.