0% found this document useful (0 votes)
162 views49 pages

Project Report

This document describes a project that uses machine learning techniques to predict stock prices. It was created by Mohd. Anas Vohra, Piyush Chowdhary, and Priyansh Saxena as their final year undergraduate project at JSS Academy of Technical Education, Noida, India. The project aims to use machine learning to predict stock prices with high accuracy while requiring minimal human intervention, as machine learning systems can learn directly from patterns in historical stock price data rather than requiring manually programmed rules. The document outlines the vision, mission, objectives, and outcomes of the Computer Science and Engineering department curriculum that the project fulfills.

Uploaded by

Mohd Vohra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
162 views49 pages

Project Report

This document describes a project that uses machine learning techniques to predict stock prices. It was created by Mohd. Anas Vohra, Piyush Chowdhary, and Priyansh Saxena as their final year undergraduate project at JSS Academy of Technical Education, Noida, India. The project aims to use machine learning to predict stock prices with high accuracy while requiring minimal human intervention, as machine learning systems can learn directly from patterns in historical stock price data rather than requiring manually programmed rules. The document outlines the vision, mission, objectives, and outcomes of the Computer Science and Engineering department curriculum that the project fulfills.

Uploaded by

Mohd Vohra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

STOCK PRICE PREDICTION USING MACHINE LEARNING

TECHNIQUES

by

MOHD. ANAS VOHRA 180911090

PIYUSH CHOUDHARY 1809110111

PRIYANSH SAXENA 1809110121

Department of Computer Science and Engineering

JSS ACADEMY OF TECHNICAL EDUCATION

SECTOR 62 , NOIDA

1
MAY, 2022

STOCK PRICE PREDICTION USING MACHINE


LEARNING TECHNIQUES

by

MOHD. ANAS VOHRA 180911090

PIYUSH CHOUDHARY 1809110111

PRIYANSH SAXENA 1809110121

Submitted to the Department of COMPUTER SCIENCE

in partial fulfillment of the requirements

for the degree of

Bachelor of Technology

in

COMPUTER SCIENCE

JSS ACADEMY OF TECHNICAL EDUCATION NOIDA

Dr. A.P.J Abdul Kalam Technical University, Uttar Pradesh, Lucknow.

MAY, 2022

2
VISION OF THE DEPARTMENT:

To spark the imagination of the Computer Science Engineers with values, skills and creativity
to solve the real world problems.

MISSION OF THE DEPARTMENT:

Mission 1: To inculcate creative thinking and problem solving skills through effective
teaching, learning and research.

Mission 2: To empower professionals with core competency in the field of Computer Science
and Engineering.

Mission 3: To foster independent and life-long learning with ethical and social
responsibilities.

PROGRAMME EDUCATIONAL OBJECTIVES:

PEO1: To empower students with effective computational and problem solving skills.

PEO2: To enable students with core skills for employment and entrepreneurship.

PEO3: To imbibe students with ethical values and leadership qualities.

PEO4: To foster students with research oriented ability which helps them in analyzing and
solving real life problems and motivate them for pursuing higher studies.

3
PROGRAMME OUTCOMES:
Engineering Graduates will be able to:
PO1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex
engineering problems.
PO2. Problem analysis: Identify, formulate, review research literature, and analyze
complex engineering problems reaching substantiated conclusions using first
principles of mathematics, natural sciences, and engineering sciences.
PO3. Design/development of solutions: Design solutions for complex engineering
problems and design system components or processes that meet the specified needs
with appropriate consideration for the public health and safety, and the cultural,
societal, and environmental considerations.
PO4. Conduct investigations of complex problems: Use research-based knowledge and
research methods including design of experiments, analysis and interpretation of data,
and synthesis of the information to provide valid conclusions.
PO5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modelling to complex
engineering activities with an understanding of the limitations.
PO6. The engineer and society: Apply reasoning informed by the contextual knowledge to
assess societal, health, safety, legal and cultural issues and the consequent
responsibilities relevant to the professional engineering practice.
PO7. Environment and sustainability: Understand the impact of the professional
engineering solutions in societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainable development.
PO8. Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.
PO9. Individual and team work: Function effectively as an individual, and as a member
or leader in diverse teams, and in multidisciplinary settings.
PO10. Communication: Communicate effectively on complex engineering activities with
the engineering community and with society at large, such as, being able to
comprehend and write effective reports and design documentation, make effective
presentations, and give and receive clear instructions.
PO11. Project management and finance: Demonstrate knowledge and understanding of
the engineering and management principles and apply these to one’s own work, as a
member and leader in a team, to manage projects and in multidisciplinary
environments.
PO12. Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological
change

PROGRAMME SPECIFIC OUTCOMES:

4
PSO1: An ability to apply foundation of Computer Science and Engineering, algorithmic
principles and theory in designing and modelling computation based systems.

PSO2: The ability to demonstrate software development skills.

COURSE OUTCOMES
C 410.1 Identify, formulate, design and analyse a research-based/web-based problem to
address societal and environmental issues.

C 410.2 Communicate effectively in verbal and written form.

C 410.3 Apply appropriate computing, engineering principle and management skills for
obtaining effective solution to the formulated problem within a stipulated time.

C 410.4 Work effectively as a part of team in multi-disciplinary areas.

C 410.5 Consolidate the final outcome in the form of a publication.

CO-PO-PSO MAPPING
COs PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2

C
3 3 3 3 2 3 3 3 3 3 2 3 3 3
410.1

C
2 2 2 2 2 2 2 2 2 3 2 3 2 3
410.2

C
3 3 3 3 3 3 2 3 3 3 3 3 3 3
410.3

C
3 3 3 3 2 3 2 3 3 3 3 3 3 3
410.4

C410.5 3 3 3 3 3 3 3 3 3 3 3 3 3 3

C410 2.80 2.80 2.80 2.80 2.40 2.80 2.40 2.80 2.80 3.00 2.60 3.00 2.80 3.00

5
DECLARATION

We hereby declare that this submission is our own work and that, to the best of our knowledge
and belief, it contains no material previously published or written by another person nor
material which to a substantial extent has been accepted for the award of any other degree or
diploma of the university or other institute of higher learning, except where due
acknowledgment has been made in the text.

