Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Intelligent System for Intraday Stock Market

Forecasting
Badre LABIAD Abdelaziz Berrado Loubna Benabbou
Equipe AMIPS Equipe AMIPS Département Sciences de la Gestion
Ecole Mohammadia d’Ingénieurs Ecole Mohammadia d’Ingénieurs Université du Québec à Rimouski (UQAR)
Mohammed V University Mohammed V University Campus de Lévis
Rabat Morocco Rabat Morocco Québec Canada
Email: labiad.badre@gmail.com Email: berrado@emi.ac.ma Email: Loubna benabbou@uqar.ca

Abstract—During recent years, the trading of financial in- The remainder of this paper is organized as follows. Section
struments is becoming reliant upon different type of intelligent II deals with the literature review. Details about experimental
systems to make buy/sell decisions. These systems use different setups can be found in section III. The experimental results
machine learning techniques to come up with the wanted in-
vestment decision. Artificial Neural Networks (ANN) are among are presented in section IV. Finally, we conclude this study
the most used techniques for stock markets forecasting. In this and discuss possible future work in section V.
work, we present an end-to-end system to implement ANNs
for intraday forecasting of Moroccan stock market. Different II. L ITERATURE R EVIEW
ANN architectures are implemented and tested. Experimental
results show that ANN can be used to make satisfactory intraday The diversification of financial instruments and the
predictions. increase in the number of transactions per second, even per
Index Terms—Stock Market, Artificial Neural Network, Short millisecond, and the permanent changes in price trends have
Term Forecasting accentuated the need for models capable of capturing this
complexity in order to obtain the most accurate forecasts in a
I. I NTRODUCTION very short time. Artificial neural networks have shown their
Stock markets are indispensable levers for the economies of adaptation to this type of problem [1].
the countries. In these markets, issuers seek to finance their
projects and investors want to grow their money. The prices
of financial assets on these markets are affected by factors of A. Artificial Neural Networks
different kinds: economic, psychological and political. This Artificial Neural Networks are computing system with
exposure to exogenous factors makes these markets very non-linear processing units connected by edges (weights).
volatile or even unstable. They are used for a wide variety of problems from time series
To maximize profits and limit potential losses, actors modeling, image classification to text mining.
on these markets (investors, traders and even academic The learning phase of the ANN is done through the
researchers) are constantly looking for tools that can offer adjustment of the weights. To do this, an error is calculated
accurate forecasting in a very short time. by comparing the output of the model and the target value.
For some dynamic markets, intraday trading strategies tend We can formulate the learning task of an ANN as follows:
to be more profitable, hence the need for highly accurate
forecasting tools to track future trends within the desired For a training set D = (Y, X) with k elements and a loss
forecasting horizon. Developed stock markets have been the function L(Yi , YW,b (Xi )) we search parameters (W, b) such
subject of several studies that have tried to offer tools of as :
various kinds to achieve this goal: Times Series Analysis,
Technical Analysis and Machine Learning Techniques.For the k
1X
Moroccan stock market, there is a limited number of studies Args min L(Yi , YW,b (Xi )) (1)
on this subject.
W,b k i=1

To find thes parameters, the error of prediction is back-


This work contributes to this research area. Our goal is the propagated through the ANN and the weights are adjusted
prediction of the movements of the stock market prices in proportionally. Using the gradient descent algorithm each
the very short term (60 min ahead) using Artificial Neural weight Wij is corrected proportionally to the present input
Networks. and error:

978-1-7281-1482-8/19/$31.00 © 2019 IEEE Wij (n + 1) = Wij (n) + ηδi Xj(n) (2)

Authorized licensed use limited to: Shah and Anchor Kutchhi Engineering College. Downloaded on August 03,2021 at 08:48:08 UTC from IEEE Xplore. Restrictions apply.
Where δi is the local error of the network, the constant η III. T HE EXPERIMENTAL SETUPS
is the learning rate wich indicates the step size.
Our goal is the prediction of short-term price changes of
For effective implementation of ANNs, particular attention
listed securities in the Moroccan stock market. We present in
should be paid to the following:
the following the experimental setups adopted in this work
(a) The most critical part of ANN’s implementation is the
fig.1.
choice of its architecture: the number of layers and hidden
units. The choice of a complicated structure can negatively A. Tick by tick Data
impact the generalization of the model.
(b) Particular attention should be given to the choice of In this work we use intraday data, they are called Tick
learning rate, the use of very small values can slow down by tick data. They capture all the price values recorded in
the learning process and the use of very large values can lead a trading session. The advantage of using these data is their
to a divergence in the process. large numbers and the variety of information they can provide
(c) It is also important to reduce the number of input variables. on price behavior in very short time intervals.
using a large number of input variables can slow down the
learning process. TABLE II
T ICK BY TICK DATA
(d) It is important to standardize the values of the input
variables. Time Price Quantity
(e) ANNs suffer from their tendency to over-fit. To remedy 9:00:00 100 1000
this problem, it is necessary to use early stop criteria and a
9:01:00 103 800
regularization techniques.
9:01:55 98 900
B. ANN for Stock Market 9:02:11 105 60
For the Moroccan stock market, few studies have tried to
treat the prediction of movements in the very short term [2],
and this, contrary to the more developed markets for which
the literature is much richer:

