Project Report Group-2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

Stock Price Prediction Using Time Series Analysis

B.Tech Project Report


Submitted to the Faculty of Engineering and Technology of

MGM University Chhtrapati Sambhajinagar 431003

In partial fulfillment of the requirement for the award of the degree in


Bachelor of Technology

Electronics and Telecommunications Engineering

by

Prathmesh Rajesh Kulkarni (202001104010)


Chanchal Vinod Rathod (202101104701)
Ameya Dinesh Deshpande (202001104016)

Under the Guidance of


Dr.Vandana B.Malode

Department of Electronics & Telecommunications Engineering


JAWAHARLAL NEHRU ENGINEERING COLLEGE
MGM UNIVERSITY CHHATRAPATI SAMBHAJINAGAR (M.S.),
INDIA.
OCTOBER 2023

i
MGM University
JAWAHARLAL NEHRU ENGINEERING COLLEGE
N-6, CIDCO, CHHTRAPATI SAMBHAJINAGAR (M.S.),
INDIA.

CERTIFICATE

This is to certify that the Project report entitled “Stock Price Prediction Using Time
Series Analysis” has been submitted by Mr. Prathmesh Rajesh Kulkarni, Mr. Ameya
Deshpande, Ms. Chanchal Vinod Rathod with PRN No. 202001104010, 202001104016,
202101104701 in partial fulfillment for the award of the degree of Bachelor of Technology in
Electronic and Telecommunications Engineering from Jawaharlal Nehru Engineering
College, MGM University, Chhtrapati Sambhajinagar.
The matter embodied in this project report is a record of his/her own independent work
carried out by him/her under my supervision and guidance. The matter embodied in this report
has not been submitted to any other University or Institute for the award of any degree or
diploma.

Guide H.O. D Dean (Engg. and Tech.)


Dr. Vandana B. Malode Dr S.N. Pawar Dr. H.H. Shinde
Asso. Professor Professor & Head JNEC, MGMU
ETC Dept ETC Dept

ii
PROJECT APPROVAL CERTIFICATE

Practical oral examination for the project is conducted on __________________ and the work

is approved for the award of Bachelor of Technology in Electronics and Telecommunication

Engineering.

________________ ________________
EXTERNAL INTERNAL

iii
UNDERTAKING

I certify that
a. The work contained in the project report is original and has been done by myself under
the supervision of my guide.

b. The work has not been submitted to any other Institute for any degree or diploma.

c. Whenever I have used materials (data, theoretical analysis, and text) from other sources, I
have given due credit to them by citing them in the text of the project report and giving their
details in the references.

Date:

Place:

Name of student: Chanchal Vinod Rathod Sign:


PRN No: 202101104701

Name of student: Prathmesh Rajesh Kulkarni Sign:


PRN No. 202001104010

Name of student: Ameya Dinesh Deshpande Sign:


PRN No. 202001104016

iv
ACKNOWLEDGEMENTS

We would like to express our sincere gratitude to Dr. Vandana B. Malode at Jawaharlal Nehru
Engineering College, for their invaluable guidance and support throughout this project. Their
insights and expertise have been instrumental in shaping the direction of this work.

We would also like to thank Dr. S.N. Pawar, H.O.D Electronics and Telecommunication
Department, for providing us with the necessary resources and materials to carry out this project.
Their generosity has been crucial in enabling us to conduct our research.

Furthermore, we would like to extend our appreciation to Dr. H.S. Shinde, Principal at Jawaharlal
Nehru Engineering College, for their assistance in proof reading and editing this report. Their keen
eye for detail and constructive feedback has been immensely helpful in improving the quality of this
work.

Lastly, we would like to thank our family and friends for their unwavering support and encouragement
throughout this project. Their love and motivation have been a constant source of inspiration for us.

v
ABSTRACT

Stock price data have the characteristics of time series. At the same time, based on machine learning
long short-term memory (LSTM) which has the advantages of analyzing relationships among time
series data through its memory function, we propose a forecasting method of stock price based on
LSTM. Moreover, the forecasting results of these models are analyzed and compared.
In terms of historical data, choosing a feature, closing price and adopting LSTM model to predict
the stock price with the extracted feature data. According tothe experimental results, the LSTM can
provide a reliable stock price forecasting with the highest prediction accuracy. This forecasting
method not only provides a new research idea for stock price forecasting but also provides practical
experience for scholars to study financial time series data.

Keywords – Machine Learning, LSTM, Forecasting

vi
LIST OF ABBRIVATIONS

ARIMA Autoregressive Integrated Moving Average


BSE Bombay Stock Exchange
RNN Recurrent Neural Networks
GARCH Generalized Auto Regressive Conditional
Heteroskedasticity
GUI Graphical User Interface.
GPU Graphics Processing Unit
LSTM Long Short-Term Memory
ML Machine Learning
NSE National Stock Exchange
OS Operating system
SVM Support Vector Machine