Signature:

Name :

Roll No.:

Date :

Signature:

Name :

Roll No.:

Date :

Signature:

Name :

Roll No.:

Date :

6
CERTIFICATE
 

This is to certify that Project Report entitled “Stock Market Prediction Using Machine
Learning Techniques” which is submitted by Priyansh Saxena(1809110121), Piyush
Chowdhary (1809110111) and Mohd Anas Vohra(1809110090) in partial fulfillment of the
requirement for the award of degree B. Tech. in the Department of Computer Science and
Engineering of Dr. APJ Abdul Kalam Technical University, Uttar Pradesh, Lucknow is a
record of the candidate’s own work carried out by him/her under my/our supervision. The
matter embodied in this thesis is original and has not been submitted for the award of any
other degree.
 
 

Supervisor

Date

7
ACKNOWLEDGEMENT

It gives us a great sense of pleasure to present the report of the B. Tech Project undertaken during B.
Tech. Final Year. We owe special debt of gratitude to Professor Sur Singh Rawat, Department of
Computer Science & Engineering, JSS Academy of Technical Education, Noida for his constant
support and guidance throughout the course of our work. His sincerity, thoroughness and
perseverance have been a constant source of inspiration for us. It is only his cognizant efforts that our
endeavors have seen light of the day.

We also take the opportunity to acknowledge the contribution of Professor Kakoli Banerjee, Head,
Department of Computer Science & Engineering, JSS Academy of Technical Education, Noida for his
full support and assistance during the development of the project.

We also do not like to miss the opportunity to acknowledge the contribution of all faculty members of
the department for their kind assistance and cooperation during the development of our project. Last
but not the least, we acknowledge our friends for their contribution in the completion of the project.

Signature:

Name :

Roll No.:

Date :

Signature:

Name :

Roll No.:

Date :

Signature:

Name :

Roll No. :

8
ABSTRACT

Machine learning is a technique that enables computers to learn on their own by monitoring
real-world interactions and extrapolating from instances rather than requiring human
intervention. Rule-based programming is explicitly programmed. Many uncertainties and
connected economic and political issues affect stock markets on both sides of the Atlantic. on
a local and global scale Getting the finest results with the least amount of effort is the secret
to excellent stock market forecasting. data input It's a difficult work to identify the set of
significant criteria for creating correct predictions, which is why it's done on a regular basis.
Stock market analysis is crucial, and it cannot be stressed. The stock market's movements are
studied and predicted in greater depth. to obtain information that may assist investors in
deciding whether to buy or sell. We will utilize Python as our programming language for this,
as it supports a large number of ML-based libraries. Moving Average for technical analysis
and LSTM model will be used for predicting the trend.

keywords: Machine learning, stock price, stock market, moving average, long short term
memory.

9
TABLE OF CONTENTS Page

VISION i
MISSION i
PROGRAMME EDUCATIONAL OBJECTIVES i
PROGRAM OUTCOMES ii
PROGRAM SPECIFIC OUTCOMES iii
COURSE OUTCOMES iii

CO-PO-PSO MAPPING iii


DECLARATION ................................................................................................... iv
CERTIFICATE ..................................................................................................... v
ACKNOWLEDGEMENTS .................................................................................. vi
ABSTRACT ........................................................................................................... vii
LIST OF TABLES.................................................................................................. viii
LIST OF FIGURES................................................................................................ ix
LIST OF SYMBOLS .............................................................................................. x
LIST OF ABBREVIATIONS ................................................................................ xi

CHAPTER 1 6
1.1. INTRODUCTION.................................................................................... 6
1.2. PREVIOUS WORK................................................................................. 10
CHAPTER 2 ……………………………. .......................................................... 16
2.1. LITERATURE SURVEY......................................................................... 16
CHAPTER 3 …………………………….......................................................... 21
3.1. SYSTEM DESIGN.................................................................................. 21
CHAPTER 4 …………………..........................................................................
4.1. IMPLEMENTATION ..................... ................................................... 28
4.2 RESULT………………………………………………………………… 38
CHAPTER 5 (CONCLUSION)............................................................................... 39
5.1. PERFORMANCE EVALUATION………………………………………. 39
5.2. FUTURE DIRECTIONS……………………………………………….. 39
REFERENCE ………………………………………………………………………. 40

1
LIST OF FIGURES

Figure 1.1 Stock Prediction…………………………………………… 5

Figure 1.2 LSTM Architecture Flow Diagram……………………….. 11

Figure 3.1 System Architecture to build model………………………. 19

Figure 3.2 LSTM Working…………………………………………… 20

Figure 4.1 Import Libraries…………………………………………… 27

Figure 4.2 Loading the Training Set………………………………….. 28

Figure 4.3 Normalize the Dataset…………………………………….. 29

Figure 4.4 Creating Data Structures………………………………….. 29

Figure 4.5 Adding LSTM Layers…………………………………….. 30

Figure 4.6 100 and 200 Days Moving Average………………………. 31

Figure 4.7 Loading the Model………………………………………… 32

Figure 4.8 Dataset…………………………………………………….. 33

Figure 4.9 Graph with 100MA and 200MA………………………….. 34

Figure 4.10 Prediction vs Original Graph……………………………… 35

2
(Example)

LIST OF SYMBOLS

[x] Integer value of x.

≠ Not Equal

∈ Belongs to

€ Euro- A Currency

_ Optical distance

_o Optical thickness or optical half thickness

3
(Example)

LIST OF ABBREVIATIONS

AAM Active Appearance Model

ICA Independent Component Analysis

ISC Increment Sign Correlation

PCA Principal Component Analysis

ROC Receiver Operating Characteristics

LSTM Long-Short Term Memory


KNN K Nearest Neighbor
SVM Support Vector Machine

4
CHAPTER 1

INTRODUCTION

What is the Stock Market?

A stock market is a public market where you may purchase and sell shares in firms that are
publicly traded. The stocks, also known as equities, indicate the company's ownership. The
stock exchange acts as a middleman between buyers and sellers of stocks.