TABLE I
ANN FOR S TOCK M ARKET

Studies Studied Market Used methods


[3] Nasdaq-100 index + 6 stocks ANN + Fuzzy
in Nasdaq-100 index Inference System

[4] 5 futures contracts: Multilayer ANN; SVR;

Chicago Mercantile Market Regularized RBF ANN

[5] Turkish stock market Recurrent ANN; Mixture of Experts


[6] 367 public corporations: Univariate ANN / Multivariate ANN
Shanghai Stock Exchange
[7] 4 stocks: NASDAQ ANN + Hidden Markov Model
+ Genetic Algorithm
[8] 9 stocks from Taiwan stock market ANN
+ Case based dynamic window
[9] 4 stocks: NASDAQ ANN + Hidden Markov Model
+ Genetic Algorithm
[10] Sub-index of TAIEX SOM ANN
Taiwan stock market + Genetic Programming
Fig. 1. Main steps of the experimental framework.
[11] Securities from ANN; CART
Taiwan stock market and Logistic regression
[12] Intraday data for the SP500 ANN; GARCH; As experimental datasets we use a selection of 4 stock’s
SVR; Combination prices series from the Moroccan stock market. The entire
dataset covers a period of three years 2013-2015.
Regarding the choice of explanatory variables, most studies The choice of these stocks is motivated by the diversity of
[8, 13–18] use what stock market analysts call Technical In- their behaviors over the period studied, as shown in Figures
dicators. Technical Indicators are handcrafted features largely 2, 3, 4 and 5.
used by market analysts to model markets dynamics. They The datasets are divided into two parts. The first part (2/3
can be roughly classified under the following categories: Sen- of observations) is used to train the models. The second
timent, Flow-of-fund, Raw data, Trend, Momentum, Volume, (1/3) part is for out-of-sample evaluation and comparison of
Cycle and Volatility. performances of different tested models.

Authorized licensed use limited to: Shah and Anchor Kutchhi Engineering College. Downloaded on August 03,2021 at 08:48:08 UTC from IEEE Xplore. Restrictions apply.
TABLE III
C ARACTERISTICS OF THE SELECTED STOCKS

Stocks Mean value Standard Max - Min Number of


Deviation trades
BCP 204 15 243 - 173 24 332
ADI 250 182 558 - 25 27 723
TQM 454 43 595 - 343 28 328
SNP 219 65 335 - 71 13 258

Fig. 3. ADI Stock variation

Fig. 2. BCP Stock variation


Fig. 4. TQM Stock variation

B. Data Discretization
As shown in Table 2, the intraday data are not uniformly For the hidden units we use the ReLU function wich is
spaced. To correct this irregularity we perform a discretization defined as :
of our database in the form of intervals of 60 minutes.
ReLU (x) = max(x, 0) (12)
The ReLU is known to provide a faster learning speed than
C. Input variables : Technical Indicators
the sigmoid function.
As input variable we select 21 technical indicators among To find the arguments defined in the Eq.(1) our ANNs are
the most frequently used ones by market analysts Table 4. trained with 2000 epochs (iterations).
The optimal combination of hyper-parameters of the tested
models is found by the grid search technique.
D. Data Normalization
The input variables have different absolute values. To fix F. Artificial Neural Networks Testing
this issue we use the normalization technique to transform We evaluate the forecasting performance using Mean
these variables. The normalization prevents large input values Absolute Percentage Error (MAPE)
from slowing down the learning process.
Given the error et wich mesures the difference between
0 Xij − µj the predicted value and the target value, MAPE is defined
Xij = (11)
σj as follows:
k
100% X et
Where µj and σj is the mean and standard deviation of M AP E = (13)
variable j. The preprocessed data is fed into the classifiers for k t=1 yt
forecasting stocks mouvements. where: k is the total number of test data and yt is the actuel
stock price.
E. Artificial Neural Networks Training
For the scope of this study, we use different simple and IV. E XPERIMENTAL RESULTS
shallow feedforword ANN with the following architectures: In this section, we present the results of the different tested
- Input layers: with [21+1] neurons for the 21 input variables ANN architectures on the experimental data of four stocks
and a neuron for the bais b; from the moroccan stock market. Tables 5 and 6 present
- Hidden layer: All the tested models have one hidden layer; the comparison of AMPE of ANN architectures with 4, 10,
- Hidden units: The number of hidden units differs between 15 and 20 hidden units. A comparison beteween the results
the tested ANN; on the training and on the testing set is also presented on fig. 7.
- Output layer: with a single output unit.

