A Machine Learning Model For Stock Market
A Machine Learning Model For Stock Market
A Machine Learning Model For Stock Market
1 2 3
Osman Hegazy , Omar S. Soliman and Mustafa Abdul Salam
1,2
Faculty of Computers and Informatics, Cairo University, Egypt
3
Higher Technological Institute (H.T.I), 10th of Ramadan City, Egypt
2
[email protected], [email protected]
Abstract– Stock market prediction is the act of trying to regularization parameter and the kernel parameters play an important
determine the future value of a company stock or other financial role in the regression system. Therefore, it is necessary to establish a
instrument traded on a financial exchange. The successful methodology for properly selecting the LS-SVM free parameters, in
prediction of a stock's future price will maximize investor’s such a way that the regression obtained by LS-SVM must be robust
gains. This paper proposes a machine learning model to predict against noisy conditions, and it does not need priori user knowledge
stock market price. The proposed algorithm integrates Particle about the influence of the free parameters values in the problem
swarm optimization (PSO) and least square support vector studied [6].
machine (LS-SVM). The PSO algorithm is employed to optimize The perceived advantages of evolutionary strategies as
LS-SVM to predict the daily stock prices. Proposed model is optimization methods motivated some researchers to consider such
based on the study of stocks historical data and technical stochastic methods in the context of optimizing SVM. A survey and
indicators. PSO algorithm selects best free parameters overview of evolutionary algorithms (EAs) found in [7]. Particle
combination for LS-SVM to avoid over-fitting and local minima swarm optimization (PSO) is one of the most used EAs. PSO is a
problems and improve prediction accuracy. The proposed model recently proposed algorithm by James Kennedy and Russell Eberhart
was applied and evaluated using thirteen benchmark financials in 1995, motivated by social behavior of organisms such as bird
datasets and compared with artificial neural network with flocking and fish schooling [8]. The optimizer which is used in the
Levenberg-Marquardt (LM) algorithm. The obtained results particle swarm optimization algorithm, while making adjustment
showed that the proposed model has better prediction accuracy towards "local" and "global" best particles, is conceptually similar to
and the potential of PSO algorithm in optimizing LS-SVM. the crossover operation used by genetic algorithms [9]. As well
particle swarm optimization includes fitness function, which
Index Terms– Least Square Support Vector Machine, Particle measures the closeness of the corresponding solution to the
Swarm Optimization, Technical Indicators and Stock Price optimum. The main difference of particle swarm optimization
Prediction concept from the evolutionary computing is that flying potential
solutions through hyperspace are accelerating toward "better"
solutions, while in evolutionary computation schemes operate
I. INTRODUCTION directly on potential solutions which are represented as locations in
hyperspace [10]. SVM was used in stock market forecasting in [11].
Financial time series forecasting using SVM optimized by PSO was
S TOCK price prediction has been at focus for years since it can
yield significant profits. Predicting the stock market is not a
simple task, mainly as a consequence of the close to random-
presented in [12]. The Optimization of Share Price Prediction Model
Based on Support Vector Machine is presented in [14]. Financial
walk behavior of a stock time series. Fundamental and technical time series forecasting based on wavelet kernel support vector was
analyses were the first two methods used to forecast stock prices. presented in [15]. Computational Intelligence Approaches for Stock
Artificial Neural networks (ANNs) is the most commonly used Price Forecasting was introduced in [16]. A hybrid approach by
technique [1]. In most cases ANNs suffer from over-fitting problem integrating wavelet-based feature extraction with MARS and SVR
due to the large number of parameters to fix, and the little prior user for stock index forecasting was presented in [17]. An interval type-2
knowledge about the relevance of the inputs in the analyzed Fuzzy Logic based system for modeling generation and
problem [2]. summarization of arbitrage opportunities in stock markets was
Also, Support vector machines (SVMs) had been developed as an presented in [18]. Robust stock trading using fuzzy decision trees is
alternative that avoids such limitations. Their practical successes can presented in [19]. Ensemble ANNs-PSO-GA Approach for Day-
be attributed to solid theoretical foundations based on VC-theory [3]. ahead Stock E-exchange Prices Forecasting was presented in [20].
SVM compute globally optimal solutions, unlike those obtained with Index prediction with neuro-genetic hybrid network was proposed in
ANNs, which tend to fall into local minima [4]. [21]. A hybrid fuzzy intelligent agent-based system for stock price
Least squares –support vector machines (LS-SVM) method was prediction was introduced in [22]. Improved Stock Market Prediction
presented in [5], which was reformulated the traditional SVM by Combining Support Vector Machine and Empirical Mode
algorithm. LS-SVM uses a regularized least squares function with Decomposition was presented in [23]. Neural Network Ensemble
equality constraints, leading to a linear system which meets the Model Using PPR and LS-SVR for Stock Market Forecasting was
Karush-Kuhn-Tucker (KKT) conditions for obtaining an optimal proposed in [24]. Computational Intelligence Techniques for Risk
solution. Although LS-SVM simplifies the SVM procedure, the Management in Decision Making was introduced in [25]. Stock
II. LEAST SQUARE SUPPORT VECTOR MACHINE From rows one and three in (3) w Z T a and Ce a
ij ij c1q( xijpb xij ) c2 ( x sbj xij ), j 1,.., n (11) Testing LS-SVM-PSO model with new data
Where w is the inertia weight, xipb is the best variable vector Computing MSE for( LS-SVM, LS-SVM-PSO, and ANN)
sb
encountered so far by particle i , and x is the swarm best
Fig. 2: The Proposed Model
vector, i.e. the best variable vector found by any particle in
the swarm, so far c1 and c 2 are constants, and q and r are The proposed algorithm was tested for many companies
random numbers in the range (0, 1). Once the velocities have which cover all stock sectors in S&P 500 stock market. These
been updated, the variable vector of particle i is modified sectors are Information Technology (Adobe, Hp, and Oracle);
according to: Financials (American Express and Bank of New York);
Health Care (Life Technologies, and Hospera); Energy
xij xij ij , j 1,..., n. (12) (Exxon-Mobile and Duck energy); Communications (AT&T);
Materials (FMC Corporation); Industrials (Honey Well).
The cycle of evaluation followed by updates of velocities
Five technical indicators are calculated from the raw
and positions (and possible update of xipb and x sb ) is then datasets:
repeated until a satisfactory solution has been found. PSO
algorithm is shown in Fig. 1. Relative Strength Index (RSI): A technical momentum
indicator that compares the magnitude of recent gains to
recent losses in an attempt to determine overbought and
oversold conditions of an asset. The formula for
computing the Relative Strength Index is as follows.
RSI = 100- [100 / (1+RS)] (13)
Where RS = Avg. of x days’ up closes / Average of x
days’down closes.
Money Flow Index (MFI): This one measures the
strength of money in and out of a security. The formula
for MFI is as follows:
Money Flow (MF) = Typical Price * Volume. (14)
Fig. 6: Results for American Express Co Fig. 9: Results for Hospera Company
Algorithm
PSO-LS-SVM LS-SVM NN-BP
Company
4
PSO-LSSVM LSSVM NN-BP
3.5
3
2.5
2
1.5
Fig. 13: Results for FMC corporation
1
0.5
0
VI. CONCLUSIONS
to the global minimum. Also, it is capable to overcome the SVR for stock index forecasting”, ELSEVIER, Decision
over-fitting problem which found in ANN, especially in case Support System, 2012.
of fluctuations in stock sector. PSO-LS-SVM algorithm [18] Bernardo, D.:“An interval type-2 Fuzzy Logic based system
parameters can be tuned easily. The performance of the for model generation and summarization of arbitrage
opportunities in stock markets”, IEEE Computational
proposed model is better than LS-SVM and compared Intelligence (UKCI), 2012 12th UK Workshop, pp. 1-7., 2012.
algorithms. LS-SVM-PSO achieves the lowest error value [19] Ochotorena, C.N. :“Robust stock trading using fuzzy decision
followed by single LS-SVM, while ANN-BP algorithm is the trees”, IEEE Conference on Computational Intelligence for
worst one. Financial Engineering & Economics (CIFEr), pp. 1-8, 2012.
[20] Yi X., Jin X., Fengbin L. & Shouyang W. :“Ensemble ANNs-
REFERENCES PSO-GA Approach for Day-ahead Stock E-exchange Prices
Forecasting”, International Journal of Computational
[1] Olivier C., Blaise Pascal University: “Neural network Intelligence Systems, Volume 6, Issue 1, pp.96-114 2013.
modeling for stock movement prediction, state of art”. 2007 [21] Nayak, S.C. :“Index prediction with neuro-genetic hybrid
[2] Leng, X. and Miller, H.-G. : “Input dimension reduction for network: A comparative analysis of performance”, IEEE
load forecasting based on support vector machines”, IEEE International Conference on Computing, Communication and
International Conference on Electric Utility Deregulation, Applications (ICCCA), pp. 1-6, 2012.
Restructuring and Power Technologies (DRPT2004), 2004. [22] Fazel Z.,Esmaeil H., Turksen B.: “A hybrid fuzzy intelligent
[3] Vapnik, V., “The nature of statistical learning”, second agent-based system for stock price prediction”, International
edition, ©Springer, 1999. Journal of Intelligent Systems, Volume 27, Issue 11, pages
[4] Cherkassky, V. and Ma, Y., “Practical Selection of SVM 947–969, 2012.
Parameters and Noise Estimation for SVM regression”. [23] Honghai Y., Haifei L.: “Improved Stock Market Prediction by
Neural Networks, vol., 17, pp. 113-126, 2004. Combining Support Vector Machine and Empirical Mode
[5] Suykens, J. A. K., Gestel, V. T., Brabanter, J. D., Moor, B.D Decomposition”, Fifth International Symposium on
and Vandewalle, J. “Least squares support vector machines”, Computational Intelligence and Design (ISCID), pp. 531 -
World Scientific, 2002. 534 , 2012.
[6] ANDRÉS M., GENARO DAZA, S., CARLOS D., GERMÁN [24] Lingzhi W., Jiansheng W.: “Neural Network Ensemble Model
C. : “Parameter Selection In Least Squares-Support Vector Using PPR and LS-SVR for Stock Market Forecasting”,
Machines Regression Oriented, Using Generalized Cross- Springer, Advanced Intelligent Computing Lecture Notes in
Validation” , Dyna, year 79, Nro. 171, pp. 23-30. Medellin, Computer Science Volume 6838, pp 1-8, 2012.
February, 2012. [25] İhsan K., Cengiz K., Selçuk Ç. :“Computational Intelligence
[7] Carlos A. Coello, Gary B. Lamont, David A. van Veldhuizen: Techniques for Risk Management in Decision Making”,
“Evolutionary Algorithms for Solving Multi-Objective Springer, Handbook on Decision Making Intelligent Systems
Problems”,Springer, 2007. Reference Library Volume 33, pp 9-38, 2012.
[8] D. N. Wilke. “Analysis of the particle swarm optimization [26] Gupta, A. :“Stock market prediction using Hidden Markov
algorithm”, Master's Dissertation, University of Pretoria, Models”, IEEE Engineering and Systems (SCES), 2012
2005. Students Conference on, pp.1-4, 2012.
[9] Khalil A.S.: “An Investigation into Optimization Strategies of [27] Lipo W., Shekhar G.: “Neural Networks and Wavelet De-
Genetic Algorithms and Swarm Intelligence”. Artificial Life Noising for Stock Trading and Prediction”, Springer, Time
(2001). Series Analysis, Modeling and Applications Intelligent
[10] Kennedy J., Spears W.M.: “Matching Algorithms to Systems Reference Library Volume 47, pp 229-247, 2013.
Problems”, An Experimental Test of the Particle Swarm and [28] Suykens, J.A.K.; Vandewalle, J. "Least squares support vector
Some Genetic Algorithms on the Multimodal Problem machine classifiers", Neural Processing Letters, 9 (3), 293-
Generator. Processes. Current as of December 15th, 2003. 300., 1999.
[11] Chun C, Qinghua M, Shuqiang L.: “Research on Support
Vector Regression in the Stock Market Forecasting”
©Springer, Advances in Intelligent and Soft Computing
Volume 148, , pp 607-612, 2012.
[12] Guo Z., Wang H., Liu Q. : “Financial time series forecasting
using LPP and SVM optimized by PSO” © Springer, Soft
Computing Methodologies and Applications , December 2012.
[13] http://finance.yahoo.com.
[14] Xie, G.: “The Optimization of Share Price Prediction Model
Based on Support Vector Machine”, International Conference
on Control, Automation and Systems Engineering (CASE),
pp.1-4., 30-31 July 2011.
[15] Huang C.; Huang L.; Han T.: “Financial time series
forecasting based on wavelet kernel support vector machine”
IEEE, Eighth International Conference on Natural
Computation (ICNC), 2012.
[16] Jui Y.: “Computational Intelligence Approaches for Stock
Price Forecasting”, IEEE International Symposium on
Computer, Consumer and Control (IS3C), pp. 52 - 55, 2012.
[17] Ling J., Chih C., Chi L, Chih H., “A hybrid approach by
integrating wavelet-based feature extraction with MARS and