Fig. 1.1 Stock Pediction

Importance of Stock Market

Stock exchanges assist businesses in raising financing.


It contributes to personal wealth creation.
The stock market is used to gauge the state of the economy.
It is a popular way for people to invest in businesses with strong development potential.

5
Stock Price Prediction

Machine learning-based stock price prediction assists you in determining the future worth of
firm shares and other financial assets traded on an exchange. The whole point of stock price
forecasting is to make a lot of money. It's difficult to predict how the stock market will fare.
Physical and psychological elements, rational and irrational behaviour, and other factors all
play a role in the forecast. All of these elements combine to create a vibrant and turbulent
stock market. This makes it extremely difficult to accurately estimate stock values.

Predicting Stock Prices Using Machine Learning

The stock market is notorious for its volatility, dynamic, and nonlinear nature. Multiple
(macro and micro) aspects, such as politics, global economic conditions, unforeseen events, a
company's financial performance, and so on, make accurate stock price forecast extremely
difficult.
All of this, though, means that there is a lot of data to sort through. As a result, financial
analysts, researchers, and data scientists continue to experiment with analytics to detect stock
market trends. This gave rise to the concept of algorithmic trading, which involves the
execution of orders using automated, pre-programmed trading techniques.

Check the Trend in Stocks using Machine Learning

Fundamental vs. technical analysis in stock analysis


Fundamental and technical evaluations of stocks are on different extremes of the market
analysis spectrum.

6
Fundamental analysis:

Examines the inherent value of a company's stock, which includes but is not limited to
tangible assets, financial statements, managerial effectiveness, strategic objectives, and
customer habits; essentially all of a company's fundamentals.
The fundamental analysis, as a useful indication for long-term investment, uses both
historical and current data to measure revenues, assets, costs, liabilities, and so on.
In general, basic analysis results do not change in response to short-term news.

Technical analysis :

Analyzes measurable data from stock market activities, such as stock prices, historical
returns, and volume of historical trades; in other words, quantitative data that can be used to
find trading signals and capture stock market movement patterns.
Technical analysis, like fundamental analysis, focuses on past and current data, but it's
primarily utilised for short-term trading.
Technical analysis results are easily impacted by news due to their short-term nature.
We'll focus only on technical analysis for this exercise, using the Simple MA and Exponential
MA approaches to forecast stock values. In addition, we'll develop a predictive model using
LSTM (Long Short-Term Memory), a deep learning framework for time-series, and compare
its performance to our technical analysis.
Stock trading strategy is not covered in this article, as indicated in the disclaimer. I'll use
trading and investment words to help you understand the research better, but this isn't
financial advice. We'll use phrases like:
Tend Indicators: statistics that show stock price trends, medium-term movements: the 50-day
stock price movement trend.

7
1.1 Motivation

Mean reversion is a useful concept that indicates that the stock price is just temporary and
tends to return to its previous level. The average price over a period of time since the
introduction of information technology, stock markets have operated on a digital paradigm.
The core of this programme is Artificial Neural Networks, which serve as mathematical
function approximations. The feed forward network is a widely used ANN for this purpose.
The SVM (Support vector machine) Algorithm, as well as Random Forest, have been
implemented for stock prediction. The LSTM, a modified sort of recurrent neural network, is
also used. It remembers prior or previous data in order to make predictions. This project's
outcome contains a brief conclusion on how the algorithm performs in comparison to
real-world figures.
There are two types of Data we can use to train our model
1) Data from stock exchange
2) Social Network
We will train our model using data from stock exchange and find its probability.

1.1.3 Project Objective

The Autoregressive Integrated Moving Average (ARIMA) is a time series forecasting model
that can be used to predict stock market movements. While ARIMA thrives with linear and
stationary time series, it fails in the stock market with nonlinear and non-stationary data.
Combining ARIMA with SVM is one technique to solve this problem. The concept is that
forecasting has two parts: linear and nonlinear, with the linear part forecasted using ARIMA
8
and the nonlinear part predicted using SVM. Another method combines wavelet basis with
SVM, dissecting stock data using wavelet transformation and forecasting using SVM. The
Artificial Neural Network (ANN) was linked with ARIMA to anticipate the nonlinear portion
of the stock price data.
When wavelet transformation and artificial neural networks (ANN) were combined, it was
discovered that beneficial properties should be retrieved for ANN training. A Convolutional
Neural Network was used to forecast stock prices from the limit order book (CNN). The
number of orders and the price of 10 bid/ask orders were combined into a 2D array.

1.1.4 Scope of the Project

The investment industry has always been profitable. Investing money used to necessitate a
deep understanding of both domestic and international markets. People used to manually
research and analyse market trends. The manual analysis took a long time to complete.
However, as the reach of Machine Learning expands, we may witness a growing number of
mobile applications that give us with instant investing advice in a variety of areas. An
application called 'Upstox' can help you make smart stock market investments. It use
Machine Learning to forecast the market's future prospects.

1.2Previous Work

The discovery and application of multilayers in neural network research paved the way for a
new era in the 1960s. It was observed that a perceptron with two or more layers had much
greater processing power than a perceptron with just one layer. After the perceptron opened
the door to "layers" in networks, other types of neural networks emerged, and the variety of
neural networks continues to grow. Feedforward neural networks and backpropagation were
created as a result of the utilization of numerous layers.

9
Back-propagation, which was invented in the 1970s, allows a network to adapt to new
situations by adjusting its hidden layers of neurons/nodes. It covers "reverse error
propagation," in which a mistake is processed at the output and then propagated backward
through the network's layers for learning purposes. Deep neural networks are now being
trained using back propagation.
Hidden layers in an artificial neural network (ANN) allow it to respond to more sophisticated
tasks than perceptrons could. ANNs are a common technique for

artificial intelligence Input and output layers are utilised in neural networks, and a hidden
layer (or layers) is usually included to transform input into data that can be used by the output
layer. The hidden layers are ideal for detecting patterns that are too complicated for a human
programmer to notice, which means that a person would not be able to find the pattern and
then teach the device to recognise it.

Separate paths are taken by machine learning and artificial intelligence.