Authorized licensed use limited to: Shah and Anchor Kutchhi Engineering College. Downloaded on August 03,2021 at 08:48:08 UTC from IEEE Xplore. Restrictions apply.
TABLE IV
L IST OF T ECHNICAL I NDICATORS CONSIDERED

Features Description and Formula


MA5, MA3, MA[q]: is the average price of a stock over q
MA10 intervals.
Pi
Pj
j=i−9
M A10i = (3)
10

EMA5, EMA3, EMA[q]: like MA but assigns weight to more recent


Fig. 5. SNEP Stock variation EMA10 prices.
EM A[q]i = (Pi − EM Ai−1 ) ∗ γ + EM Ai−1
(4)
γ = 2/(1+q)

P(t-q), q=1 to 5 5 lagged values


ROC(q), q=1 to 5
Pi − Pi−q
ROC(q)i = 100 ∗ (5)
Pi−q

SD10 Standard Deviation over 10 previous intervals.


v
u
u 1 X i
SD[q]i = t (Pj − P )2 (6)
q − 1 j=i−9

PSL10 Psychological line over 10 previous intervals.


U Pqi
P SL(q)i = 100 ∗ (7)
q
Fig. 6. Example of tested architecture
UPqi is the total number of intervals regarding stock
price rises of the previous 10 intervals.

The following conclusions can be made from the experi- %K50, %D50 Stochastic oscillator: it contains two lines %K and
mental results: %D over 50 previous intervals
- A ANN with simple architecture (4 hidden units) does not
fully capture the complexity of stock price behavior; Pi − M inq (Pi )
%K(q)i = 100 ∗ (8)
- An improvement was observed following the increase in the M axq (Pi ) − M inq (Pi )
complexity of the architecture used (10 hidden units); %D(q)i = 3 − day M A of %K
- The use of more complex models (15 hidden units) does
not necessarily make it possible to significantly improve the RSI10 Relative strength index line over the 10 previous
quality of forecasts; intervals
- The most complicated models (20 hidden units) fail on the
100
test set and lose the power of generalization obtained by the RSI10 = 100 − (9)
1 + RS10
simple models.
Average gain in 10 intervals
RS10 = (10)
Average loss in 10 intervals

V. C ONCLUDING REMARKS
The prediction of short term variations of stock markets
presents more difficulties than prediction based on daily data
due to the noisy behavior of intraday movements. We pro-
pose a framework to overcome the difficulties related to the
implementation of ANN techniques on this type of data. The
framework consists of different steps of data preprocessing
to get meaningful and ready to use input data. The results
Fig. 7. Comparison of performance measure of experimentations show that the proposed approach makes
it possible to obtain very good outputs using ANN. Further

