Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
We hereby declare that we carried out the work reported in this project ‘Stock Market Price
Prediction using Machine Learning, under the supervision of professor who deliver us
presentations. We solemnly declare that to the best of our knowledge, no part of this report
has been submitted here or elsewhere in a previous application for award of a degree. All
sources of knowledge used have been duly acknowledged.
Approval
This is to certify that the report titled “Stock Market Price Prediction using Machine
Learning” has been carried out by and has been read and approved for meeting part of the
requirements and regulations. It has been thoroughly reviewed and checked for both
content and accuracy.
Acknowledgment
Many capable people like our seniors have contributed in the field of Machine Learning
Project. It has been thoroughly reviewed and checked for both content and accuracy. Our
respected professor has contributed greatly to this project throughout the many phases of
development Dr. Kashif Javed have done an outstanding job editing the manuscript.
Thanks to all for management of the art and text program. We wish to express our
appreciation to those already mentioned as well as the reviewers who provided many
valuable suggestions and constructive criticism that greatly influenced this report.
Dedications
“Stock Market Price Prediction using Machine Learning”, in this project, we learnt many
technical skills their while visiting to whole algorithms. Moreover, this project was for
polishing our practical knowledge about machine learning that how it works. The training
of modules, testing on test, validation set, calculating errors, accuracy guided and showed
to us brief overview of machine learning algorithms and platforms used for using
algorithms.
8|Page
Contents
List of Figures
Figure 1: Relation between Predicted/Actual Closing Price for 1-year Period ..................... 17
Figure 2: Dataset of Descon Oxychem ................................................................................... 18
Figure 3: Reading Dataset ....................................................................................................... 19
Figure 4: Output after Reading Dataset ................................................................................. 19
Figure 5: Jupyter Notebook for Python Code ........................................................................ 19
Figure 6: Creating Data Frame Variables ............................................................................... 19
Figure 7: Output after Preprocessing .....................................................................................20
Figure 8: Basic Graph between Data and Closing Price ........................................................20
Figure 9: KNN Model for Making Predictions .......................................................................20
Figure 10: KNN Results ........................................................................................................... 21
Figure 11: Calculating ERMS ................................................................................................... 21
Figure 12: Comparing Results ................................................................................................. 21
Figure 13: High/Low/Open/close with 500 epochs ...............................................................24
Figure 14: LSTM Model ........................................................................................................... 25
Figure 15: LSTM Results .......................................................................................................... 25
Figure 16: Comparing Results ................................................................................................ 26
11 | P a g e
Chapter No.1
Introduction
Stock market is a collection of buyers and sellers which show their interest with the trading
of stocks which are released by the companies for elevating the capital and are bought by
the investors in order to get a portion of the company. Stock Market is always aggressive;
you don’t know what will happen next as it is very difficult to predict the future stock price
of the companies since it keeps fluctuating every day. As we all know a company’s stock
depends on many factors and taking into account the nonlinearities and discontinuities of
the factors which are considered to impact stock markets. Some of the reasons are like
company related news, political events natural disasters etc. stock price prediction is one
of the most important issues to be investigated in academic and financial researches.
The stock market is an evolutionary, complex and a dynamic system. Market prediction is
characterized by noise, data intensity, non-stationary, uncertainty and hidden
relationships. The prediction of trend in stock market exchange has been a challenging and
important research topic. It is challenging because the data is noisy and not stationary. It
is important because it can yield important results for decision makers. Stock market is
such a location where companies invest high capital and do their shares trading. Stock
market prediction has disproved the Efficient Market Hypothesis which states that it is
impossible to predict the market because it is efficient. Researchers have proved that it is
possible to predict the stock market. The ability of making future stock market prediction
is an important factor for investors for making money. It also helps investors to make
selling or buying decisions to generate higher profits.
The following report will delve into the concept of using algorithms to attempt to predict
stock market prediction. This is an important aspect to knowledge because it can give rise
to many prediction techniques in the future and it introduces a link between the finance
field and the field of computer science. To explain the approach of the research, question
the following section will explain the scope of the project.
This report will explore the ability of using the KNN, Linear Regression and Long-Short
Term Memory algorithms as methods of predicting stock market movements. Several steps
will be followed as we attempt to answer and explore the research question.
12 | P a g e
Chapter No.2
Literature View
M.Suresh Babu et al., 2012, this paper investigates the significant clustering calculations: K-
Means, Hierarchical grouping calculation and turn around K-Means and look at the
execution of these noteworthy clustering calculations on part of effectively class savvy
group building capacity of calculation. The proposed strategy comprises of three stages. To
start with, they change over each money related report into an element vector and utilize
the various levelled agglomerative grouping strategy to isolate the changed over element
vectors into bunches. They consider both subjective and quantitative highlights in
monetary reports. Second, they join the upsides of two grouping techniques to propose a
compelling clustering strategy. Third, picking a fitting number of parts in HAC can limit
the bunches produced and in this way enhance the nature of the grouping created by the
K-means clustering.
Khalid Alkhatib et al., 2013, applied “K-Nearest Neighbour” algorithm and indirect relapse
approach so as to anticipate stock costs for an example of six noteworthy organizations
recorded on the Jordanian stock exchange to help financial specialists, administration,
chiefs, and clients in making right and educated ventures choices. As indicated by the
outcomes, the k-NN algorithm is vigorous with little mistake proportion; subsequently the
outcomes were sound and furthermore sensible.
Mahajan Shubhrata D et al., 2016, this paper is to anticipate future stock value utilizing
forecast idea. In that Parse Records at that point figure anticipated esteem and send to
client. Also, consequently perform activities like buy and deal shares utilizing
Automation idea. For that utilization Naïve Bayes Algorithm. There is Real time Access
by Download log shapes hurray back site and Store in dataset. The investigations uncover
a high capability of Naïve Bayes Algorithm in foreseeing the arrival on interest in the offer
market.
Xiao Ding et al., 2015, recommended that a deep learning technique for occasion driven
securities exchange expectation. Initially, occasions are removed from news message, and
spoke to as thick vectors, prepared utilizing a novel neural tensor system. Second, a deep
convolutional neural system is utilized to demonstrate both here and now and long haul
impacts of occasions on stock value developments. They exhibited that deep learning is
helpful for occasion driven stock value development forecast by proposing a novel neural
tensor system for learning occasion embedding, and utilizing a deep convolutional neural
13 | P a g e
system to demonstrate the joined impact of long haul occasions and here and now
occasions on stock value developments.
Adebiyi Ayodele et al., 2012, proposed investigation work to enhance the exactness of every
day stock value forecast of securities exchange records utilizing artificial neural
networks. The examination utilized three-layer, multilayer perceptron models (a
feedforward neural system demonstrate) prepared with backpropagation calculation.
This paper displays that hybridized approach can possibly upgrade the nature of basic
leadership of financial specialists in money markets by offering more precise stock forecast
contrasted with existing specialized investigation based approach.
Luckyson Khaidem et al., 2016, proposed a novel method to limit the danger of interest in
stock advertise by foreseeing the profits of a stock utilizing a class of intense machine
learning calculations known as ensemble learning. They have utilized four administered
learning calculations, i.e “Logistic Regression, Gaussian Discriminant Analysis,
Quadratic Discriminant Analysis, and SVM”.
Dinesh Bhuria et al., 2017, surveyed about stock market prediction using regression
techniques and proposed productive regression way to deal with foresee the stock market
cost from stock market information based. In future the consequences of multiple
regression approach could be enhanced utilizing more number of factors. This
examination ponder is to help the stock merchants and speculators for putting cash in the
stock market. The expectation plays an imperative part in stock market business which is
exceptionally confused and testing process due to dynamic nature of the stock market.
Murtaza Roondiwala, Harshal Patel, Shraddha Varma 2018 presented paper was modeled
and predicted the stock returns of NIFTY 50 using LSTM. Collected 5 years of historical
data of NIFTY 50 and used it for the training and validation purposes for the model.
14 | P a g e
Chapter No.3
Problem Statement
The stock market is an evolutionary, complex and a dynamic system. Market prediction is
characterized by noise, data intensity, non-stationary, uncertainty and hidden
relationships. The prediction of trend in stock market exchange has been a challenging and
important research topic. It is challenging because the data is noisy and not stationary. It
is important because it can yield important results for decision makers.
Chapter No.4
Proposed Solution
In order to predict the stock prices in future markets, we have analyzed papers and has
given an overview on how these algorithms give precise and accurate future predictions. In
this project, we used several algorithms from which we observed that not all the algorithms
implemented can predict data we need. There has been a basic requirement for
computerized and atomized ways to deal with powerful and proficient usage of huge
measure of money related information to help organizations and people in vital arranging
and decision making on investments. We propose an online learning algorithm for
predicting the end-of-day price of a given stock with the help of KNN, Linear Regression
and Long Short Term Memory (LSTM), a type of Recurrent Neural Network (RNN).
The following report will delve into the concept of using algorithms to attempt to predict
stock market prediction. This is an important aspect to knowledge because it can give rise
to many prediction techniques in the future and it introduces a link between the finance
field and the field of computer science. To explain the approach of the research, question
the following section will explain the scope of the project.
This report will explore the ability of using the KNN, Linear Regression and Long-Short
Term Memory algorithms as methods of predicting stock market movements. Several steps
will be followed as we attempt to answer and explore the research question.
16 | P a g e
Chapter No.5
Research Paper -I
Stock Price Prediction Using K-Nearest Neighbor (kNN)
Algorithm
Khalid Alkhatib, Hassan Najadat, Ismail Hmeidi ( Vol. 3 No. 3; March 2013)
The kNN algorithm method is used on the stock data. Also, mathematical calculations and
visualization models are provided and discussed below.
5.1 Methodology
K-nearest neighbor technique is a machine learning algorithm that is considered as simple
to implement (Aha et al. 1991). The stock prediction problem can be mapped into a
similarity based classification. The historical stock data and the test data is mapped into a
set of vectors. Each vector represents N dimension for each stock features. Then, a
similarity metric such as Euclidean distance is computed to take a decision. In this section,
a description of kNN is provided. kNN is considered a lazy learning that does not build a
model or function previously, but yields the closest k records of the training data set that
have the highest similarity to the test (i.e. query record). Then, a majority vote is performed
among the selected k records to determine the class label and then assigned it to the query
record.
The prediction of stock market closing price is computed using kNN as follows:
a) Determine the number of nearest neighbors, k.
b) Compute the distance between the training samples and the query record.
ESS =
Chapter No.6
Implementing Research Paper -I
6.4 Results
The results are given as follows where origin color in plot shows the predicted price and
blue color shows the original price.
21 | P a g e
The KNN results are not quite promising if we compare it to our implementation. We got
Erms of 6.1 while in paper it is mentioned of 0.8.
22 | P a g e
Chapter No.7
Research Paper -II
Long Short-Term memory is one of the most successful RNNs architectures. LSTM
introduces the memory cell, a unit of computation that replaces traditional artificial
neurons in the hidden layer of the network. With these memory cells, networks are able to
effectively associate memories and input remote in time, hence suit to grasp the structure
of data dynamically over time with high prediction capacity.
7.1 Methodology
Various types of neural networks can be developed by the combination of different factors
like network topology, training method etc. For this experiment, they considered Recurrent
Neural Network and Long Short-Term Memory. This section we will discuss the
methodology of our system. Our system consists of several stages which are as follows: -
Raw Data
Data
Visualize Graph
Preprocessing
Feature
Calculate RMSE
Extraction
After performing various simulations with a different number of parameters and epochs,
they observed that by taking 4 features set (High/Low/Open/ Close) with 500 epochs they
achieved the best results with training RMSE of 0.00983 and testing RMSE of 0.00859.
24 | P a g e
Chapter No.8
Implementing Research Paper -II
Here in this paper implementation, the first four steps; Dataset Collection, Division of
Dataset, Environment & IDE and Preprocessing of dataset is same, also calculating root
mean square error is same as above in KNN Model. So, proceeding further:
The input gate: The input gate adds information to the cell state
The forget gate: It removes the information that is no longer required by the model
The output gate: Output Gate at LSTM selects the information to be shown as output
8.2 Results
The following graph shows the reation between the actual and predicted stock price.
Stable and robust with small error ratio, so the results are rational and reasonable. RMSE
is found to be 0.04 with confusion matrix given as follow below:
Confusion matrix for the actual gradient Vs. the predicted gradient. Accuracy found to be
83.3%.
Up Down
Up 14 1 15
Down 3 6 9
17 7 25
27 | P a g e
Chapter No.9
Conclusion
We implemented two papers on Jupyter and carried out quite promising results in
comparison with research paper results. Overall accuracy of LSTM is better than the KNN
approach. It was a great experience and was a learning platform for us to polish our
technical skills and practical knowledge. We learnt many technical practical work related
to machine learning algorithms, about training, testing and implementation here in our
project. “Stock Market Price Prediction using Machine Learning”, in this project, we learnt
many technical skills their while visiting to whole algorithms. Moreover, this project was
for polishing our practical knowledge about machine learning that how it works. The
training of modules, testing on test, validation set, calculating errors, accuracy guided and
showed to us brief overview of machine learning algorithms and platforms used for using
algorithms.
28 | P a g e
Chapter No.10
References
https://www.analyticsvidhya.com/blog/2018/10/predicting-stock-price-machine-
learningnd-deep-learning-techniques-python/
https://github.com/jerrytigerxu/Stock-Price-Prediction
[2] Kai Chen, Yi Zhou and FangyanDai ―A LSTM-based method for stock returns
prediction: A case study of China stock market,‖ IEEE International Conference on Big
Data,2015. [3] A.U.S.S Pradeep, SorenGoyal, J. A. Bloom, I. J. Cox, and M. Miller,
―Detection of statistical arbitrage using machine learning techniques in Indian Stock
market,‖ IIT Kanpur, April 15, 2013.
[3] Khalid Alkhatib Hassan Najadat Ismail Hmeidi Mohammed K. Ali Shatnawi ― Stock
Price Prediction Using K-Nearest Neighbor (kNN) Algorithm: Vol. 3 No. 3; March 2013.
[4] Murtaza Roondiwala Harshal Patel Shraddha Varma Predicting ― Stock Prices Using
LSTM: International Journal of Science and Research (IJSR) ISSN (Online): 2319-7064 Index
Copernicus Value (2015): 78.96 | Impact Factor (2015): 6.391.