Artificial intelligence research in the late 1970s and early 1980s concentrated on logical,
knowledge-based approaches rather than algorithms. Furthermore, computer science and AI
researchers have abandoned neural network research. Artificial intelligence and machine
learning became divided as a result of this. Machine learning had previously been utilised as
an AI training programme.

The machine learning industry, which employed many researchers and technicians, was
separated into its own field and struggled for nearly a decade. The industry's objective has
switched from artificial intelligence training to real difficulties in service delivery. Its focus
switched away from AI-inspired ideas and toward probability theory and statistics
10
methodologies and tactics. The ML industry remained focused on neural networks at this
time, and then boomed in the 1990s.

1.2.1Proposed solution

Our proposed solution's high-level architecture can be divided into three sections. The first
step is feature selection, which ensures that the features chosen are very effective. Second, we
examine the data and reduce the number of dimensions. The last aspect of our work, which is
the most important contribution, is to create a target stock prediction model.

Fig.1.2 LSTM Architecture Flow Diagram

11
Different stock categories can be classified in a variety of ways. Long-term investments are
preferred by certain investors, whereas short-term investments are preferred by others. It is
typical to observe stock-related reports that show an average performance while the stock
price is rapidly increasing; this is one of the phenomena that indicates stock price prediction
has no fixed rules, necessitating the discovery of effective features prior to training a model
on data.

The focus of this study is on predicting short-term price trends. At the moment, we simply
have raw data with no labelling. The first step is to label the information. We determine the
price trend by comparing the current closing price to the closing price of n trading days ago,
where n is a number between 1 and 10 because our study is focused on the short term. If the
price trend is upward, we label it as 1; if it is downward, we record it as 0. To be more
specific, we anticipate the price trend of the nth day using indices from the indices of the nth
day.

According to earlier research, several researchers used procedures to filter high-quality stocks
using both financial domain knowledge and technical tools on stock data. We drew
inspiration from their work and applied their rules to our feature extension design.

However, we will examine the data first to assure the optimal performance of the prediction
model. There are a lot of features in the raw data; taking all of them into account will not only
raise the computing complexity, but it will also have negative consequences if we want to do
unsupervised learning in the future. To verify that all of the selected features are effective, we
use recursive feature elimination (RFE).

We discovered that most previous works in the technical domain analysed all stocks, whereas
researchers in the financial domain prefer to analyse a specific investment scenario. To bridge
the gap between the two domains, we decided to apply a feature extension based on the
financial domain findings before beginning the RFE procedure.

12
Because we want to represent the data as a time series, the more characteristics we have, the
more difficult the training procedure will be. As a result, we'll take advantage of
dimensionality reduction by starting our proposed solution architecture with randomised
PCA.

1.3 Organization of the Report

Chapter 2 contains a literature survey that provides a summary of individual paper.


Chapter 3 provides with the overview of system design along with its architecture
and algorithms used.
Chapter 4 presents Implementation and its results, tools and technology used to achieve this
and dataset detail.
Chapter 5 contains a conclusion about stock price prediction and future work about what you
are wanted to do in future.

13
CHAPTER 2

Literature Survey

Stock Price Forecasting Using Data From Yahoo Finance and Analysing Seasonal and
Nonseasonal Trend:
Publication Year: 2018
Author: Jai Jagwani, Hardik Sachdeva, Manav Gupta, Alka Singhal
Journal Name: 2018 IEEE
Summary:The major goal of the proposed work is to determine the link between multiple
existing time series algorithms, such as ARIMA and Holt Winter, and stock prices. For
investments, a good risk-free range of stock prices is evaluated, resulting in greater model
accuracy. To produce a variety of pricing for the consumer of stocks, a combination of two
different time series analysis models is used to produce distinct results for shares in the stock
market. The key advantage of these models is that they are not sophisticated in nature and
that they estimate values merely based on past stock prices for non-seasonal or seasonal
securities.

Stock Market Prediction Using Machine Learning:


Publication Year: 2018
Author: Ishita Parmar, Ridam Arora, Lokesh Chouhan, Navanshu Agarwal, Shikhin Gupta,
Sheirsh Saxena, Himanshu Dhiman
Journal Name: 2018 IEEE
Summary: The use of regression and LSTM-based machine learning to forecast stock prices
is investigated in this work. Open, close, low, high, and volume are all factors that are
monitored. Using machine learning techniques, this article attempted to predict the future
prices of a company's stocks with more accuracy and reliability. The LSTM algorithm
produced a positive result in terms of stock price prediction accuracy.

14
Multi-Category Events Driven Stock Price Trends Prediction:
Publication Year: 2018
Author: Youxun Lei, Kaiyue Zhou, Yuchen Liu
Journal Name: 2018 IEEE
Summary:Multi-category news events are used as features in this work to create a model for
stock price trend prediction. The multi-category events are based on a feature word dictionary
that has already been developed. We've also looked at the association between stock price
fluctuations and particular multi-category news using both neural networks and SVM models.
The predefined multi-category news events outperformed the baseline bag-of-words feature
in predicting stock price trend in the experiments. According to this study, short term
prediction is superior to long term prediction.

Share Price Prediction using Machine Learning Technique:


Publication Year: 2018
Author: Jeevan B, Naresh E, Vijaya kumar B P, Prashanth Kambli
Journal Name: 2018 IEEE
Summary:This study is mainly [5] focused on the approach of forecasting the stock value on
NSE data utilizing various criteria such as current market price, price-earning ratio, base
value, and other anonymous events using Long Short Term Memory (LSTM) and Recurrent
Neural Networks (RNN). An RNN graph is used to compare the genuine data and the
forecasted data to determine the model's efficiency. Machine learning to predict stock price as
seen in the model, which is able to predict the stock price extremely near to the actual price
by capturing comprehensive features and employing various methodologies.