vii
LIST OF TABLES

Table no. Title Page no


2.1 Literature survey 8
3.1 Objectives 10
3.2 Pair – wise comparison chart 12
4.1 Dataset Details 16
5.1 Model evaluation (TATA MOTORS) 31
5.2 Future predictions 31

viii
LIST OF FIGURES

Figure no Title Page no


2.1 Valueinvesting 9
2.2 Koyfin 9
3.1 Objective tree 11
3.2 Function tree 13
3.3 Conceptual Model design 14
3.4 Glass box 15
4.1 Python 16
4.2 LSTM 18
4.3 Jupyter Notebook 20
5.1 Stock Dataset Information 21
5.2 Read Dataset 21
5.3 Missing Values 22
5.4 Graph of Close Price history 22
5.5 Data Scaling 23
5.6 Train test Split 23
5.7 LSTM Summary 23
5.8 training process 24
5.9 Real Stock Fluctuation of TATA MOTORS 25
5.10 Predicted graph of TATA MOTORS 25
5.11 Real Stock Fluctuation of HINDUSTAN UNILEVER 26
5.12 Predicted graph of HINDUSTAN UNILEVER 26
5.13 Real Stock Fluctuation of ASIAN PAINTS 27
5.14 Predicted graph of ASIAN PAINTS 27
5.15 Real Stock Fluctuation of INFOSYS 28
5.16 Predicted graph of INFOSYS 28
5.17 Real Stock Fluctuation of ASHOK LEYLAND 29
5.18 Predicted graph of ASHOK LEYLAND 29
5.19 Real Stock Fluctuation of UJJIVAN FINANCIAL 30
SERVICES
5.20 Predicted graph of UJJIVAN FINANCIAL SERVICES 30

ix
CONTENT

Page no
Chapter 1 Introduction 1
1.1 Stock Price Prediction 2
1.1.1 Time series analysis 2
1.1.2 Fundamental analysis 3
1.1.3 Technical analysis 4
1.2 Why time series analysis 4

Chapter 2 Literature survey 5


2.1 Literature survey 5
2.2 Existing solution 9

Chapter 3 Model requirement and design constraint 10


3.1 Design Objective 10
3.2 Constraint 13
3.3 Functions 13
3.4 Model Design 14

Chapter 4 Dataset and implementation 16


4.1 Dataset Detail 16
4.2 Tool & Technologies 16
4.2.1 Python 16
4.2.2 Numpy 17
4.2.3 Sk Learn 17
4.2.3.1 LSTM 18
4.2.4 Tensorflow 19
4.2.5 Keras 19
4.2.6 Pandas 19
4.2.7 Jupyter Notebook 20

x
Chapter 5 Results and Discussion 21

Chapter 6 Conclusion and Future scope 30

Reference and links 31

xi
Chapter 1

INTRODUCTION

Stock price prediction is a process of forecasting future stock prices based on 1] historical data, 2]
market trends and other factors that influence stock prices. Time series analysis is one of the most
popular methods used in stock price prediction.

Time series analysis involves analyzing and modeling time series data which is a sequence of
observations recorded at regular intervals over time. Stock prices are an example of time series data
because they are recorded over time and can be influenced by various factors such as 1] market trends
2] company news and economic indicators.

In stock price prediction using time series analysis, the past data is analyzed to identify patterns and
trends which are then used to forecast future stock prices. Some of the commonly used time series
analysis techniques for stock price prediction include 1] moving averages 2] Autoregressive
Integrated Moving Average (ARIMA) models and exponential smoothing.

In addition to time series analysis techniques other factors such as market trends and economic
indicators can also be incorporated into the stock price prediction models to improve their accuracy.
Machine learning algorithms such as Long Short-Term Memory and Support Vector Machines
(SVM) can also be used to analyze and predict stock prices.

Overall, stock price prediction using time series analysis is a complex and dynamic process that
requires a combination of 1] statistical analysis 2] domain knowledge and market insights. While it
is not possible to predict stock prices with complete accuracy, time series analysis can provide
valuable insights and help investors make informed decisions.

1
1.1 Stock price prediction

Due to the high profit of the stock market, it is one of the most popular investments. People
investigated for methods and tools that would increase their gains while minimizing the risk, as
the level of trading and investing grew. Two stock exchanges namely- the NSE and the BSE which
are the most of the trading in Indian Stock Market takes place. Sensex and Nifty are the two
prominent Indian Market Indexes. Since the prices in the stock market are dynamic, the stock
market prediction is complicated. From gradually the very past years some forecasting models are
developed for this kind of purpose and they had been applied to money market prediction.
Generally, this classification is done by:

