Prediction of Stock Returns Using Machine Learning: A Project Report Submitted To Manipal Academy of Higher Education
Prediction of Stock Returns Using Machine Learning: A Project Report Submitted To Manipal Academy of Higher Education
to
of
Bachelor of Technology
in
Information Technology
by
Sahil Singh
Dr.Sanjay Singh
Professor
Department of I & CT
Manipal Institute of Technology
AUGUST 2020
I dedicate my thesis to my friends and family.
i
DECLARATION
I hereby declare that this project work entitled Prediction of Stock Re-
turns Using Machine Learning is original and has been carried out by me
I. T., Manipal. No part of this work has been submitted for the award of a
Place: Manipal
Date :12-08-20
Sahil Singh
ii
CERTIFICATE
independently under my guidance and supervision for the award of the Degree
iii
ACKNOWLEDGEMENTS
I would llike to thank my internal guide for this project, Dr Sanjay Singh,
iv
ABSTRACT
Finacial market forecasting has been a very challenging problem for both
researchers and industrialists as the markets generally have a very low signal to
Machine Learning domain.There have been attempts to solve this problem us-
ing modified ML techniques.For instance in McNally, Roche, and Caton [8] the
author has tried to predict the directional movement of price of Bitcoin using
LSTM networks.He shows how the LSTM networks outperforms standard time
series forecasting techniques like ARIMA although the best accuracy achieved
predictions.
to modify the noisy price data before using it as input into the model.Two
appoaches have been taken to solve the prediction problem, namely funamental
analysis, in which certain key financial ratios which demonstrate the health
of the company has been used as an input, and Technical Analysis, wherein
input to the model in order smooth out the inherent noise, similar to time
series analysis.
CCS CONCEPTS
v
Contents
Acknowledgements iv
Abstract v
List of Tables ix
List of Figures x
Abbreviations x
1 Introduction 1
1.2 Objectives . . . . . . . . . . . . . . . . . . . . . . 4
2 Methodology 5
vi
2.2 Using Control Systems theory to Filter Time Series
Data . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.4.1 Calculation of K . . . . . . . . . 16
2.3 RSI . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.4 MLP-LSTM . . . . . . . . . . . . . . . . . . . . . 18
3 Results 23
4 Conclusion 29
Appendices 31
vii
A 32
References 34
ProjectDetail 35
viii
List of Tables
ix
List of Figures
terworth filter . . . . . . . . . . . . . . . . . . . 12
2.6 MLP-LSTM . . . . . . . . . . . . . . . . . . . . . 21
x
ABBREVIATIONS
ML : Machine Learning
tp : True Positives
fp : False Positives
fn : False Negatives
tn : True Negatives
xi
Chapter 1
Introduction
the approaches.
ple in McNally, Roche, and Caton [8], the researchers used LSTM
1
like ARIMA, it had only 52 percent accuracy which limits the
not freely available and therefore can further improve the model
2
use it to solve the problem of classification in imbalanced classes.
both the temporal aspect and the spatial aspect of the data.One
al. [11], where they used a CNN-LSTM neural network for sen-
the outpu of these CNNs was fed as input to the LSTM blocks.In
3
ing the performance of a classifier.
1.2 Objectives
time series.
4
Chapter 2
Methodology
i.e. the time series looks the same whether one samples the data
created which shows the nature of the time series i.e whether the
5
Brownian motion.The equation for the Hurst’s exponent is as
follows.
R(n)
E = CnH as n → ∞ (2.1)
S(n)
where, R(n) is the range of sum of deviation from the mean.
surements.
C is a constant.
however the one which has been used in this project is called the
1
Pn
1. The mean, m is given by n i=1 Xi
6
2. The next step is to create a mean adjusted series: Yt =
Xt − m for t = 1, 2, 3 · · · n
Pt
3. We calculate the sum of the deviated series Zt = i=1 Yi for
t = 1, 2, 3 · · · n
min(Z1 , Z2 · · · Zn )
culated:
qP
n
S(n) = 1
n i=1 (Xi − m)2
H > 0.5 we say that the time series is persistent which means that
7
Figure 2.1: A visual representation of behaviour of time series based on the Hurst’s
Exponent value
in turns tells the model whether its possible in the first place
has been calculated using the Closing prices of the previous 150
8
2.2 Using Control Systems theory to Filter
ied and applied in the filed of electronics for the purpose of mainly
mapping of the function f (t) where t is time into the s-plane such
that
Z ∞
F (s) = e−st f (t) (2.2)
0
denoted as
O(s)
= f (s) (2.3)
I(s)
where O(s) is the output and I(s) is the input.
9
following relation holds while using it to a function f (t)
f (t − k) = Z −k f (t) (2.4)
F (t) Z −1 + Z −2 + · · · Z −N
= (2.5)
f (t) N
quency ω is given by
For our purpose,we will be using digital filters since the finan-
To smoothen the data, the simplest and the most widely used
needed as inputs to the Moving Average which creates lag i.e. the
10
the digital version of Butterworth filter as given in Ehlers [1].The
c1 = 1 − c2 − c3
Where O(t) is the filtered time series while I(t) is the orignal
response is same for freuencies less than the cutoff frequency, af-
11
Figure 2.2: Power,Frequency and phase,frequency plot for Butterworth filter
Figure 2.3: Power,Frequency and phase,frequency plot for Moving Average filter
12
2.2.2 High Pass Digital Filters
than the cutoff frequency and let the lower ones pass.
filter
series.
13
Figure 2.4: High Pass Filter Gain-Frequency plot
14
gle pole High pass filter only attenuuates at the rate of -6db per
is for this reason we use a two-pole high pass filter so that the
15
2.2.4.1 Calculation of K
−1.5 = 20 log10 (K 19 )
combination of high pass and low pass filter will have to be used.In
this project, the data of daily closing prices is first passed through
2.3 RSI
16
SM M A(U, n)
RS =
SM M A(D, n)
where SMMA(U,n) is the average of positive returns over the
last n time periods and SMMA(D,n) does the same for negative
returns.
lowing formula;
100
RSI = 100 −
1 + RS
100 ∗ SM M A(U, n)
RSI = (2.10)
SM M A(U, n) + SM M A(D, n)
where 100 is just a scaling term and can be ignored. Let D(t) =
17
c3 are given in equation (2.7).
(2.11)
Before feeding input into the RSI, the original time series is
2.4 MLP-LSTM
of the MLP was fed into the input of the corresponding LSTM
block.
Three inputs were taken for each timestep i.e. RSI value of
18
has been positive or negative in the next 10 days.
is the ith feature of the timestep t.The output from the MLP will
was downloaded and the Key Financial Ratios were taken as in-
put which were fed into a prediction model after being normal-
next year.
i.e. the maximum and minimum value to be used for the stocks in
19
Figure 2.5: Details of the MLP-LSTM neural network used
20
Label3 hhti
Cell Label1
cht−1i × + chti
Tanh
× ×
X2t
X3t .. O1
.. . xhti Input
Xnt .
are recorded.
2. In the next stage the data vectors which were assigned the
21
the next round of classification.After choosing the data vec-
22
Chapter 3
Results
23
TP
Precision = TP+FP
tion
TP × TN − FP × FN
MCC = p (3.1)
(TP + FP)(TP + FN)(TN + FP)(TN + FN)
sures the balance between precision and recall and MCC mea-
classifier and Ada Boost Classifier, the results are given below
in the table below. In table 3.1, accuracy and F1-score for var-
24
with neural nets, the method of manifold mixup has been used
to generate new training vectors such that the effect of class im-
frequently occuring class label and lower weights to the more fre-
For Beta:
2. The training vectors are created such that the new training
25
For Normal:
can take the value of any integer assigned by the user, accord-
this case the weights will be more centered around the mean
others.
Ada Boost has been used along with Decision tree classifier and
6.
26
Table 3.1: Perfomance of Neural Net and AdaBoost Classifier in Fundamental
27
3.2 Results on Technical Analysis
The best accuracy obtained from the technical analysis time series
28
Chapter 4
Conclusion
that our models predict the direction of the returns better than
systems.
In this project, the time series data used was sampled at daily
would make the model more robust and adaptive to all kinds
of condition.
29
It is also observed that the scope of this project was limited
30
Appendices
31
Appendix A
def b u t t e r w o r t h 2 ( s e l f , c l , p e r i o d ) :
c l 1=c l
c l = np . z e r o s ( len ( c l ) )
a = np . exp ( − 1 .4 1 4 ∗ 3 .1 4 15 9 / p e r i o d )
b = 2∗ a∗np . c o s ( 1 . 4 1 4 ∗ ( 3 . 1 4 1 5 9 / 2 ) / p e r i o d )
c2 =b
c3=−a∗a
c1=1−c2−c3
c l [ i ] = c1 ∗( c l 1 [ i ]+ c l 1 [ i −1])/2+ c2 ∗ c l [ i −1]+c
return c l
32
def h i g h p a s s 2 ( s e l f , c l , p e r i o d ) :
hp = np . z e r o s ( len ( c l ) )
c o s e l e m e n t=np . c o s ( 0 . 7 0 7 ∗ 2 ∗ np . p i / p e r i o d )
s i n e l e m e n t=np . s i n ( 0 . 7 0 7 ∗ 2 ∗ np . p i / p e r i o d )
print ( alpha )
peak = np . z e r o s ( len ( c l ) )
return hp
33
References
Advanced Technical Trading Concepts”. In: John Wiley & Sons, 2013,
pp. 31–33.
Advanced Technical Trading Concepts”. In: John Wiley & Sons, 2013,
pp. 77–79.
Advanced Technical Trading Concepts”. In: John Wiley & Sons, 2013,
pp. 54–55.
34
[8] S. McNally, J. Roche, and S. Caton. “Predicting the Price of Bitcoin
[9] Yensen Ni, Yi-Ching Liao, and Paoyu Huang. “Momentum in the Chi-
[11] Jin Wang et al. “Dimensional sentiment analysis using a regional CNN-
LSTM model”. In: Proceedings of the 54th Annual Meeting of the Asso-
pp. 225–230.
35
Table A.1: Project Detail
Student Details
Project Details
36