15
Stock Market Prediction Using Machine Learning Techniques:
Publication Year: 2016
Author: Mehak Usmani, Syed Hasan Adil, Kamran Raza, Syed Saad Azhar Ali
Journal Name: 2016 IEEE
Summary: The main goal of this research is to use machine learning algorithms to [6]
anticipate the market performance of the Karachi Stock Exchange (KSE) on day close. The
predictions model takes a number of qualities as input and anticipates the market as Positive
or Negative. The model's features include oil prices, gold and silver prices, interest rates,
foreign exchange (FEX) rates, news, and social media feeds. The Single Layer Perceptron
(SLP), Multi-Layer Perceptron (MLP), Radial Basis Function (RBF), and Support Vector
Machine (SVM) machine learning techniques are contrasted. When compared to other
approaches, the MLP algorithm (multi-layer perceptron) performed the best.

Forecasting stock price in two ways based on LSTM neural network:


Publication Year: 2019
Author: Jingyi Du, Qingli Liu, Kang Chen, Jiacheng Wang
Journal Name: 2019 IEEE
Summary:To evaluate the model's forecast effect on stock time series, the LSTM neural
network is utilized to predict Apple stocks using single feature and multi-feature input
variables. The experimental findings demonstrate that the model is accurate and has a high
accuracy of 0.033 for the multivariate input. The projected squared absolute error for the
univariate feature input is 0.155, which is lower than the multi-feature variable input.

16
Share Price Trend Prediction Using CRNN with LSTM Structure:
Publication Year: 2018
Author: Shao-En Gao , Bo-Sheng Lin ,Chuin-Mu Wang
Journal Name: 2018 IEEE
Summary: The stock market drives the whole financial industry, and one of the most
interesting study topics is anticipating stock price volatility. The information from previous
stocks is used to predict future stock prices, and the deep learning method is used to
determine the approximate trend value of stock prices in this study. This paper not only saves
past stock data with a time scale, but also uses a built neural network to anticipate future
stock prices. This is because market trends are frequently linked to previous stock price
information.

Applying Long Short Term Memory Neural Networks for Predicting Stock Closing
Price:
Publication Year: 2017
Author: Tingwei Gao, Yueting Chai, Yi Liu
Journal Name: 2017 IEEE
Summary: The major goal of this work is to evaluate a strategy that combines RNNs with
useful input variables to provide an enhanced and successful way for forecasting the next-day
market. Long-short memory (LSTM) and stock basic trading data are used in the stock
prediction model. The case study is based on Standard & Poor's (S&P500) and NASDAQ.
Their forecasting approach for the next day outperforms the comparison models in terms of
predicting the stock closing price. This is the case study's most important finding. They use
five different models to demonstrate the system's utility: moving average (MA), exponential
moving average (EMA), support vector machine (SVM), and LSTM. The forecasting
objective is the next day's closing value.

17
Developing a Prediction Model for Stock Analysis:
Publication Year: 2017
Author: R. Yamini Nivetha, Dr. C. Dhaya
Journal Name: 2017 IEEE
Summary: The major goal of this research is to compare three algorithms: Multiple Linear
Regression (MLR), Support Vector Machine (SVM), and Artificial Neural Network (ANN).
Monthly and daily predictions will be used to predict the next day's market price. The stock
price is predicted using sentiment analysis and the best prediction system. The Multiple
Linear Regression algorithm, which assesses the correlation between volume and stock price,
is a less developed approach. The study's findings suggest that deep learning algorithms are
more advanced than MLR and SVM algorithms.

Stock Price Prediction Based on Information Entropy and Artificial Neural Network:
Publication Year: 2019
Author: Zang Yeze, Wang Yiying
Journal Name: 2019 IEEE
Summary:The stock market is one of the most significant parts of the financial system.
Money is directed by the related frim's investors to promote the activity and evolution.
Machine learning framework is built by combining information theory and Artificial Neural
Network (ANN). This method employs information entropy for non-linear causation and
stock relevance to facilitate ANN time series modelling. With the pricing of Amazon, Apple,
Google, and Facebook, the practicality of this machine learning architecture is evaluated.
This study outlines a time series analysis method based on information theory as well as
LSTM to model stock price movements.

Summary of Literature Survey:

I've looked at a few different ways to stock price prediction. Each method has its own set of
benefits and drawbacks. CNN and LSTM are the most popular algorithms for stock price
prediction, but they have certain drawbacks, such as requiring a large amount of training data,
having a high computing cost, being sluggish to train without GPU data, and relying on
previous information for prediction. To address these challenges, a hybrid strategy can be
adopted. While machine learning beats all classic prediction methods and may deliver very
accurate predictions using standard tools.

18
Chapter 3

System Design

Architecture is divided into two parts , first the LSTM model is trained using test data and saved for
further use then a python program will use this saved model to predict data for other stocks and show
this on a website.

3.1 System design for building the model

Fig.3.1 System architecture to build model

The typical LSTM unit consists of a cell, an info door,an entrance door and a door with a view. The
cell collects values over discretionary time intervals, and the three inputs manage the progress of
data into and out of the cell. The main advantage of the LSTM is its ability to learn
context-specific temporal dependence. Each LSTM unit collects information for either a long or short
period of time (hence the name) without explicitly using the activation function within the
recurrent components. A significant certainty to note is that any cell state is uniquely increased by
19
the output of the overlooked entryway, which changes somewhere in the range of 0 and 1. In other
words, the overhead door in the LSTM cell is responsible for both the loads and the capacity to
initiate the cell state. Subsequently, data from a past cell state can pass through a cell unaltered rather
than expanding or decreasing exponentially at each time-step or layer, and loads can meet their
ideal quality in a reasonable measure of time. This allows LSTM's to take care of the evaporating
slope issue – as the value put away in the memory cell is not iteratively adjusted, The inclination
does not disappear when prepared with back engendering, where markets such as NSE and BSE
are considered to be Indian trading entities for our analyzes.
3.2.1. Working of LSTM model

Fig 3.2 LSTM Working

Long Short Term Memory is a kind of recurrent neural network. In RNN output from the last
step is fed as input within the present step. It tackled the matter of long-term dependencies of
RNN within which the RNN will not predict the word hold on within the long term memory
however can offer additional accurate forecasts from the recent info. Because the gap length
will increases RNN does not offer an economical performance. LSTM will by default retain
the knowledge for a long period of time. It is used for processing, predicting and classifying
on the basis of time-series data.
Structure of LSTM:
● LSTM has a chain organization that contains four neural networks and different
memory blocks called cells.