1. Time series analysis


2. Fundamental analysis
3. Technical analysis

1.1.1 Time Series Analysis

The definition of forecasting can be like this the valuation of some upcoming result or results by
analyzing the past data. It extents different areas like industry and business, economics and
finance, environmental science. Forecasting problems can be classified as follows:

•Long term forecasting (estimation beyond 2 years)

•Medium-term forecasting (estimation for 1 to 2 years)

•Short term forecasting (estimation for weeks or months, days, minutes, few seconds)

The analysis of time consists of several forecasting problems. The designation of a time series is
a linear classification of observations for a selected variable. The variable of the stock price in our
case. Which can weather multivariate or univariate? Only particular stock is included in the
univariate data while more than one company for various instances of time is added in
multivariate. For investigating trends, patterns and cycle or periods the analysis of time series
advantages in the present data. In spending money wisely an early data of the bullish or bearish
in the case of the stock market. Also, for categorizing the best-performing companies the analysis
of patterns plays its role for a specific period. This makes forecasting as well as time series analysis
an important research area.

2
1.1.2 Fundamental analysis

Fundamental Analysts are concerned with the business that reasons the stock itself. They assess a
company's historical performance as well as the reliability of its accounts. Different performance
shares are created that aid the fundamental forecaster with calculating the validity of a stock, such
as the P/E ratio. Warren Buffett is probably the foremost renowned of all Fundamental Analysts.
What fundamental analysis within the stock market is making an attempt to reach, is organizing
the true value of a stock, that then will be matched with the worth it is being listed on stock markets
and so finding out whether or not the stock on the market is undervalued or not. Find out the
correct value will be completed by numerous strategies with primarily a similar principle. The
principle is that an organization is price all of its future profits. Those future profits have to be
discounted to their current value. This principle goes on the theory that a business is all about
profits and nothing else. Differing to technical analysis, the fundamental analysis is assumed as
further as a long approach. Fundamental analysis is created on conviction that hominoid society
desires capital to make progress and if the company works well, then it should be rewarded with
an additional capital and outcome in a surge in stock price. Fundamental analysis is usually used
by the fund managers as it is the maximum sensible, objective and prepared from openly existing
data like financial statement analysis. One more meaning of fundamental analysis is on the far
side bottom-up business analysis, it discusses the top-down analysis since initial analyzing the
world economy, followed by country analysis and also sector analysis, and last the company
analysis.

1.1.3 Technical Analysis

Chartists or the technical analysts are not involved with any other of the fundamentals of the
company. The long run price of a stock based generally exclusively on the trends of the past value
(a form of time series analysis) that is set by them. The head and shoulders or cup and saucer are
various numerous patterns that are employed. Also, the techniques, patterns are used just like the
oscillators, exponential moving average (EMA), support and momentum and volume indicators.
Candlestick patterns, believed to have been initial developed by Japanese rice merchants, are
nowadays widely used by technical analysts. For the short-term approaches, the technical analysis
is used compare to long-run ones. So, in commodities and forex markets it is more predominant
wherever traders target short-term price movements. There are basic rules are used in this analysis,
first all significant about a company is already priced into the stock, another being that the value

3
changes in trends and finally that history (of prices) tends to repeat itself that is especially due to
the market science.

1.2 Why Time series analysis?

Time series analysis is commonly used in stock price prediction because stock prices are time-
dependent and exhibit patterns and trends over time. By analyzing historical data, time series
analysis can identify these patterns and trends, which can be used to forecast future prices Stock
prices are influenced by a variety of factors, such as market trends, company news, and economic
indicators. These factors can change rapidly, and the relationship between them and stock prices
can be complex and dynamic. Time series analysis can capture these relationships and provide
insights into how they affect stock prices over time. Time series analysis can also help identify
important features of stock prices, such as seasonality, trends, and volatility. Seasonality refers to
periodic fluctuations in stock prices that occur at the same time each year, such as a stock price
increasing during the holiday season. Trends refer to the overall direction of stock prices over
time, such as a long-term upward trend or downward trend. Volatility refers to the degree of
variation in stock prices over time, such as how much the price fluctuates from day to day by
incorporating these features into predictive models, time series analysis can improve the accuracy
of stock price predictions. For example, an ARIMA model can be used to model the seasonality
and trends in stock prices, while a GARCH model can be used to model the volatility of stock
prices.

Overall, time series analysis is a powerful tool for predicting stock prices because it can capture
the complex and dynamic relationships between stock prices and various factors that influence
them.

4
Chapter 2

LITERATURE SURVEY

2.1 Literature Survey

