Close
About
FAQ
Home
Collections
Login
USC Login
Register
0
Selected
Invert selection
Deselect all
Deselect all
Click here to refresh results
Click here to refresh results
USC
/
Digital Library
/
University of Southern California Dissertations and Theses
/
The application of machine learning in stock market
(USC Thesis Other)
The application of machine learning in stock market
PDF
Download
Share
Open document
Flip pages
Contact Us
Contact Us
Copy asset link
Request this asset
Transcript (if available)
Content
1
THE APPLICATION OF MACHINE LEARNING IN
STOCK MARKET
by
Yifan Wei
A Thesis Presented to the
FACULTY OF THE USC GRADUATE SCHOOL
UNIVERSITY OF SOUTHERN CALLIFORNIA
In Partial Fulfillment of the
Requirement for the Degree
MASTER OF SCIENCE
(APPLIED MATHEMATICS)
August 2017
2
Content
Abstract .......................................................................................................................................... 4
1. Introduction ............................................................................................................................... 2
1.1 Research Background and Significance ................................................................................ 2
1.2 Related Research ................................................................................................................... 3
2. Data and Method ....................................................................................................................... 4
2.1 Output Variable ..................................................................................................................... 4
2.2 Input Variable ........................................................................................................................ 4
2.3 Logistic Regression ............................................................................................................... 6
2.3.1 Basic Model .................................................................................................................... 7
2.3.2 Solution: Gradient Descent ............................................................................................. 8
2.4 Neural Network ................................................................................................................... 10
2.4.1 Algorithm Details ......................................................................................................... 11
2.5 Support Vector Machine ...................................................................................................... 12
2.5.1 Algorithm Illustration ................................................................................................... 13
2.5.2 Calculation Process ....................................................................................................... 14
3. Result ........................................................................................................................................ 15
3.1 Logistic Regression ............................................................................................................. 15
3.2 Neural Network ................................................................................................................... 15
3.3 Support Vector Machine ...................................................................................................... 16
4. Discussion ................................................................................................................................. 16
Reference ...................................................................................................................................... 18
3
Appendix ....................................................................................................................................... 20
Appendix 1: Python code for gradient descent algorithm ......................................................... 20
Appendix 2: Python code for neural network ............................................................................ 21
Appendix 3: Python code for inputting dataset ......................................................................... 23
Appendix 4: Stock code, owned industry and their label .......................................................... 24
4
Abstract
The stock market, as a barometer of the market economy, reflects the economic situation
in various regions. More and more people choose to invest in stocks. In order to obtain
substantial gains from the stock, it is important to analyze and forecast stock market trend.
However, the data from stock market is huge, using the traditional method is difficult to make
accurate prediction. This paper is based on the stock price movements of listed companies as the
standard for the classification of stocks forecast, using three algorithms in machine learning
technology: logistic regression, neural network and support vector machine.
In this article, selecting 200 listed companies in 2016 US stock market as a sample;
whether the stock price’s rise or fall rate is greater than that industry market as an output
variable; selecting four categories of nine representative financial indicators as input variables. In
modeling, select 80% of the sample as the training set and 20% of the remaining sample as the
testing set. After the model is established, we compare the prediction accuracy of the three
methods. The correct rate of logical regression is very low, which is only 47 percent. The
accuracy of neural network and support vector machine could reach 68 percent and 74 percent.
Keywords
Machine learning, Stock Market, Logistic regression, Support vector Machine, Neural
Network
1. Introduction
1.1 Research Background and Significance
The stock market is the product of the market economy. Since the production, it has been
highly favored by investors. The stock market has variable different functions. As for listed
companies, they through stock together idle funds, and then put into the social reproduction. In
this way, these companies achieve the concentration and accumulation of capital, to get the
effective use of capital, which play a strategizing role. As for some countries and regions, whose
capital market is well developed, changes in the stock market trend can reflect the current
situation of economic development and future economic development trends. For individual
investors, the stock market is an important way to invest in financial management and to obtain
capital appreciation. Since the stock market has been produced, many statisticians have proposed
a number of analytical methods. For example: Dow theory, tangent theory, and so on. They all
want to make an accurate analysis and forecast of changes in the stock market.
However, the stock market is intricate. It is influenced by economic factors such as
economic cycle, financial policy, political form, the companies’ own situation and the
psychological state of investors. And the stock market is huge. A variety of information appears
to be cluttered. Therefore, it is almost impossible to find valuable information from stock
transaction data using traditional analytical methods. In this case, there is an urgent need to find
new predictive methods to explore the law behind the stock market.
With the development of database technology and the improvement of computer level,
machine learning technology appeared and developed rapidly. Machine learning is a process of
computer autonomous training and extracting valuable information from a large number of data.
3
The traditional data analysis of the stock is based on the perfect mathematical theory based to
analysis the data. However, machine learning technology does not need to be clear under the
premise of false conditions can be analyzed before the previously unknown information of
practical value. And machine learning techniques can handle the huge, cumbersome and
disorganized data generated by the stock market.
Based on the above reasons, this paper uses the machine learning related methods to
analyze and deal with the stock price of listed companies, from the company's annual statements
where has a large number of financial indicators, to find out the financial ratio indicators which
impact stock price of listed companies most, dig out the excellent financial characteristics of
listed companies. Hope that this article can play a guiding role for investors at the time they carry
out stock trading.
1.2 Related Research
The first application of neural networks into the field of stock forecasting is Ledes and
Fabor (1987). This kind of research method is a widening and breakthrough in both ideological
and technical field. American scholar Pati and Shnaprasad (1992) first formally proposed a
wavelet neural network. They use the wavelet function as the mapping function of neurons to
construct a discrete affine wavelet neural network. Based on the artificial neural network and the
logical regression, Penman H. (1989)
!"
proposed an automated prediction method, called "Pr-
measure", which can predict the company's annual surplus changes.
Harman et al. (2000)
[!]
uses the regression algorithm to predict when to buy the stock,
basing on Australian price index, economic growth rate, inflation rate and employment rate as an
independent variable to predict when to buy the stock. The results of the study found that the
4
recommendations provided by decision tree model can get 18.7% of the average annual rate of
return.
Dongsong Zhang, Lina Zhou (2012)
[!]
proposed an idea combining market technical
indicators and fundamental analysis. They applied the artificial neural network algorithm in
machine learning technology, with the two methods of forecasting the future price of the stock
and the fundamentals analysis, to analyze the stock history data and forecast the future price of
the stock. The results show that the future price of the stock, which using technical indicators and
basic analysis of the combination of basic methods, and actual price trend that the stock market
announcing are basically the same. And the error is relatively small. Comparing with the use of
technical indicators analysis method to predict the future price of the stock, this method has some
guidance for making better decisions for investors involved in the stock market.
2. Data and Method
2.1 Output Variable
In this article, we select 200 listed companies in 2016 US stock market as a sample.
Whether the stock price’s rise or fall rate is greater than the industry market is output
variable. If the stock price’s rise or fall rate is greater than that industry, we label ‘1’, otherwise
we label ‘0’. For example, Boeing's share price rose 7.7% in 2016 and Boeing belongs to
industry. Industrial Average rose 16.1% in 2016, which is larger than Boeing. So the label for
Boeing is ‘0’.
2.2 Input Variable
5
As for input variable, if you want to predict the stock price of a listed company, one of
the important factors is the operating efficiency of the listed company. When assessing the
annual operating efficiency of a listed company, it is necessary to select multiple financial
indicators from the financial annual report for comprehensive analysis, generally including the
ability to repay, operational capacity, profitability and growth capacity these four categories of
indicators. Through a comprehensive analysis of them, people could select more investment
value of listed companies to invest.
1. Repayment ability
Short term
Current ratio
Quick ratio
Long term
Assets and abilities
Interest protection multiples
2. Profitability
Return on asset
Rate of return on common stockholders
!
Equity (ROE)
3. Operational capability: Inventory turnover ratio
4. Ability to grow
Growth rate of earning per share EPS
Growth rate of net assets
Repayment ability is the ability of the enterprise to pay the debts incurred in the business
activities. This is a matter of particular concern to corporate creditors, investors and operators.
This paper selects the indicators of the ability to repayment of the enterprise is divided into short-
term and long-term, a total of four indicators.
Current ratio = Current assets / Current liabilities
Quick ratio = (Current assets – Inventory) / Current liabilities
Assets and liabilities = Total assets / Total liabilities × 100%
Interest protection multiples = Earnings before interests taxes / Interest expense
6
Profitability refers to the ability of enterprises to obtain profits from production and
operation. This paper selects the indicators of profitability is return on asset and rate of return on
common stockholders’ equity (ROE).
Return on asset = Net profit / Operating revenue × 100%
Rate of return on common stockholders’ equity (ROE) = Net profit / Net asset × 100%
Operational capacity is the ability of an enterprise to use its assets to obtain profits. This
paper selects the indicators of operational capacity is inventory turnover ratio.
Inventory turnover ratio = Operating cost / Average inventory × 100%
Growth ability reflects the future development of a company. Such as the future size of
the enterprise, the level of profits and the owner's rights and so on. This paper selects the
indicators of growth ability is growth rate of earnings per share (EPS) and growth rate of net
assets.
Growth rate of earnings per share = (Current earnings per share – Earning per share) /
Earning per share × 100%
Growth rate of net assets = (Net assets at the end of the period – Net assets at the
beginning of the period) / Net assets at the beginning of the period × 100%
2.3 Logistic Regression
Logistic regression, also known as logistic regression analysis, is a generalized linear
regression analysis model, commonly used in data mining, automatic disease diagnosis,
economic prediction and other fields. For example, we can use logistic regression to explore the
risk factors that trigger the disease or we can use it to predict the probability of the disease based
on the risk factors. Now we can give an example about gastric cancer disease. Select two groups
7
of people: one group is gastric cancer group and another group is non-gastric cancer group. The
two groups of people must have different signs and lifestyle. Therefore, the dependent variable is
whether the gastric cancer: the value of "yes" or "no". The independent variables can include a
lot, such as age, sex, eating habits, Helicobacter pylori infection. Arguments can be either
continuous or categorical. And then through the logistic regression analysis, you can get the
weight of independent variables. People can generally understand which factors influent gastric
cancer. At the same time, according to the weight, people can predict the possibility of a person
suffering from cancer based on these risk factors.
2.3.1 Basic Model
The test data is 𝑋 𝑥
!
,𝑥
!
,… ,𝑥
!
. The parameters to be learned is 𝛩 (𝛩
!
,𝛩
!
,… ,𝛩
!
)
𝑍= 𝛩
!
𝑥
!
+ 𝛩
!
𝑥
!
+⋯+ 𝛩
!
𝑥
!
Vector representation: 𝑍= 𝛩
!
𝑋
Then process binary data. The Sigmoid function is introduced to smooth the curve:
𝑔 𝑍 =
!
!! !
!!
8
Predictive function: ℎ
!
𝑋 = 𝑔 𝛩
!
𝑋 =
!
!! !
!!
!
!
Expressed by probability:
Positive example (y = 1): ℎ
!
𝑋 =𝑃 𝑦= 1𝑋,𝛩)
Counter Example (y = 0): 1− ℎ
𝛩
𝑋 =𝑃 𝑦=0𝑋,𝛩)
From linear regression, now define cost function: ℎ
!
𝑥
(!)
= 𝛩
!
+ 𝛩
!
𝑥
(!)
Find the appropriate 𝛩
!
,𝛩
!
to make the above formula minimum.
Logistic Regression:
2.3.2 Solution: Gradient Descent
Gradient descent is a first order optimization algorithm. Using gradient descent method to
find a local minimum value of a function, the iterative search must be performed at the specified
step distance in the opposite direction of the current point corresponding to the gradient (or the
approximate gradient).
The gradient descent method is based on the following process:
1) First, suppose the value of Θ, this value can be random, you can also let Θ is an all-
zero vector.
2) Changes the value of Θ so that J (Θ) decreases in the direction in which the gradient
decreases.
9
To make the explanation clearer, give the following figure:
This is a graph showing the relationship between the parameter Θ and the error function
𝐽 (𝛩).
The red part is that 𝐽 (𝛩) has a relatively high value. We need to be able to make the
value of 𝐽 (𝛩) as low as possible. That is, the dark blue part. 𝛩
!
,𝛩
!
represent two dimensions of
the Θ vector. The first step is to give an initial value to Θ, assuming that the initial value given is
the top cross point at the graph. Then we adjust Θ in the direction of the gradient. This will cause
𝐽 (𝛩) to change in the lower direction, as shown in the figure, the end of the algorithm will be
when Θ falls to the point where it can not continue to fall.
Iterative rule:
10
2.4 Neural Network
Neural network is an abstract computational model for simulating human brain thinking
patterns. It consists of a large number of artificial neurons connected by a certain way to form.
And the neural network is a highly nonlinear adaptive organization system. Neural network has a
lot function. We can use it to do classify, forecast and cluster analysis. Its practicality is strong.
This paper mainly uses the back propagation (BP) neural network to establish the classification
model of the three stocks’ data to forecast trends.
The BP neural network contains both the forward propagation of information and the
reverse propagation of errors when establish the classification model. It includes an input layer,
an output layer and one or more hidden layers. When the input layer receives an incoming signal
from the outside, it will be passed to the neurons in the middle hidden layer. And then he output
layer makes some necessary processing of the information come from hidden layer. At this point
the BP neural network completes the forward propagation process. After this, it output the result
of the information processing by the output layer. When the actual value of the neural network
output in the forward propagation process and the expected output value does not satisfy the
predetermined error range, the network will start the reverse propagation process of the error.
Error through the output layer, according to the error gradient method corrects the weight of each
layer. In this way, error correction process transfer to each hidden layer and input layer. The
information forward propagation and the error back propagation process are repeated until the
network output error reaches the pre-set range. The structure of the BP neural network is as
follows:
11
2.4.1 Algorithm Details
Input: data set, learning rate, a multi-layer forward neural network.
Output: a trained neural network.
Initialize weights and bias: Random initialization between -1 and 1, or between -0.5 and
0.5, with each unit having a bias.
For each training instance X, perform the following steps:
1) Forwarded by the input layer:
𝐼
!
= 𝑤
!"
𝑂
!
+ 𝛩
! !
𝑂
!
=
1
1+ 𝑒
!!
!
2) According to the error reverse delivery:
12
For the output layer: 𝐸𝑟𝑟
!
= 𝑂
!
(1− 𝑂
!
)(𝑇
!
− 𝑂
!
)
For hidden layers: 𝐸𝑟𝑟
!
= 𝑂
!
(1− 𝑂
!
) 𝐸𝑟𝑟
!
𝑤
!" !
, 𝛥𝑤
!"
= (𝑙)𝐸𝑟𝑟
!
𝑂
!
Weight update: 𝑤
!"
= 𝑤
!"
+ 𝛥𝑤
!"
Bias update: 𝛥𝛩
!
= (𝑙)𝐸𝑟𝑟
!
, 𝛩
!
= 𝛩
!
+ 𝛥𝛩
!
3) Termination condition: The weight update is below a certain threshold; the predicted
error rate is below a certain threshold; the cycle time up to a certain number.
2.5 Support Vector Machine
The support vector machine comes from the classification problem, which is essentially a
forward neural network. According to the structural risk minimization criterion, the support
vector machine can improve the generalization ability of the classifier as much as possible under
the premise of minimizing the classification error of training samples. The key to the support
vector machine is the kernel function. Low-dimensional space vector sets are often difficult to
divide. The solution is to map them to high-dimensional space. SVM's core idea is to make the
sorting interval the largest, in fact, is the control of generalization ability. That is, not only can
the two categories be separated, but also to maximize the classification interval. Two linearly
separable support vector machine problems are a quadratic programming problem. It can be
transformed into optimization problems.
The most important feature of the economic system is non-linearity. One of the most
critical problems that support vector machines can use in the economic is that SVM can deal
with nonlinear problems. It can be transformed other complex problem into a linear problem in a
high-dimensional space by non-linear transformation. And then find the optimal classification
surface in the transformation space.
13
2.5.1 Algorithm Illustration
As a sorting algorithm, SVM's purpose is to make the margin the largest.
When the case of linear inseperable, separation may be easier in higher dimension.
We use two steps to solve:
1) Using a non-linear mapping to transform the vector points in the original data set into
a higher dimension space
2) Find a linear hyperplane in this high-dimensional space to deal with linear separable
situations.
14
There is an easier sample on the plane:
2.5.2 Calculation Process
Suppose the two-dimensional eigenvector: X (x
!
,x
!
) and think of b as an extra weight.
The hyperplane equation becomes: 𝑤
!
+ 𝑤
!
𝑥
!
+ 𝑤
!
𝑥
!
= 0
All points above the hyperplane are satisfied: 𝑤
!
+ 𝑤
!
𝑥
!
+ 𝑤
!
𝑥
!
> 0
All points below the hyperplane are satisfied: 𝑤
!
+ 𝑤
!
𝑥
!
+ 𝑤
!
𝑥
!
< 0
Adjust the weight so that both sides of the flat definition are satisfied:
𝐻
!
: 𝑤
!
+ 𝑤
!
𝑥
!
+ 𝑤
!
𝑥
!
≥ 1 𝑓𝑜𝑟 𝑦
!
= +1
𝐻
!
: 𝑤
!
+ 𝑤
!
𝑥
!
+ 𝑤
!
𝑥
!
≤ 1 𝑓𝑜𝑟 𝑦
!
= −1
All points on the super-plane of the sides of the marginal are called "support vectors".
Combined the above two functions, we have:
𝑦
!
𝑤
!
+ 𝑤
!
𝑥
!
+ 𝑤
!
𝑥
!
≥ 1 𝑓𝑜𝑟 𝑎𝑛𝑦 𝑖
The above formula can be changed to a restricted convex quadratic optimization problem.
Using the Karush-Kuhn-Tucker (KKT) condition and the Lagrangian formula, the maximum
margin hyperplane (MMH) can be expressed as the following "decision boundary ".
𝑑 𝑋
!
= 𝑦
!
𝛼
!
𝑋
!
𝑋
!
+𝑏
!
!
!!!
15
Among them, 𝑦
!
is the support vector 𝑋
!
!
𝑠 class label. 𝑋
!
is example to test. 𝑎
!
and 𝑏
!
are single
numerical parameters, derived from the above-mentioned optimal algorithm. l is the number of
support vector points.
Now there are two problems. How to choose a reasonable non-linear transformation of
the data to high-dimensional? How to solve the problem of very high computational complexity
when calculating inner product? The answer is using kernel trick.
Normally used kernel functions are: polynomial kernel of degree h; Gaussian radial basis
function kernel; sigmoid function kernel.
3. Result
3.1 Logistic Regression
We set the number of iteration is 10000 and α is 0.0005.
Then we apply logistic regression model to classify the stock. We calculate the
coefficient and then test the model on test set, the predicted value exceeds the range and the
accuracy rate is only 47%. So this model is not satisfying.
Python code of the gradient descent algorithm could be found in appendix 1.
3.2 Neural Network
We build the BP neural network model for the dataset. Since our input data are 9
indicators we mentioned before, we set 9 neurons in the input layer. Our goal in to predict
whether the stock’s rise or fall rate is greater than the industry market, so the number of neurons
in the output layer should be 1. Besides, we use the value 0.2 for the learning rate. For each
16
perceptron, the sigmoid function is Ɵ(s) = 1/(1+𝑒
!!
) or Ɵ(s) = tan(𝑠). And we set 10000
training epochs.
After the training, the predictive accuracy rate for the test set can reach 68 percent.
Python code for neural network could be found in appendix 2.
3.3 Support Vector Machine
In python, we use a library called “sklearn”, which is specifically for machine learning.
We use package “svm” in this library and function SVC to build a model to classify our data.
Python code is:
training_X is the input data and training_Y is output data. The kernel function could be
linear, polynomial, rbf or sigmoid. After the training, the predictive accuracy rate for the test set
can reach 74 percent.
4. Discussion
This paper is on the basis of machine learning technology. We use logistic regression,
neural network and support vector machine three methods, as the standard of the listed
company's stock price growth rate (decline rate), to train model. Then we use our model to
predict whether the stock will grow well or bad. After that, we compare the predict value and
real value. The correct rate of prediction from neural network and support vector machine could
be reach about 70 percent.
Methods of neural network and support vector machine may be some meaningful way to
predict stock market, but it is not perfect.
17
1) The data used in this paper only represents last one year. It is too short. If we want to
have a comprehensive analysis of a stock, we need to consider a longer time data.
2) This article only randomly selected 200 stocks. This is not so representative for the
entire stock market.
3) This paper only considers the impact of some representative financial ratios on share
prices. This may ignore some other important indicators that have an impact on the stock price.
4) This article uses the 2016 annual index to forecast the 2016 stock price changes. These
are the data that already happened. If you want to use the data from first half of 2017 to predict
the second half of 2017 stock trend, which did not occur, perhaps the result will be not so good.
18
Reference
[1] Agrawal R,Lmielinshi T Swmia. Database Mining: A Performance Perspective[J]. IEEE
Trans on Knowledge and Data Engineering, 2009, 4(6): 919-930.
[2] Bollerslov T, Cai J, Song F M. Intraday periodicity, long memoryvolatility, and
macroeconomic announcement effects in the US Treasury bond market[J]. Journal of
Empirical Finance, 2011, 7(1): 38-56.
[3] Dongsong Zhang, Lina Zhou. Discovering Godden Nuggets: Data Mining in Financial
Application [J]. IEEE transactions Systems, 2012,34(4): 513-522.
[4] Han Wook-Shin, Lee Jinsoo, Pham Minh-Duc. A framework for comparisons of disk based
graph indexing techniques [J]. Association for Computing Machinery, 2010, 3(1): 449-459.
[5] Harman et al. A study of applying data mining approach to the information disclosure for
AU’s stock market investors [J]. Expert System with Application, 2000 (9): 156-159.
[6] Jiawei Han, Micheline Kanber. Data mining: Coneeptsand Techniques[M]. Morgan
Kaufmann Pubisher, 2000:137-189.
[7] Labib, K.Vemuri. An Application of Principle Componet Analysis to the Detection and
Visualization of computer Network Attacks [M]. Annals of Telemuncations,2005,
12(9):220-236.
[8] Lu RQ. Artificial intelligence[M]. Beijing; Science Press, 2008:156-189.
[9] Nottola, Condamin, Naim. Application Study of BP Neural Network and Decision tree on
Stock Market Prediction[C]. Ninth International Conference on Hybrid Intelligent System,
1991(8):174-178.
[10] Penman H. Application Study of BP Neural Network and Logistic Regression for stock
investment [J]. Expert System, 1989,5 (12): 22-38.
19
[11] Qian Yu. A Visual Approach to Parameter Selection of Density-Based Noise Removal for
Effective Data Clustering [J]. Journal of software, 2008, 19(8): 1965-1979
[12] Tong-Seng Quah. Improving returns on stock investment through neural network
selection[J] Expert Systems with Applications, 2006(18): 295-301
[13] Tzungpei Hong, Chansheng Kuo, Shengchai Chi. Mining association rules from
quantitative data[J]. Intelligent Date Analysis, 2009, 8(3): 363-376
[14] W.H.Inmon. Building the Data Warehouse[M]. Wiley computer publishing, 2007:12-26.
[15] Wang, J-L, Chan, S-H. Stock market trading rule discovery using two-layer bias decision
tree, Expert Systems with Applications, 2006,30: 605–611.
20
Appendix
Appendix 1: Python code for gradient descent algorithm
import numpy as np
import csv
def gradientDescent(x,y,theta,alpha,m,numIterations):
xTran = np.transpose(x)
for i in range(numIterations):
hypothesis = np.dot(x,theta)
loss = hypothesis-y
cost = np.sum(loss**2)/(2*m)
gradient=np.dot(xTran,loss)/m
theta = theta-alpha*gradient
# print ("Iteration %d | cost :%f" %(i,cost))
return theta
m,n = np.shape(training_X)
n_y = np.shape(testing_Y)
print("m:"+str(m)+" n:"+str(n)+" n_y:"+str(n_y))
numIterations = 10000
alpha = 0.0005
theta = np.ones(n)
theta= gradientDescent(training_X, training_Y, theta, alpha, m, numIterations)
print(theta)
21
Appendix 2: Python code for neural network
import numpy as np
def tanh(x):
return np.tanh(x)
def tanh_deriv(x):
return 1.0 - np.tanh(x)*np.tanh(x)
def logistic(x):
return 1/(1 + np.exp(-x))
def logistic_derivative(x):
return logistic(x)*(1-logistic(x))
class NeuralNetwork:
def __init__(self, layers, activation='tanh'):
"""
:param layers: A list containing the number of units in each layer.
Should be at least two values
:param activation: The activation function to be used. Can be
"logistic" or "tanh"
"""
if activation == 'logistic':
self.activation = logistic
self.activation_deriv = logistic_derivative
elif activation == 'tanh':
self.activation = tanh
self.activation_deriv = tanh_deriv
self.weights = []
for i in range(1, len(layers) - 1):
self.weights.append((2*np.random.random((layers[i - 1] + 1, layers[i] + 1))-1)*0.25)
self.weights.append((2*np.random.random((layers[i] + 1, layers[i + 1]))-1)*0.25)
def fit(self, X, y, learning_rate=0.2, epochs=10000):
X = np.atleast_2d(X)
temp = np.ones([X.shape[0], X.shape[1]+1])
temp[:, 0:-1] = X # adding the bias unit to the input layer
X = temp
y = np.array(y)
for k in range(epochs):
i = np.random.randint(X.shape[0])
a = [X[i]]
for l in range(len(self.weights)): #going forward network, for each layer
a.append(self.activation(np.dot(a[l], self.weights[l]))) #Computer the node value for each layer (O_i) using activation
function
error = y[i] - a[-1] #Computer the error at the top layer
deltas = [error * self.activation_deriv(a[-1])] #For output layer, Err calculation (delta is updated error)
#Staring backprobagation
for l in range(len(a) - 2, 0, -1): # we need to begin at the second to last layer
#Compute the updated error (i,e, deltas) for each node going from top layer to input layer
deltas.append(deltas[-1].dot(self.weights[l].T)*self.activation_deriv(a[l]))
deltas.reverse()
for i in range(len(self.weights)):
layer = np.atleast_2d(a[i])
delta = np.atleast_2d(deltas[i])
22
self.weights[i] += learning_rate * layer.T.dot(delta)
def predict(self, x):
x = np.array(x)
temp = np.ones(x.shape[0]+1)
temp[0:-1] = x
a = temp
for l in range(0, len(self.weights)):
a = self.activation(np.dot(a, self.weights[l]))
return a
23
Appendix 3: Python code for inputting dataset
thesisdata = []
with open('/Users/weiyifan/Desktop/thesis_200.csv', 'rU') as f:
reader = csv.reader(f)
for row in reader:
thesisdata.append(row)
f.close()
trainingdata = thesisdata[:160]
testdata = thesisdata[161:]
training_X = []
for i in trainingdata:
i = map(eval, i)
training_X.append(i[0:8])
training_Y = []
for i in trainingdata:
i = map(eval, i)
training_Y.append(i[9])
testing_X = []
for i in testdata:
i = map(eval, i)
testing_X.append(i[0:8])
testing_Y = []
for i in testdata:
i = map(eval, i)
testing_Y.append(i[9])
24
Appendix 4: Stock code, owned industry and their label
Data source: http://www.nasdaq.com
Code
Owned
GICS
industry
Label
Code
Owned
GICS
industry
Label
AIRI.A Industrials 0
AUO.N Technology 1
AUMN.A Materials 1
AVA.N Utilities 0
AUXO.A Healthcare 1
AVD.N Materials 1
AWX.A Industrials 1
AVP.N Consumer 1
AXN.A Healthcare 0
AVY.N Industrials 0
BAA.A Materials 0
AWI.N Industrials 0
BDR.A Technology 1
AWK.N Utilities 0
BTG.A Materials 1
AWR.N Utilities 0
CMT.A Materials 1
B.N Industrials 1
CPHI.A Healthcare 1
BA.N Industrials 0
CRHM.A Healthcare 1
BAS.N Energy 1
DNN.A Materials 0
BAX.N Healthcare 1
EMAN.A Technology 1
BC.N Industrials 0
ENRJ.A Energy 0
BCC.N Materials 0
ESNC.A Industrials 1
BCE.N Telecom 0
FSI.A Materials 1
BCR.N Healthcare 1
GDP.A Energy 0
BDX.N Healthcare 1
GTE.A Energy 1
BETR.N Consumer 0
HLTH.A Healthcare 0
BG.N Consumer 1
IGC.A Technology 1
BGS.N Consumer 1
IMO.A Energy 0
BHI.N Energy 1
KLDX.A Materials 1
BIO.N Healthcare 1
LEU.A Utilities 0
BIOB.N Healthcare 1
LNG.A Energy 0
BITA.N Technology 0
LODE.A Materials 0
BKH.N Utilities 0
MCF.A Energy 1
BLD.N Industrials 0
MICR.A Healthcare 1
BLL.N Materials 0
NHC.A Healthcare 1
BMS.N Materials 0
NYLD.A.N Utilities 0
BORN.N Consumer 0
ONP.A Materials 0
BP.N Energy 0
PARR.A Energy 0
BRFS.N Consumer 1
PLX.A Healthcare 0
BRSS.N Materials 1
RDS.A.N Energy 0
BSX.N Healthcare 1
REED.A Consumer 0
BTU.N Energy 0
ROX.A Consumer 0
BVN.N Materials 1
RVP.A Healthcare 0
BW.N Industrials 0
25
SENS.A Healthcare 0
BWXT.N Industrials 1
SSY.A Healthcare 1
BXC.N Materials 1
STS.A Industrials 1
CAH.N Healthcare 0
TAP.A.N Consumer 1
CAPL.N Energy 0
TGB.A Materials 1
CAT.N Industrials 1
TGC.A Energy 1
CBB.N Telecom 1
TIS.A Consumer 0
CBD.N Consumer 1
UAMY.A Materials 0
CBI.N Industrials 0
USAS.A Materials 0
CBPX.N Materials 1
UUU.A Technology 0
CC.N Materials 1
VII.A Technology 0
CCE.N Consumer 0
WYY.A Technology 1
CCJ.N Materials 0
XTNT.A Healthcare 0
CCK.N Materials 0
RDS.B.N Energy 1
CCM.N Healthcare 0
WSO.B.N Industrials 1
CCU.N Consumer 0
CIG.C.N Utilities 0
CDE.N Materials 1
AA.N Materials 1
CE.N Materials 1
ABBV.N Healthcare 1
CEA.N Industrials 0
ABC.N Healthcare 0
CEL.N Telecom 1
ABT.N Healthcare 0
CEO.N Energy 0
ACH.N Materials 1
CF.N Materials 0
ADM.N Consumer 1
CGA.N Materials 0
ADS.N Technology 0
CHA.N Telecom 0
ADSW.N Industrials 0
CHD.N Consumer 0
AEE.N Utilities 0
CHE.N Healthcare 1
AEP.N Utilities 0
CHU.N Telecom 0
AES.N Utilities 0
CIG.N Utilities 0
AFI.N Industrials 1
CIR.N Industrials 1
AGCO.N Industrials 1
CJ.N Energy 0
AGI.N Materials 1
CL.N Consumer 0
AGN.N Healthcare 0
CLB.N Energy 0
AGR.N Utilities 0
CLF.N Materials 1
AGRO.N Consumer 0
CLS.N Technology 0
AIT.N Industrials 1
CLX.N Consumer 0
AJRD.N Industrials 0
CMI.N Industrials 1
AKS.N Materials 1
CMP.N Materials 0
ALB.N Materials 1
CNNX.N Energy 1
ALDW.N Energy 0
CNX.N Energy 1
ALE.N Utilities 0
CO.N Healthcare 1
ALG.N Industrials 1
COG.N Energy 1
ALJ.N Energy 0
COL.N Industrials 0
ALK.N Industrials 0
COTY.N Consumer 0
ALLE.N Industrials 0
CPAC.N Materials 1
26
AME.N Industrials 0
CPK.N Utilities 0
AMFW.N Energy 0
CPL.N Utilities 0
AMOV.N Telecom 0
CRL.N Healthcare 0
AMX.N Telecom 0
CRR.N Energy 0
ANET.N Technology 1
CSL.N Industrials 1
AOI.N Consumer 1
CSTM.N Industrials 0
AP.N Industrials 1
CVI.N Energy 0
APA.N Energy 1
CVO.N Industrials 1
APD.N Materials 0
CVS.N Consumer 0
APFH.N Consumer 1
CVX.N Energy 1
APH.N Technology 1
CWT.N Utilities 0
ARA.N Healthcare 0
CX.N Materials 1
ARC.N Industrials 0
CYH.N Healthcare 0
ARCH.N Energy 1
CZZ.N Utilities 0
ARNC.N Materials 0
DAC.N Industrials 0
AROC.N Energy 1
DAL.N Industrials 0
ASPN.N Materials 0
DCO.N Industrials 1
ASX.N Technology 0
DCP.N Energy 0
ATEN.N Technology 1
DD.N Financial 0
ATI.N Materials 1
DF.N Consumer 1
ATW.N Energy 1
DFIN.N Financial 0
Abstract (if available)
Abstract
The stock market, as a barometer of the market economy, reflects the economic situation in various regions. More and more people choose to invest in stocks. In order to obtain substantial gains from the stock, it is important to analyze and forecast stock market trend. However, the data from stock market is huge, using the traditional method is difficult to make accurate prediction. This paper is based on the stock price movements of listed companies as the standard for the classification of stocks forecast, using three algorithms in machine learning technology: logistic regression, neural network and support vector machine. ❧ In this article, selecting 200 listed companies in 2016 US stock market as a sample
Linked assets
University of Southern California Dissertations and Theses
Conceptually similar
PDF
Supervised learning algorithms on factors impacting retweet
PDF
Asset price dynamics simulation and trading strategy
PDF
Recurrent neural networks with tunable activation functions to solve Sylvester equation
PDF
Improvement of binomial trees model and Black-Scholes model in option pricing
PDF
Application of statistical learning on breast cancer dataset
PDF
Finding technical trading rules in high-frequency data by using genetic programming
PDF
Elements of dynamic programming: theory and application
PDF
Interval arithmetic and an application in finance
PDF
Panel data forecasting and application to epidemic disease
PDF
An empirical characterisation of the Bombay Stock Exchange
PDF
Machine learning techniques for perceptual quality enhancement and semantic image segmentation
PDF
Flymodeller: an interactive machine learning platform for automatic fly behavior annotation
PDF
Human appearance analysis and synthesis using deep learning
PDF
Which of stock returns or dividend growth is predictable? A defense of stock return predictability
PDF
A rigorous study of game-theoretic attribution and interaction methods for machine learning explainability
PDF
Designing data-effective machine learning pipeline in application to physics and material science
PDF
An application of Markov chain model in board game revised
PDF
Object detection and digitization from aerial imagery using neural networks
PDF
Construction of orthogonal functions in Hilbert space
PDF
Predicting mortality of sepsis with machine learning model approaches
Asset Metadata
Creator
Wei, Yifan
(author)
Core Title
The application of machine learning in stock market
School
College of Letters, Arts and Sciences
Degree
Master of Science
Degree Program
Applied Mathematics
Publication Date
07/14/2017
Defense Date
07/14/2017
Publisher
University of Southern California
(original),
University of Southern California. Libraries
(digital)
Tag
logistic regression,machine learning,neural network,OAI-PMH Harvest,stock market,support vector machine
Language
English
Contributor
Electronically uploaded by the author
(provenance)
Advisor
Lotosky, Sergey (
committee chair
), Mancera, Ricardo (
committee member
), Sacker, Robert (
committee member
)
Creator Email
wyifan@usc.edu
Permanent Link (DOI)
https://doi.org/10.25549/usctheses-c40-398028
Unique identifier
UC11265718
Identifier
etd-WeiYifan-5514.pdf (filename),usctheses-c40-398028 (legacy record id)
Legacy Identifier
etd-WeiYifan-5514.pdf
Dmrecord
398028
Document Type
Thesis
Rights
Wei, Yifan
Type
texts
Source
University of Southern California
(contributing entity),
University of Southern California Dissertations and Theses
(collection)
Access Conditions
The author retains rights to his/her dissertation, thesis or other graduate work according to U.S. copyright law. Electronic access is being provided by the USC Libraries in agreement with the a...
Repository Name
University of Southern California Digital Library
Repository Location
USC Digital Library, University of Southern California, University Park Campus MC 2810, 3434 South Grand Avenue, 2nd Floor, Los Angeles, California 90089-2810, USA
Tags
logistic regression
machine learning
neural network
stock market
support vector machine