20
● LSTM has a new structure called a memory cell. The memory cell makes the
decisions about what information to store, and when to allow reading, writing and
forgetting.
● A memory cell contains three main gates:
○ Input gate- a new value flows into the memory cell.
○ Forget gate- a value remains in the memory cell.
○ Output gate- value in the memory cell is used to compute the output
Applications of LSTM includes:
● Language Modelling
● Machine Translation
● Image Captioning
● Handwriting generation
● Question Answering Chatbot
3.2. System design for showing predictions for any stock on a web app
For displaying the predictions on the web, streamlit a python open source framework is used .
3.2.1. Streamlit
● What is Streamlit?
Streamlit is an open-source python framework for building web apps for Machine
Learning and Data Science. We can instantly develop web apps and deploy them
easily using Streamlit. Streamlit allows you to write an app the same way you write a
python code. Streamlit makes it seamless to work on the interactive loop of coding
and viewing results in the web app.
● Installing Streamlit
1. Make sure you have python installed in your system

2. Use the following command to install streamlit,

pip install streamlit

The flow of Streamlit while developing a web app


● Running a streamlit app
First, you create a python script with streamlit commands and execute the script using

the following command,

streamlit run <yourscript.py>

After running this a sample app will open in a new tab in your default browser.

21
● Development flow
If the source code of the streamlit’s python script changes the app shows whether to

rerun the application or not in the top-right corner. You can also select the ‘Always

rerun’ option to rerun always when the source script changes.

This makes our development flow much easier, every time you make some changes

it’ll reflect immediately in your web app. This loop between coding and viewing

results live makes you work seamlessly with streamlit.

● Data flow
Streamlit allows you to write an app the same way you write a python code. The

streamlit has a distinctive data flow, any time something changes in your code or

anything needs to be updated on the screen, streamlit reruns your python script

entirely from the top to the bottom. This happens when the user interacts with the

widgets like a select box or drop-down box or when the source code is changed.

If you have some costly operations while rerunning your web app, like loading data

from databases, you can use streamlit’s st.cache method to cache those datasets, so

that it loads faster.

● Displaying the data


Streamlit provides you with many methods to display various types of data like

arrays, tables, and data frames.

○ To write a string simply use, st.write(“Your string”)

○ To display a data frame use, st.dataframe method

● Widgets

There are several widgets available in streamlit, like st.selectbox, st.checkbox,

st.slider, and etc. Let us see an example for widget in streamlit.


22
import streamlit as st
value = st.slider('val') # this is a widget
st.write(value, 'squared is', value * value)

During the first run, the web app would output the string “0 squared is 0”, and then if

a user increases or decreases the widget, the code is rerun by the streamlit from top to

bottom and assigns the present state of the widget to the variable.

For example, if the user slides the slider to point 15, streamlit will rerun the code and

output the following string “15 squared is 225”.

● Layout
You can easily arrange your widgets or data seamlessly using the st.sidebar method.

This method helps you to align data in the left panel sidebar. All you have to do is

simply use st.sidebar.select box to display a select box in the left panel.

Let’s summarize the working of streamlit

● Streamlit runs the python script from top to bottom


● Each time the user interacts the script is a rerun from top to bottom
● Streamlit allows you to use caching for costly operations like loading large
datasets.
3.2.2. Load the Model

Keras is a simple and powerful Python library for deep learning and machine learning
algorithms.

A Keras model consists of multiple components:

● The architecture of the model, which specifies its layers and how they are connected
with each other. It also includes the type of model, e.g., sequential, etc.
● A set of weights values (the “state of the model”).
● An optimizer (defined by compiling the model).
● A set of losses and metrics.

Many deep learning models are complex and may take days to train and test the data.
Therefore, it is important to understand how to save and load data for later use.
23
In order to load the model, a user can use the load_model() function specified in the
keras.models library. The user will first have to import this function from the relevant library
in order to use it. The user will specify the name and location of the file with an .h5 extension.
Take a look at the syntax below:

from keras.models import load_model

model_new = load_model("myModel.h5")

24
CHAPTER 4

Implementation and Results

4.1. Software and Hardware Requirements

Hardware Requirements

● Intel Core i5 6th Generation processor or above as the central processing unit (CPU).
An AMD-compatible processor will also suffice.

● 8 GB of RAM is required, however 16 GB or more is preferred.

● NVIDIA GeForce GTX 960 or greater graphics processing unit Regardless, AMD
GPUs are unable to do deep learning. Visit https://developer.nvidia.com/cuda-gpus for
additional information about NVIDIA GPUs for deep learning.

● Ubuntu versus Microsoft Windows 10 as the operating system Before continuing, I


urge that you update Windows 10 to the most recent version.

Software Requirements

● TensorFlow
TensorFlow is the common moniker for Machine Learning in the Data Science sector.

TensorFlow is a machine learning software library that is free and open-source. It is


commonly used for a range of tasks, but it excels at deep neural network training and
inference.

25
● Google Cloud Platform:
For a comprehensive and unified experience, Google Cloud AI platform combines its
AI Platform, AutoML, and MLOps. Their technology adapts to the user's skill level,
providing both point-and-click data science and complex model optimization utilising
AutoML. For a simplified machine learning experience, they offer both code-based
and no-code solutions.

The Google Cloud AI Platform starts at $0.19 per hour and includes a $300 credit for
the first 90 days.

● Microsoft Azure:
Azure Machine Learning allows customers to create, train, and deploy machine
learning models fast and easily. QA managers will appreciate the ability to use
automated machine learning to find acceptable methods and hyperparameters more
rapidly. Many of its enhancing features, such as specific app services, event
processing, and automation for up to 500 minutes of job runtime, are available for free
indefinitely.

Azure Machine Learning costs $0.333 per hour and comes with a free 12-month trial
period and a $200 credit for the first 30 days.

● Python:
Python is a general-purpose, high-level, interpreted programming language. Its design
philosophy prioritizes code readability through extensive indentation.