By reviewed various approaches for Stock price prediction. All approaches have their own
advantages and disadvantages. LSTM is a most popular algorithm to prediction the stock price
but there are some challenges in this method like use to need a lot of training data, High
computational cost, without GPU data quite slow to train, depend on any previous information for
prediction. This approach can be used to overcome these issues. While machine learning is able
to provide highly accurate prediction result using standards tool and also outperforms all standard
prediction methods.

Stock Price Forecasting Using Data from Yahoo Finance and Analyzing Seasonal and
Nonseasonal Trend:

Publication Year: 2018

Author: Jai Jagwani, Hardik Sachdeva, Manav Gupta, Alka Singhal Journal Name: 2018
IEEE

Summary: To identify the relationship between different existing time series algorithms namely
ARIMA and Holt Winter and the stock prices is the main objective of the proposed work, for the
investments a good risk-free range of stock prices are analyzed and therefore better accuracy of
the model can be seen. To find distinguished results for shares in the stock market, the combination
of two different time series analysis models is opted by producing a range of prices to the
consumer of the stocks. Not complex in nature and estimation of values which are purely based
on the past stock prices for non-seasonal or seasonal is the main advantage of these models. In
this experiment, some limitations are, the work that never takes into consideration and other
circumstances like news about any new market strategy or media release relevant to any company
which may get affected by the prices of stocks.

5
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: In this paper studies, the use of Regression and LSTM based Machine learning to
forecast stock prices. Factors measured are open, close, low, high and volume. This paper was an
attempt to determine the future prices of the stocks of a company with improved accuracy and
reliability using machine learning techniques. LSTM algorithm resulted in a positive outcome
with more accuracy in predicting stock prices.

Multi-Category Events Driven Stock Price Trends Prediction

Publication Year: 2018

Author: Youxun Lei, Kaiyue Zhou, Yuchen Liu Journal

Name: 2018 IEEE

Summary: In this paper, multi-category news events are used as features to develop stock price
trend prediction, model. The multi-category events are based on already defined feature word
dictionary. And we have employed both neural networks and SVM models to analyses the
relationship between stock price movements and specific multi-category news. Experimental
results showed that the predefined multi-category news events are more improved than the
baseline bag-of-words feature to predict stock price trend. As compared to long term prediction,
short term prediction is better based on this study.

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

6
Summary: This paper is mostly based on the approach of predicting the share price using Long
Short-Term Memory (LSTM) and Recurrent Neural Networks (RNN) to forecast the stock value
on NSE data using various factors such as current market price, price-earnings ratio, base value
and other anonymous events. The efficiency of the model is analyzed by comparing the true data
and the predicted data using an RNN graph. Machine learning to predict stock price as see the
model is able to predict the stock price very close to the actual price where this model captures
the detailed feature and uses different strategies to make a prediction. The model train for all the
NSE data from the internet and recognize the input and group them and provide input according
to the user configuration this RNN based architecture proved very efficient in forecasting the stock
price by changing the configuration accordingly which also use backpropagation mechanism
while gathering and grouping data to avoid mixing of data

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 prominent aim of this study is to forecast the market performance of the Karachi
Stock Exchange (KSE) on day closing using machine learning algorithms. A variety of attributes
as an input and forecasts market as Positive & Negative is predicted by using the predictions
model. The features employed in the model are contains Oil rates, Gold & Silver rates, Interest
rate, Foreign Exchange (FEX) rate, NEWS and social media feed. The machine learning
algorithms including Single Layer Perceptron (SLP), Multi-Layer Perceptron (MLP), Radial Basis
Function (RBF) and Support Vector Machine (SVM) are compared. The algorithm MLP that is
multi-layer perceptron performed best as compared to different methods. The foremost helpful
feature in predicting the market was the oil rate attribute. The end results of this research confirm
that machine learning techniques have the ability to predict the stock market performance. The
Multi-Layer Perceptron algorithm of machine learning predicted 70% correct market
performance.

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

Author: Jingyi Du, Qingli Liu, Kang Chen, Jiacheng Wang Journal

7
Name: 2019 IEEE

Summary: The LSTM neural network is used to predict Apple stocks by consuming single feature
input variables and multi-feature input variables to verify the forecast effect of the model on stock
time series. The experimental results show that the model has a high accuracy of 0.033 for the
multivariate input and is accurate, that is in line with the actual demand. For the univariate feature
input, the predicted squared absolute error is 0.155, which is inferior to the multi-feature variable
input.

Overall, these studies demonstrate the effectiveness of time series analysis techniques in
predicting stock prices, and highlight the importance of selecting the appropriate model based on
the characteristics of the data being analyzed.

Table 2.1 Literature Survey

Above table gives an idea about literature survey. We can compare different existing model and study
them.

8
2.2 Existing solutions

1. Valueinvesting.io: -
• Regional plan- INR 1,238.1066/month
• Global plan- INR 3,550.7806/month

Fig 2.1 Value investing

