SVM Based Stock Prediction Analysis
SVM Based Stock Prediction Analysis
Volume 3 (2023)
1. Introduction
In recent years, artificial intelligence technology (big data, data mining, machine learning
technology) has developed rapidly, and the resulting data analysis models have mapped low-
dimensional indistinguishable data to high-dimensional distinguishable data through various spatial
transformations and dimensional transformations, greatly compensating for the human brain's lack of
analysis of non-linear laws. We can use historical asset prices, trading data, etc. as information input
to the model, analyze the characteristics of the data, and use various classification and regression
prediction algorithms in the field of machine learning to construct trading strategies. In actual
secondary market securities trading, stocks have time-series characteristics, so recurrent neural
networks are often used for stock price prediction. However, due to the weak ability to portray time
series data with a long memory, the general recurrent neural model is prone to gradient explosion and
overlearning, which makes training very difficult. In contrast, support vector machine algorithms do
not increase the computational complexity when mapping to higher dimensional spaces because they
use kernel functions to overcome the problems of dimensional catastrophe and nonlinear
differentiability [1]. In addition to this, support vector machines overcome the problem that traditional
neural networks can only find local optimal solutions and discover the global minimum of the
objective function using known efficient algorithms, and also have better generalization capabilities.
12
Highlights in Business, Economics and Management MSIE 2022
Volume 3 (2023)
When the training samples are linearly divisible, assuming that the sample data set is , ,
1,2, … , , ∈ , ∈ 1, 1 , then any hyperplane can be represented by 0 to be
represented. Then in the n-dimensional space, the distance from the point x to the line 0
is the distance of ‖ ‖
, ⋯ . Assume that the hyperplane , can
classify the training samples correctly, i.e., for , ∈ , if 1 , then we have
0 ; if 1, then we have 0 . So far we have the upper and lower hyperplanes of the
maximally spaced hyperplane, and the distance of each support vector to the hyperplane can be
written as ‖ ‖
, then the maximization of the distance can be expressed as max 2 ‖ ‖
,
max ‖ , thus constructing the Lagrangian function. min max , , ‖ ‖ ∑ 1
, ‖ ,
. . 0 , and then use the strong duality transformation to solve. max ∑
∑ ∑ . .∑ 0, 0 . [6]
(2) Soft interval maximization
In practical applications, fully linearly divisible samples are rare, so soft spacing is introduced.
Compared with the harsh conditions of hard spacing, soft spacing allows individual sample points to
appear inside the spacing band, and this part of the sample points cannot satisfy the constraints1
0 .In order to measure the degree of soft spacing, we introduce a relaxation variable
for each sample , such that 0, the 1 0 , the optimization objective
becomes min ‖ ‖ ∑ . . , 1 0 , 0 ,
1,2, … , . Thus, the Lagrangian function is constructed as. min max , , , , ‖ ‖
, , ,
∑ ∑ 1 ∑ . . 0, 0 ,which can then be
solved by using the strong duality transformation.
max ∑ ∑ ∑ . .∑ 0, 0, 0 . [7]
(3) Kernel function and nonlinear interval maximization
Hard and soft spacing refers to the complete linear separability of samples or linear separability of
most samples, but it will encounter sample points that are not linearly separable. For continuous
samples, the solution to this situation is to map the samples that are linearly indistinguishable in the
original space to a higher dimensional space, make the sample points linearly distinguishable in the
higher dimensional space, and then construct the optimal classification hyperplane, which is a
nonlinear SVM [8]. If the original sample points are denoted by x and denotes the new vector
obtained after mapping x to a higher dimensional feature space, then the segmentation hyperplane
can be expressed as . Thus, the pairwise problem of nonlinear SVM is
transformed into. max ∑ ∑ ∑ . .∑ 0,
0, 0 . The kernel function is a function that calculates the inner product of two vectors
in the space after the implicit mapping, and it does this by first doing the inner product on the feature
vector and then using the function k to change it, which helps to avoid the calculation in the high-
dimensional space and greatly simplifies the problem solution, which is equivalent to doing the kernel
mapping on the vector first and then doing the inner product, which shows that the introduction of
the kernel function reduces our computation on the one hand, and reduces our storage data on the
other hand memory usage. The common kernel functions are: linear kernel function ( ,
), polynomial kernel function ( , ), and Gaussian kernel function
( ). [9]
,
13
Highlights in Business, Economics and Management MSIE 2022
Volume 3 (2023)
3.1 Pre-processing
Data pre-processing is a key step in the modeling process. In most cases, the raw data obtained
from the data acquisition stage may have missing values or outliers, so preprocessing is required.
Preprocessing data not only improves the prediction of the model, but also reduces the arithmetic
power loss, shortens the computation time, and subsequently optimizes the model efficiency [10].
The basic process adopted in this paper includes: applying python's data preprocessing function
IsNull() to detect missing values, and no missing values are found, and performing max-min
normalization on data such as volume.
3.2 Modeling
The SVM model of the Sklearn library from the Python third-party library is called, and the linear
kernel function, polynomial function, sigmoid function, and RBF function are called to construct the
SVM model separately, to analyze the effect of different kernel functions on the stock prediction of
the SVM model.
There are many ways to evaluate models, but both classification and regression problems can be
broadly based on two methods. In stock price forecasting, the mean square error MSE and the
coefficient of determination R2 can be used; in stock price trend forecasting, the F1 value and the
ROC curve are used [11].
In this paper, firstly, different kernel functions are evaluated based on four dimensions: training
set score, test set score, test set mean square deviation, and test set R2 score, and the specific scores
are shown in Figure 1. From the comparison of these four data, the linear kernel function and RBF
function outperform the polynomial function and sigmoid function.
14
Highlights in Business, Economics and Management MSIE 2022
Volume 3 (2023)
Secondly, this paper evaluates the model by the different areas under the ROC curve, the larger
the area under the ROC curve, the higher the accuracy. And from the comparison of ROC curves, the
inflection points of ROC curves of different kernel function SVM models are different, among which
the SVM model with linear kernel function has the highest inflection point, and the specific curve is
shown in Figure 1.
15
Highlights in Business, Economics and Management MSIE 2022
Volume 3 (2023)
16
Highlights in Business, Economics and Management MSIE 2022
Volume 3 (2023)
plt.show()
return 0
4. Main Conclusion
Stock prices fluctuate frequently and, in many cases, quite dramatically. For a more stable stock
market, it is necessary to reduce uncertainty for investors and funders and to enable stock forecasts
to be applied more flexibly between investors and funders in order to achieve an optimal resource
allocation market.
17
Highlights in Business, Economics and Management MSIE 2022
Volume 3 (2023)
In this paper, SVM is applied to stock market forecasting. SVM is used to select the kernel function
and optimize the parameters, and then find the optimal model to measure the stock trend. Based on
the fast convergence and high accuracy of the SVM model, the SVM model can predict the stock data
well and make the prediction results very close to the actual values. Kernel function selection and
kernel parameter selection have a very important impact on the learning and prediction performance
of SVM. Different kernel functions and kernel parameters are directly related to the accuracy of the
operation results. svm has good accuracy in predicting stock prices and provides a meaningful
analysis tool for general investors.
5. Summary
Stock data are chaotic and disorderly. The original variables of the dataset used in this paper are
trading date, opening price, closing price, minimum price, maximum price, volume, and increase/
decrease rate. The SVM algorithms using different kernel functions for stock prediction are different.
From the experimental analysis results, the LINEAR kernel function is more suitable for stock
prediction analysis.
References
[1] Li, Hang. Statistical learning methods. Beijing: Tsinghua University Press,2012.
[2] Xixi Xu. Research on stock price prediction and investment strategy based on support vector machine.
Xi'an: Northwest University Academic, 2018.
[3] Shahi Tej Bahadur, Shrestha Ashish, Neupane Arjun, Guo William. stock Price Forecasting with Deep
Learning: A Comparative Study. Mathematics,2020,8(9).
[4] Zhang, X.-G. On statistical learning theory and support vector machines. Journal of Automation,
2000,01:36-46.
[5] Gu Yaxiang. Ding S. F. Advances in support vector machine research. Computer Science, 2011,02:14-17.
[6] Tang, Inv. Research on support vector machine algorithm based on statistical learning theory. Huazhong
University of Science and Technology, 2005.08.
[7] Chen, Yi-Bing. Zhang L. L., Nie G. L. et al. financial time series forecasting based on improved support
vector regression machine. Mathematical Practice and Perceptions, 2012, 42(04): 38-44.
[8] Jun Wei. An efficient support vector machine parameter optimization algorithm. Computer Technology
and Development. 2015,25(12):97-104.
[9] Liu M, Zhou S, Wu H. A new hybrid kernel function support vector machine. Computer Applications,
2009, 29(S2):167-168.
[10] Yang XW, Hao ZF. Algorithm design and analysis of support vector machines. Beijing: Science Press,
2013.
[11] Ren, Y. F. Some research on SVM model improvement. Nanjing University of Posts and
Telecommunications, 2013.
18