Python is garbage-collected and dynamically typed. It works with a variety of


programming paradigms, including structured (especially procedural),
object-oriented, and functional programming. Because of its extensive standard
library, it is often referred to as a "batteries included" language.

Guido van Rossum started working on Python in the late 1980s as a replacement for
the ABC programming language, and Python 0.9.0 was launched in 1991. List
comprehensions, cycle-detecting garbage collection, reference counting, and Unicode
support were all included in Python 2.0, which was published in 2000. Python 3.0,
introduced in 2008, was a significant update that was not fully backwards compatible
with previous versions.
26
4.2. Assumptions and dependencies

1. KNN

The data is in feature space, which means that distance metrics like Manhattan,
Euclidean, and others can be used to quantify it.

Each training data point contains a set of vectors as well as a class label for each
vector.

In the event of a two-class classification, it was desired that 'K' be an odd integer.

2. Logistic Regression

It is assumed that the independent variables are minimally or completely

multicollinear.

To predict correctly, you normally need a big sample size.

It presupposes that the observations are unrelated to one another.

3. Linear Regression

A linear relationship should exist.

Multicollinearity should be absent or minimal.

Homoscedasticity: For any value of X, the residual variance should be the same.

4. Support Vector Machines

It assumes data is independent and identically distributed.

Works really well on high dimensional data.Memory efficient. Effective in


cases where the number of dimensions is greater than the number of samples.

27
4.2 Implementation Details:

4.2.1 Building the LSTM model

Fig 4.1 Import Libraries

4.2.2 Load the training set


There are five columns. The Open column tells the price at which a stock started
trading when the market opened on a particular day. The Close column refers to the
price of an individual stock when the stock exchange closed the market for the day.
The High column depicts the highest price at which a stock traded during a period.
The Low column tells the lowest price of the period. Volume is the total amount of
trading activity during a period of time. start and end date is set here and apple data is
being fetched from yahoo .

Fig 4.2 Loading the training set

28
4.2.3. Normalize the dataset
Normalization is changing the values of numeric columns in the dataset to a common scale,
which helps the performance of our model. To scale the training dataset we use Scikit-Learn’s
MinMaxScaler with numbers between zero and one.

Fig 4.3 Normalize the dataset

4.2.4. creating x_train and y_train data structures

Fig 4.4 Creating Data Structures

4.2.5 Building and saving the model by importing crucial libraries and adding
different layers to LSTM

Before we can develop the LSTM, we have to make a few imports from Keras: Sequential for
initializing the neural network, LSTM to add the LSTM layer, Dropout for preventing overfitting with
dropout layers, and Dense to add a densely connected neural network layer.

The LSTM layer is added with the following arguments: 50 units is the dimensionality of the output

space, return_sequences=True is necessary for stacking LSTM layers so the consequent LSTM layer

has a three-dimensional sequence input, and input_shape is the shape of the training dataset.

29
Specifying 0.2 in the Dropout layer means that 20% of the layers will be dropped. Following the

LSTM and Dropout layers, we add the Dense layer that specifies an output of one unit. To compile

our model we use the Adam optimizer and set the loss as the mean_squared_error. After that, we fit

the model to run for 100 epochs (the epochs are the number of times the learning algorithm will work

through the entire training set) with a batch size of 32.

Fig 4.5 Adding LSTM Layers

30
4.3 Setup for 100 days and 200 days Moving average.

100 days and 200 days moving average will be calculated by getting the mean of Closing
price on respective days.

Fig 4.6 100 and 200 days Moving Average

31
4.4 Loading the model and showing the prediction graph.

Fig 4.7 Loading the Model

Training the following model using the machine learning techniques produces the

model for prediction changing the dataset for different sales of stock prices.

Using the Api calls for different data sets for 100 days and 200 days.

32
Fig 4.8. Dataset

33
Fig 4.9 Graph with 100MA and 200MA

34
Results

Fig 4.10 Prediction vs Original Graph

The Following predicts the values of stock prices using different datasets available on the

data analysis websites like kaggle or google or the data sets of stocks available on google or

other websites. Usually the dataset is being disoriented into many blocks and then ruptured

into smaller fragments or usually called the base block or the test block. The model is

trained on that data set using different training techniques.The stock prices for next 100 and

35
200 days is being predicted using the LSTM and other machine learning tech

CHAPTER 5

Conclusion

5.1 Performance Evaluation


We will compare machine learning models such as the LSTM model, the CNN model, and
the hybrid approach of the LSTM model in this paper. To anticipate the stock's future value,
we usually train the model using data from NSE listed firms. This demonstrates that the
proposed method can distinguish between data interrelations. The results also show that the
hybrid method of the LSTM model is capable of detecting changes in trends. The Hybrid
technique of LSTM is known as the best model for the projected strategy. It makes
predictions based on the information available at the time.Even if the other two models are
successful Although LSTM is used in many other time-dependent data analyses, it does not
outperform the Hybrid LSTM architecture in this scenario. This is frequently due to the stock
market's rapid fluctuations. Stock market fluctuations do not necessarily follow a predictable
pattern or follow a continuous cycle. The existence of trends and the duration of their
existence will vary depending on the firms and sectors.

5.2 Future Directions


The understanding of these types of cycles and patterns can help investors make more money.
To improve the accuracy of forecasted stock prices, we will incorporate more stock market
data and compare more models in future work. In the future, the model can be taught with
more varied and detailed data to improve accuracy. Other algorithms can be used with the
presented to produce a new hybrid model. In future, Sentiment Analysis can be used to make
the prediction much more reliable. The feedback on a particular stock and other news related
to the stock can be trained based on positive and negative impact and will help to fetch much
more accuracy.

36
References
[1] “Stock price prediction using LSTM, RNN and CNN-sliding window model -IEEE

Conference Publication.” https://ieeexplore.ieee.org/document/8126078 (accessed Dec.

27, 2019).

[2] J. Jagwani, M. Gupta, H. Sachdeva, and A. Singhal, “Stock Price Forecasting Using

Data from Yahoo Finance and Analysing Seasonal and Nonseasonal Trend,” in 2018

Second International Conference on Intelligent Computing and Control Systems