2. Koyfin:-
• Basic- USD 15/month
• Plus- USD 35/month
• Pro- USD 70/month

Fig 2.2 Koyfin

9
Chapter 3
MODEL REQUIREMENT AND DESIGN CONSTRAINT

3.1 Design Objective


The objective of a project focused on stock price prediction using Machine Learning (ML) can vary
depending on the specific goals and scope of the project. Here are some common objectives for such a
project. Predict the future price of a particular stock or a basket of stocks. This is often the primary
goal of stock price prediction projects, and it can be useful for traders, investors, and financial
institutions. Assess and quantify the risk associated with a particular investment or portfolio. ML
models can help in understanding how volatile a stock or portfolio might be, which is crucial for risk
management strategies. Develop and optimize trading strategies based on ML predictions. This
involves creating algorithms that make buy/sell decisions based on price forecasts, historical data, and
market indicators. Recognize recurring patterns in historical stock price data, which can be used to
make informed trading decisions. Incorporate sentiment analysis of news articles, social media, and
other sources to gauge market sentiment and its impact on stock prices. Determine whether the project
aims to predict exact stock prices (regression) or binary outcomes such as whether the price will go up
or down (classification). Incorporate sentiment analysis of news articles, social media, and other
sources to gauge market sentiment and its impact on stock prices. Continuously assess the performance
of ML models and refine them to improve prediction accuracy and reliability.

Table no 3.1 Objectives of project


Sr no Objectives

1 Predict the future price of a particular stock or a basket of stocks.

2 Assess and quantify the risk associated with a particular investment or portfolio.

3 Develop and optimize trading strategies based on ML model predictions.

4 Recognize recurring patterns in historical stock price data

5 Evaluate the historical performance of trading strategies based on past predictions to


assess their profitability.

6 Identify unusual or unexpected patterns in stock price movements.

10
Fig 3.1 Objective tree

11
A pairwise comparison chart, also known as a decision matrix, is a tool used to compare and
evaluate multiple options or criteria. It consists of a table with rows and columns representing
the options or criteria being evaluated.

Table no 3.2 (Pairwise Comparison Chart) PCC

Objectives Price Risk Model Portfolio Anomaly Score


Forecasting Management Evaluation Management Detection
and
Improvement
Price **** 1 1 1 1 4
Forecasting

Risk 0 **** 1 1 1 3
Management

Model 0 0 **** 1 0 1
Evaluation
and
Improvement

Portfolio 1 0 0 **** 1 2
Management

Anomaly 0 0 1 0 **** 1
Detection

Problem statement:
Create a machine learning-based stock price prediction system leveraging the power of LSTM (Long
Short-Term Memory). LSTM networks are known for their ability to capture sequential dependencies
in time-series data, making them well-suited for modeling and predicting stock prices. The primary
objective of this project is to design, train, and evaluate an LSTM-based model that can provide accurate
and timely predictions of stock prices for a selected set of stocks or financial instruments.

12
3.2 Constraint:
1. Data Availability: The availability and quality of historical stock price data are crucial for training
and evaluating machine learning models. Ensure access to a reliable source of historical stock
price data, such as APIs or databases, and consider constraints related to data latency and
accuracy.
2. Model Complexity: Depending on the computational resources and infrastructure available, you
may need to consider the complexity of your machine learning model. Complex models like deep
neural networks may require powerful GPUs or TPUs, which can be a constraint in terms of cost
and availability.
3. Time Constraints: The time required for model training and prediction can be a constraint,
especially if you need real-time or near-real-time stock price predictions. Ensure that your model
can meet the desired prediction frequency while considering computational limitations.
4. Ethical and Regulatory Constraints: Stock price prediction can have significant financial
implications, and there may be ethical and regulatory constraints related to the use of machine
learning for trading or investment purposes. Ensure compliance with relevant laws and
regulations.
5. Interpretability: Complex machine learning models, such as deep neural networks, can be
challenging to interpret. If interpretability is a constraint, consider using simpler models or
techniques like linear regression or decision trees.

Fig 3.2 function tree


3.3 Functions:
Input:
1. Collect historical stock price data, including features such as open, high, low, and volume.
2. Preprocess the data by handling missing values, outliers, and converting timestamps to usable
formats.

13
Processing:
1. Choose an appropriate machine learning algorithm or model for stock price prediction. Common
choices include linear regression, decision trees, random forests, support vector machines, and
neural networks.
2. Split the data into training and testing sets.
3. Evaluate the model's performance using appropriate metrics (e.g., Mean Absolute Error, Root
Mean Squared Error, accuracy, or F1-score for classification tasks).
Output:
1. Use the trained model to make stock price predictions for a given time horizon (e.g., daily,
weekly, or monthly).
2. Monitor and update the model regularly with new data to improve prediction accuracy.