Authorized licensed use limited to: Shah and Anchor Kutchhi Engineering College. Downloaded on August 03,2021 at 08:48:08 UTC from IEEE Xplore. Restrictions apply.
TABLE V [4] L. Cao and F. Tay, “Support vector machine with adaptive
C OMPARISON OF PERFORMANCE MEASURE parameters in financial time series forecasting,” IEEE
Transactions on Neural Networks, vol. 14, no. 6, pp.
Stocks ANN [22:4:1] ANN [22:10:1] 1506–1518, 2003.
[5] M. S. Yumlu, F. S. Gurgen, and N. Okay, “Turkish stock
Training set Test set Training set Test set market analysis using mixture of experts,” Proceedings of
Engineering of Intelligent Systems (EIS), Madeira, 2004.
BCP 2.81 3.17 0.99 1.02 [6] Q. Cao, K. B. Leggio, and M. J. Schniederjans, “A com-
parison between Fama and French’s model and artificial
ADI 2.71 3.26 0.88 1.18 neural networks in predicting the Chinese stock market,”
Computers & Operations Research, vol. 32, no. 10, pp.
TQM 2.73 3.51 1.07 1.1 2499–2512, Oct. 2005.
[7] M. R. Hassan, B. Nath, and M. Kirley, “A fusion model
SNEP 2.13 3.85 0.97 1.16 of HMM, ANN and GA for stock market forecasting,”
Expert Systems with Applications, vol. 33, no. 1, pp. 171–
180, Jul. 2007.
Mean values 2.595 3.447 0.977 1.115 [8] P.-C. Chang, C.-H. Liu, J.-L. Lin, C.-Y. Fan, and C. S.
Ng, “A neural network with a case based dynamic
window for stock trading prediction,” Expert Systems
TABLE VI with Applications, vol. 36, no. 3, pp. 6889–6898, Apr.
C OMPARISON OF PERFORMANCE MEASURE 2009.
[9] Z. H. Khan, T. S. Alin, and M. A. Hussain, “Price
Stocks ANN[22:15:1] ANN[22:20:1]
prediction of share market using artificial neural network
(ANN),” International Journal of Computer Applica-
Training set Test set Training set Test set tions, vol. 22, no. 2, pp. 42–47, 2011.
[10] C.-M. Hsu, “A hybrid procedure for stock price pre-
BCP 0.81 1.03 0.79 2.82 diction by integrating self-organizing map and genetic
programming,” Expert Systems with Applications, 2011.
ADI 0.71 1.16 0.68 2.8 [11] C.-F. Tsai, Y.-C. Lin, D. C. Yen, and Y.-M. Chen, “Pre-
dicting stock returns by classifier ensembles,” Applied
AQM 0.73 1.2 0.70 2.86
Soft Computing, vol. 11, no. 2, pp. 2452–2459, 2011.
[12] J. C. Reboredo, J. M. Matı́as, and R. Garcia-Rubio,
“Nonlinearity in Forecasting of High-Frequency Stock
SNEP 0.73 1.1 0.71 2.76
Returns,” Computational Economics, vol. 40, no. 3, pp.
245–264, Oct. 2012.
Mean values 0.745 1.122 0.72 2.81 [13] L.-Y. Wei, T.-L. Chen, and T.-H. Ho, “A hybrid model
based on adaptive-network-based fuzzy inference system
to forecast Taiwan stock market,” Expert Systems with
Applications, 2011.
research may include some features selection schemes and the [14] C.-M. Hsu, “A hybrid procedure with feature selection
use of some deep models architectures. for resolving stock/futures price forecasting problems,”
Neural Computing and Applications, vol. 22, no. 3-4,
R EFERENCES pp. 651–671, Mar. 2013.
[1] G. S. Atsalakis and K. P. Valavanis, “Surveying stock [15] S. Banik, A. F. M. Khodadad Khan, M. Anwer, S. Banik,
market forecasting techniques – Part II: Soft computing A. F. M. Khodadad Khan, and M. Anwer, “Hybrid Ma-
methods,” Expert Systems with Applications, vol. 36, chine Learning Technique for Forecasting Dhaka Stock
no. 3, pp. 5932–5941, Apr. 2009. Market Timing Decisions, Hybrid Machine Learning
[2] B. Labiad, A. Berrado, and L. Benabbou, “Machine Technique for Forecasting Dhaka Stock Market Tim-
learning techniques for short term stock movements ing Decisions,” Computational Intelligence and Neuro-
classification for moroccan stock exchange,” in 2016 science, Computational Intelligence and Neuroscience,
11th International Conference on Intelligent Systems: vol. 2014, 2014, p. e318524, Feb. 2014.
Theories and Applications (SITA), Oct 2016, pp. 1–6. [16] A. S. Hussein, I. M. Hamed, and M. F. Tolba, “An
[3] A. Abraham, B. Nath, and P. K. Mahanti, “Hybrid Efficient System for Stock Market Prediction,” in Intelli-
intelligent systems for stock market analysis,” in Compu- gent Systems’2014, D. Filev, J. Jabłkowski, J. Kacprzyk,
tational science-ICCS 2001. Springer, 2001, pp. 337– M. Krawczak, I. Popchev, L. Rutkowski, V. Sgurev,
345. E. Sotirova, P. Szynkarczyk, and S. Zadrozny, Eds.

Authorized licensed use limited to: Shah and Anchor Kutchhi Engineering College. Downloaded on August 03,2021 at 08:48:08 UTC from IEEE Xplore. Restrictions apply.
Cham: Springer International Publishing, 2015, vol. 323,
pp. 871–882.
[17] X. Li, H. Xie, R. Wang, Y. Cai, J. Cao, F. Wang, H. Min,
and X. Deng, “Empirical analysis: stock market predic-
tion via extreme learning machine,” Neural Computing
and Applications, vol. 27, no. 1, pp. 67–78, Jan. 2016.
[18] C. Anish and B. Majhi, “Hybrid nonlinear adaptive
scheme for stock market prediction using feedback
FLANN and factor analysis,” Journal of the Korean
Statistical Society, vol. 45, no. 1, pp. 64–76, 2016.

Authorized licensed use limited to: Shah and Anchor Kutchhi Engineering College. Downloaded on August 03,2021 at 08:48:08 UTC from IEEE Xplore. Restrictions apply.

You might also like