(ICICCS),

Madurai, India, Jun. 2018, pp. 462–467, doi: 10.1109/ICCONS.2018.8663035.

[3] I. Parmar et al., “Stock Dec. 2018, pp. 574–576, doi: 10.1109/ICSCCC.2018.8703332.

[4] Y. Lei, K. Zhou, and Y. Liu, “Multi-Category Events Driven Stock Price Trends

Prediction,” in 2018 5th IEEE International Conference on Cloud Computing and

Intelligence Systems (CCIS), Nanjing, China, Nov. 2018, pp. 497–501, doi:

10.1109/CCIS.2018.8691392.

[5] B. Jeevan, E. Naresh, B. P. V. kumar, and P. Kambli, “Share Price Prediction using

Machine Learning Technique,” in 2018 3rd International Conference on Circuits,

Control, Communication and Computing (I4C), Bangalore, India, Oct. 2018, pp. 1–4, doi:

10.1109/CIMCA.2018.8739647.

[6] M. Usmani, S. H. Adil, K. Raza, and S. S. A. Ali, “S tock market prediction using machine

learning techniques,” in 2016 3rd International Conference on computer and Information

Sciences (ICCOINS), 2016, pp. 322–327.

[7] J. Du, Q. Liu, K. Chen, and J. Wang, “Forecasting stock prices in two ways based on

LSTM neural network,” in 2019 IEEE 3rd Information Technology, Networking,

Electronic and Automation Control Conference (ITNEC), Mar. 2019, pp. 1083–1086, doi:

10.1109/ITNEC.2019.8729026.

37
[8] S. E. Gao, B. S. Lin, and C.-M. Wang, “Share Price Trend Prediction Using CRNN with

LSTM Structure,” in 2018 International Symposium on Computer, Consumer and Control

(IS3C), Dec. 2018, pp. 10–13, doi: 10.1109/IS3C.2018.00012.

[9] T. Gao, Y. Chai, and Y. Liu, “Applying long short term momory neural networks for

predicting stock closing price,” in 2017 8th IEEE International Conference on Software

Engineering and Service Science (ICSESS), Beijing, China, Nov. 2017, pp. 575–578, doi:

10.1109/ICSESS.2017.8342981.

[10] R. Y. Nivetha and C. Dhaya, “Developing a Prediction Model for Stock AnalysisD,” in

2017 International Conference on Technical Advancements in Computers and

Communications (ICTACC), Melmaurvathur, India, Apr. 2017, pp. 1–3, doi:

10.1109/ICTACC.2017.11.

[11] Z. Yeze and W. Yiying, “Stock Price Prediction Based on Information Entropy and

Artificial Neural Network,” in 2019 5th International Conference on Information

Management (ICIM), Cambridge, United Kingdom, Mar. 2019, pp. 248–251, doi:

10.1109/INFOMAN.2019.8714662.

[12] Y. Kim, “Convolutional Neural Networks for Sentence Classification,” in Proceedings of

the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP),

Doha, Qatar, Oct. 2014, pp. 1746–1751, doi: 10.3115/v1/D14-1181.

[13]Reddy, V. Kranthi Sai. "Stock market prediction using machine learning." International

Research Journal of Engineering and Technology (IRJET) 5.10 (2018): 1033-1035.

[14]Strader, Troy J., et al. "Machine learning stock market prediction studies: Review and

research directions." Journal of International Technology and Information Management

28.4 (2020): 63-83.

[15]Mankar, Tejas, et al. "Stock market prediction based on social sentiments using machine

learning." 2018 International Conference on Smart City and Emerging Technology

38
(ICSCET). IEEE, 2018.

[16]Gurav, Uma, and Nandini Sidnal. "Predict Stock Market Behavior: Role of Machine

Learning Algorithms." Intelligent Computing and Information and Communication.

Springer, Singapore, 2018. 383-394.

[17]Mokhtari, Sohrab, Kang K. Yen, and Jin Liu. "Effectiveness of artificial intelligence in

stock market prediction based on machine learning." arXiv preprint arXiv:2107.01031

(2021).

[18]Henrique, Bruno Miranda, Vinicius Amorim Sobreiro, and Herbert Kimura. "Literature

review: Machine learning techniques applied to financial market prediction." Expert

Systems with Applications 124 (2019): 226-251.

[19] Chiong, Raymond, et al. "A sentiment analysis-based machine learning approach for

financial market prediction via news disclosures." Proceedings of the Genetic and

Evolutionary Computation Conference Companion. 2018.

[20] Moghar, Adil, and Mhamed Hamiche. "Stock market prediction using LSTM recurrent

neural network." Procedia Computer Science 170 (2020): 1168-1173.

[21]Vachhani, Hrishikesh, et al. "Machine learning based stock market analysis: A short

survey." International Conference on Innovative Data Communication Technologies and

Application. Springer, Cham, 2019

[22]Lee, Tae Kyun, et al. "Global stock market investment strategies based on financial

network indicators using machine learning techniques." Expert Systems with Applications

117 (2019): 228-242.

[23]Zhong, Xiao, and David Enke. "Predicting the daily return direction of the stock market

using hybrid machine learning algorithms." Financial Innovation 5.1 (2019): 1-20.

[24]Nabipour, Mojtaba, et al. "Deep learning for stock market prediction." Entropy 22.8

(2020): 840.

39
[25]Hiransha, M., et al. "NSE stock market prediction using deep-learning models." Procedia

computer science 132 (2018): 1351-1362.

[26]Parray, Irfan Ramzan, et al. "Time series data analysis of stock price movement using

machine learning techniques." Soft Computing 24.21 (2020): 16509-16517.

[27]Sakhare, Nitin Nandkumar, and S. Sagar Imambi. "Performance analysis of regression

based machine learning techniques for prediction of stock market movement." Int. J.

Recent Technol. Eng 7.6S4 (2019): 206-213.

[28]Naik, Nagaraj, and Biju R. Mohan. "Stock price movements classification using machine

and deep learning techniques-the case study of indian stock market." International

Conference on Engineering Applications of Neural Networks. Springer, Cham, 2019

40

You might also like