3.4 Model Design


The design requirements for a stock price prediction using LSTM include data collection, pre-
processing, feature selection, train-test split, model selection, and deployment. Historical
stock price data needs to be collected from various sources. Pre-processing involves cleaning
the data, removing any missing values, and normalizing the data to a common scale. Feature
Selection involves extracting relevant features from the data. Train Test Split involves
dividing the dataset into two subsets: a training set and a testing set. Model selection is the
process of choosing the best machine learning model for a specific problem. After training
and evaluation, models can be deployed into a production system using various technologies.

Fig 3.3 Conceptual Model design

14
Fig 3.4 Glass box
Glass box refers to models or systems that prioritize interpretability and transparency, making it easier
for humans to understand how decisions or predictions are made.

15
Chapter 4

Dataset and Implementation

4.1 Dataset Detail

The dataset consists of the stock historical data from the National stock exchange (NSE) and captures
the daily information of each stock from the National Stock Exchange. It collects different sectors
of stock data, including Building Materials sector, automobile manufacturing company, IT sector,
integrated steel manufacturers and it including the opening price, the highest price, the lowest price,
the closing price, the adjusted closing price and the volume of stock

Table 4.1 Dataset Details

Stock name Sector


Asian Paints Building Materials
Tata Motors Automobile manufacturing
Infosys IT
Hindustan Unilever Food Consuming

4.2 Tool & Technologies

4.2.1 Python:

Fig 4.1

The language of select for this project was Python. This was a straightforward call for many
reasons.
1. Python as a language has a vast community behind it. Any problems which may be

16
faced is simply resolved with visit to Stack Overflow. Python is the foremost standard
language on the positioning that makes it is very straight answer to any question.
2. Python is an abundance of powerful tools ready for scientific computing Packages.
The packages like NumPy, Pandas and SciPy area unit freely available and well
documented. These Packages will intensely scale back, and variation the code necessary
to
write a given program. This makes repetition fast.
3. Python is a language as forgiving and permits for the program that appear as if pseudo
code. This can be helpful once pseudo code give in tutorial papers should be required and
verified. Using python this step is sometimes fairly trivial.
However, Python is not without its errors. The python is dynamically written language and
packages are area unit infamous for Duck writing. This may be frustrating once a package
technique returns one thing that, for instance, looks like an array instead of being an actual array.
Plus, the standard Python documentation did not clearly state the return type of a method, this
can’t lead without a lot of trials and error testing otherwise happen in a powerfully written
language. This is a problem that produces learning to use a replacement Python package or library
more difficult than it otherwise may be

4.2.2 Numpy
Numpy is python package which provide scientific and higher-level mathematical abstractions
wrapped in python. It is the core library for scientific computing, that contains a provide tools for
integrating C, strong n-dimensional array object, C++ etc. It is also useful in random number
capability, linear algebra etc.
Numpy’s array type augments the Python language with an efficient data structure used for
numerical work, e.g., manipulating matrices. Numpy additionally provides basic numerical
routines, like tools for locating Eigenvectors

4.2.3 Scikit Learn


Scikit-learn could be a free machine learning library for Python. It features numerous
classification, clustering and regression algorithms like random forests, k-neighbours, support
vector machine, and it furthermore supports Python scientific and numerical libraries like SciPy
and NumPy.
In Python Scikit-learn is specifically written, with the core algorithms written in Cython to get
the performance. Support vector machines are enforced by a Cython wrapper around LIBSVM

17
.i.e., linear support vector machines and logistic regression by a similar wrapper around
LIBLINEAR

4.2.3.1 LSTM model:

Fig 7.2 LSTM model

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 increase 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.
➢ 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.

18
• Forget gate- a value remains in the memory cell.
• Output gate- value in the memory cell is used to compute the output

4.2.4 Tensorflow
In the TensorFlow has an open-source software library for numerical computation using data flow
graphs. Inside the graph nodes represent mathematical formulae, the edges of graph represent the
multidimensional knowledge arrays (tensors) communicated between them. The versatile
architecture permits to deploy the computation to at least one or many GPUs or CPUs in a
desktop, mobile device, servers with a single API. TensorFlow was firstly developing by
engineers and researchers acting on the Google Brain Team at intervals Google's Machine
Intelligence analysis organization for the needs of conducting deep neural networks research and
machine learning, but the system is generally enough to be appropriate in a wide range of alternate
domains as well.
Google Brain's second-generation system is TensorFlow. Whereas the reference implementation
runs on single devices, TensorFlow can run on multiple GPUs and CPUs. TensorFlow is offered
on Windows, macOS, 64-bit Linux and mobile computing platforms together with iOS and
Android

