top of page

Forecasting stock market using Machine learning models

Trading is an environment of high complexity where the main challenge consists in finding rules that describe and predict markets, then to employ them successfully to earn profits, without altering those markets in ways that might have for consequence the destruction of the rule itself.

Trading rules can be represented as alphas, algorithms that have for objective to predict the future of securities returns. The fact that the market is continuously evolving and responding to new information sources, also indicates that the opportunity to find alphas will continue to exist indefinitely. In this era of time, there is different strategies and algorithms that turn information into profit generation.

When it comes to alpha generation, researchers would say it’s not important to have a perfect description of what happened in the past, but rather to be able to predict the future as precisely as possible. The dilemma is between an overly complex model that may enable to perfect calibration but lead to overfitting and a poor quality of prediction, and a simple model that fits the sample data poorly and has low chance to predict accurately future behavior.

Different machine learning models can be used when it comes to alpha research:

Regression model, where Y and X are quantitative variables and Y is inferred by a function Y F X .

Classification model, where the qualitative variable Y is determined/inferred from a quantitative variable X.

Clustering model, where a quantitative variable X is observed and then classified into groups with similar features.

These techniques belong to two categories of machine learning algorithms : Supervised and Unsupervised learning.

The term “supervised algorithm” means that we expect the machine to train itself from a set of examples that we provide. Supervised learning can be split into classification (labeled data are used) and regression problems (continuous values for the output).

The term “unsupervised algorithm” refers also to clustering problems, where we don’t know the correct answers in advance. In this case, the algorithm search is directed by predefined quality criterion.

According to some sources, there is more than 100 different machine learning methods. Discussing the pros and cons of each of these models is well beyond the goal of this paper. Others would have combined machine learning techniques such as applying a supervised model to predict stock prices and when it comes to select stocks to build a portfolio, using an unsupervised learning model.

Stock price forecasting is a classic problem and therefore accurate forecasting methods are very important when it comes to portfolio management in the financial world. There exists a plethora of literature devoted to the subject. Regression models (defined as linear) have been traditionally used to model stock markets changes.

The stock market returns are characterised by features such as nonlinearity, discontinuity, and volatile multifaceted elements because many items affect is such as general economic situations, political actions and broker's assumptions (Hadavandi et al. 2010). Due to the volatility of the stock market, a rapid decision making process is required. Therefore, it is critical that transactions are made in the shortest timeframe (Barakat et al. 2016).

The aim of this paper is therefore to discuss the most efficient ML algorithms and the most common models used for financial prediction tasks: Artificial Neural Network (ANN) and SVM for their ability to determine nonlinear characteristics in data without prior knowledge and also their better results in forecasting the market value compared to statistical models.

Artificial Neural Network (ANN)

ANNs have a series of interconnected nodes that simulate individual neurons, and are organised into different layers based on function (input layer, processing layer, output layer, etc.). The output is calculated based on the inputs and the weights assigned on the connections. As the machine trains, weights are reassigned when new patterns are noticed in the training data. There are a variety of methods for training the ANN and some of them perform better in discovering the linear and nonlinear relationship. Two thresholds are utilized by ANN in the research of linear and nonlinear qualifications. The number of layer is very important in predictability as with too many layers, the algorithm won't be able to find the fittest choice and the structure will be complicated. In other hand, too few layers mean the network is unable to find the global solution and therefore nonlinear relationships.

Figure 1: Schematic illustration of ANN

Figure 2: An illustration of relationship between inputs and output for ANN

Support Vector Machine

SVM is a useful method for data classification and regression analysis. Support Vector Machines create a decision boundary such that most points in one category fall on one side of the boundary while most points in the other category fall on the other side of the boundary. The trained SVM model can then be tested with new data instances to predict which category they belong to based on the training performance. Linear and nonlinear are the two classes of SVM.

Linear SVMs are known to be fast to train and execute, however they tend to have a poor performance on complex datasets with many training inputs and moderate number of features. In contrary, nonlinear SVMs can present a more consistent performance across different problems. SVM has proven their capability of classifying nonlinear data by using the “Kernel trick”. In order to ensure linear separability in the nonlinear data, the “kernel trick” method projects n-dimensional space (m>n) using basis functions and instances in the new feature space that are separated into two classes using hyperplanes. Using the SVM model for prediction, researchers were able to predict test data outputs with an accuracy in high 50%, which is well above the 50% threshold.

Figure 3: Schematic illustration of SVM

While ANNs models try to minimize classification error within the training data, SVMs may make classification errors within training data in order to minimize overall error across test data. SVM models have the advantage in finding global optimum contrary to neural network models that determine local optimum instead. ANN is a good alternative to SVM in modeling noisy and nonlinear time series data.

Hybrid model

With The evolvement of artificial intelligence techniques in recent years, many proposed solutions attempted to combine machine learning and deep learning techniques based on previous approaches in order to increase the accuracy of forecasting, or improve decision-making in the market.

Some hybrid models were proposed to cover the weaknesses of each model individually and improve their overall performance. For this purpose, some machine learning techniques such as various types of artificial neural networks, time series models or the other models can be combined with each other.

Qui and Song studied the daily movement direction of the Japanese stock markets with an optimized ANN model. The latter was a hybrid model combining Genetic algorithm to ANN model and having weights and bias values adjusted during ANN training. The results obtained with this hybrid model were better (accuracy rate of 86.39%) than those of a standard ANN model.

In 2020, Sahoo and Mohanty proposed another combination, ANN with gray wolf optimization (GWO) technique and then they compared the hybrid ANN-GWO with ANN on a dataset collected from Bombay stock exchange (period used 2004 to 2018). Different error measures had been used to evaluate the performance of the ANN-GWO and ANN and the results were better with the hybrid model.

Many other researchers used ML models along with feature selection algorithms to select the input variables, while providing empirical evidence that feature selection algorithms improved their model’s performance. The paper of Firuz Kamalov and Linda Smail on forecasting with Deep learning: S&P 500 index demonstrated that their network model containing two hidden layers: convolutional and fully connected, using the previous closing values and volume of the index to predict the next-day direction, outperformed the benchmark models both in accuracy and precision.


Artificial neural networks, support vector machine, genetic algorithms combined with other techniques have been used for the past decade to forecast and analyze financial markets because these techniques do not require any assumptions about the data and often achieve higher accuracy than traditional methods. From the various models used by researchers, it has been showed that neural network-based models are models with high predictive accuracy and among these models, deep models showed more modeling power.

bottom of page