4.2.5 Keras
Keras is a high-level neural networks API, it is written in Python and also capable of running on
top of the Theano, CNTK, or. TensorFlow. It was developed with attention on enabling quick
experimentation. having the ability to travel from plan to result with the smallest amount doable
delay is key to doing great research. Keras permits for straight forward and quick prototyping
(through user-friendliness, modularity, and extensibility). Supports each recurrent networks and
convolutional networks, also as combinations of the 2. Runs seamlessly on GPU and CPU. The
library contains numerous implementations of generally used neural network building blocks like
optimizers, activation functions, layers, objectives and a number of tools to create operating with
text and image data easier. The code is hosted on GitHub, and community support forums embody
the GitHub issues page, a Gitter channel and a Slack channel.

4.2.6. Pandas
Pandas is a widely used Python library for data manipulation and analysis in the field of machine
learning (ML) and data science. It provides data structures and functions that make it easy to work

19
with structured data, such as CSV files, Excel spreadsheets, SQL databases, and more. In the
context of machine learning, Pandas is often used for data preprocessing and exploration, which
are crucial steps in the ML pipeline.

4.2.7 Jupyter Notebook

Fig 7.3 Jupyter Notebook

The Jupyter Notebook is an open-source web application that enables to making and sharing
documents that contain visualizations, narrative text, live code and equations. Uses include: data,
data visualization, data transformation, statistical modelling, machine learning, numerical
simulation, data cleaning and much more

20
Chapter 5

Results and Discussion

Step 1: Dataset Analysis

Fig 5.1 Stock Dataset Information


Firstly, Performed Data analysis for stock price of companies. Fig. represent the date, open, close,
high, low, adjusted close and volume of stocks details.

Step 2: Read Dataset

Fig 5.2 Read Dataset

After performing data analysis, I have read the dataset. It shows the dataset information table
starting from the tail. There are 1256 data are available in each companies’ dataset.

21
Step 3: Checking for missing value

Fig 5.3 Missing Values


Checking the missing values in the dataset, it may affect the learning of model and gives error.
As we can see, there are 0 missing values present in the data.

Step 4: Graph of Close Price history

Fig 5.4: Graph of Close Price history


The above graph is of INFOSYS well known IT company showing closing values from 2019 to
2023 having dates(years) on x-axis and corresponding value on y-axis

Step 5: Preprocessing

x - numbers from Min(x) to Max(x)


Formula of scaling Min(x) - Initial value of dataset
(Normalization): Max(x) - Final value of dataset

22
Fig 5.5 Data Scaling

Min-Max scaling scales the data to a specific range, typically between 0 and 1. It is
achieved by transforming each feature using the following formula:

Step 6: Train test Split

Fig 5.6 Train test Split


After performing preprocessing, I have divided the dataset into training and testing set. 90% of
the data is used for the training while the remaining 10% of the data is used for testing.

Step 7: Model fitting of Long Short Term Memory architecture

Fig 5.7: LSTM Summary

23
Step 8: Apply Training

Fig 5.8 training process


To apply training, from the samples of Training data, 1130 samples are used for training and 126
samples are used for validation. Data is processed in a batch size of 32 and epoch is 10 for the
entire training dataset with decreasing loss in each iteration.

24
Step 9: Predicted Graph
TATA MOTORS

Fig 5.9 Real Stock Fluctuation of TATA MOTORS


Above graph is real time fluctuation of TATA MOTORS from Feb 2023 to Aug 2023 having date
(month) on x-axis and corresponding price on y-axis. The above graph is in range from 410 rs to
614 rs.

Fig 5.10 Predicted graph of TATA MOTORS


Above graph is predictions of TATA MOTORS from Feb 2023 to Aug 2023 having date (month)
on x-axis and corresponding price on y-axis. The above graph is in range from 445 rs to 614 rs.

25
HINDUSTAN UNILIVER

Fig 5.11 Real Stock Fluctuation HINDUSTAN UNILEVER


Above graph is real time fluctuation of TATA MOTORS from Feb 2023 to Aug 2023 having
date(month) on x-axis and corresponding price on y-axis. The above graph is in range from
2605 rs to 2546 rs.

Fig 5.12 Predicted graph of HINDUSTAN UNILEVER


Above graph is predictions of HINDUSTAN UNILEVER from Feb 2023 to Aug 2023 having
date (month) on x-axis and corresponding price on y-axis. The above graph is in range from
2645 rs to 2546 rs.

26
ASIAN PAINTS

Fig 5.13 Real Stock Fluctuation of ASIAN PAINTS


Above graph is real time fluctuation of ASIAN PAINT from Feb 2023 to Aug 2023 having
date(month) on x-axis and corresponding price on y-axis. The above graph is in range from
2780 rs to 3337 rs.

Fig 5.14 Predicted graph of ASIAN PAINT


Above graph is predictions of ASIAN PAINT from Feb 2023 to Aug 2023 having date
(month) on x-axis and corresponding price on y-axis. The above graph is in range from 2645
rs to 2546 rs.

27
INFOSYS

Fig 5.15 Real Stock Fluctuation of INFOSYS


Above graph is real time fluctuation of INFOSYS from Feb 2023 to Aug 2023 having
date(month) on x-axis and corresponding price on y-axis. The above graph is in range
from 1605 rs to 1378 rs.

Fig 5.16 Predicted graph of INFOSYS


Above graph is predictions of INFOSYS from Feb 2023 to Aug 2023 having date (month)
on x-axis and corresponding price on y-axis. The above graph is in range from 1605 rs to
1378 rs.

28
ASHOK LEYLAND

Fig 5.17 Real Stock Fluctuation of ASHOK LEYLAND (MID CAP)


Above graph is real time fluctuation of Ashok Leyland from May 2023 to Oct 2023 having
date(month) on x-axis and corresponding price on y-axis. The above graph is in range
from 138 rs to 175 rs.

Fig 5.18 Predictions of ASHOK LEYLAND


Above graph is real time fluctuation of Ashok Leyland from May 2023 to Oct 2023 having
date(month) on x-axis and corresponding price on y-axis. The above graph is in range
from 138 rs to 175 rs.

29
UJJIVAN FINANCIAL SERVICES

Fig 5.19 Actual graph of UJJIVAN FINANCIAL SERVICES (SMALL CAP)


Above graph is real time fluctuation of Ujjivan Financial Services from May 2023 to Oct
2023 having date(month) on x-axis and corresponding price on y-axis. The above graph is
in range from 270 rs to 545 rs.

Fig 5.20 Predictions of UJJIVAN FINANCIAL SERVICES


Above graph is real time fluctuation of Ujjivan Financial Services from May 2023 to Oct
2023 having date(month) on x-axis and corresponding price on y-axis. The above graph is
in range from 265 rs to 546 rs.

30
Step 10: Model evaluation

Table 5.1 Model evaluation (TATA MOTORS)

Further evaluation of model taking data set of TATA MOTORS and feature as closing value.
Above table shows Actual and Predicted value on the end of each month from Feb 2023 to July
2023.

Step 11: Future predictions

Table 5.2 Future predictions

Above table shows comparison between actual value and predicted value which is predicted
for 07/08/2023 (Monday) on 05/07/2023(Friday).

31
Chapter 6
CONCLUSION AND FUTURE SCOPE
In report we used LSTM model to train and predict future stock values. The model has tendency to
train itself using data of NSE listed companies. We observed that LSTM-based models demonstrated
strong predictive capabilities for the given task. The model's ability to capture temporal dependencies
and handle long sequences made it well-suited for time series forecasting. The performance of LSTM
models was highly sensitive to hyperparameter settings, thus careful tuning was essential to achieve
optimal results. LSTM models excel in capturing complex patterns, they often lack interpretability.
Post hoc analysis and visualization techniques were employed to better understand the model's
predictions and internal representations. In future work, we will add more stock market data and
compare more model to improve accuracy of predicted stock price.

Future scope
1. Real-time Prediction: Real-time prediction of stock prices is a significant challenge. Advancements
in high-frequency trading, faster data processing, and more efficient algorithms will enable traders
and investors to make quicker decisions based on up-to-the-minute data.
2. Quantitative Trading Strategies: Quantitative trading strategies that use machine learning models
are likely to become more sophisticated. These strategies involve the automation of trading decisions
based on data analysis, and they can benefit from improved prediction models.

32
Reference
1) 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.
2) 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.
3) F. A. Gers, D. Eck, and J. Schmidhuber, “Applying LSTM to Time Series Predictable through Time-Window
Approaches,” in Artificial Neural Networks — ICANN 2001, Berlin, Heidelberg, 2001, pp. 669–676, doi:
10.1007/3-540-44668-0_93.
4) “Python Numpy Tutorial | Learn Numpy Arrays With Examples,” Edureka, Jul. 14, 2017.
https://www.edureka.co/blog/python-numpy-tutorial/ (accessed Apr. 21, 2020).
5) “Scikit-learn Tutorial: Machine Learning in Python – Dataquest.” https://www.dataquest.io/blog/sci-kit-
learn-tutorial/ (accessed Apr. 21, 2020).
6) “Project Jupyter.” https://www.jupyter.org (accessed Apr. 19, 2020).

Links:
1) https://www.geeksforgeeks.org/machine-learning/

2) https://chat.openai.com/c/98a1b6f3-822f-4851-9468-257f0730edbe

3) https://www.geeksforgeeks.org/understanding-of-lstm-networks/

4) https://www.w3schools.com/ai/ai_neural_networks.asp

33

You might also like