0% found this document useful (0 votes)
2K views21 pages

Machine Learning Using Python Project Report: Stock Price Prediction Using ML

This document discusses using machine learning for stock price prediction. It proposes using machine learning architectures like LSTM, CNN, and a hybrid approach of LSTM and CNN to predict stock prices of companies listed on the National Stock Exchange of India. The performance of these models will be assessed using the root mean square error over a long-term period with a sliding window approach. The goal is to improve the quality of stock price predictions compared to traditional methods like time series analysis, fundamental analysis, and technical analysis.
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)
2K views21 pages

Machine Learning Using Python Project Report: Stock Price Prediction Using ML

This document discusses using machine learning for stock price prediction. It proposes using machine learning architectures like LSTM, CNN, and a hybrid approach of LSTM and CNN to predict stock prices of companies listed on the National Stock Exchange of India. The performance of these models will be assessed using the root mean square error over a long-term period with a sliding window approach. The goal is to improve the quality of stock price predictions compared to traditional methods like time series analysis, fundamental analysis, and technical analysis.
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

MACHINE LEARNING USING PYTHON

PROJECT REPORT

ON

STOCK PRICE PREDICTION USING ML


Submitted to Centurion University of Technology& Management

in partial fulfilment of the requirement for award of the degree of

B. TECH
in
COMPUTER SCIENCE & ENGINEERING
Submitted By

Shivam Kumar Singh(210101120085)

Under the Guidance of


Ms. Aryalopa Malla

DEPT. OF COMPUTER SCIENCE & ENGINEERING

SCHOOL OF ENGINEERING &TECHNOLOGY,


CUTM, Paralakhemundi-761200

1
CERTIFICATE

This is to be certified that the minor project entitled


“MACHINE LEARNING USING PYTHON” has been
submitted for the Bachelor of Technology in Computer
Science Engineering of School of Engineering &
Technology, CUTM, PARALAKHEMUNDI during the
academic year 2022-2023 is a persuasive piece of project
work carried out by), SHIVAM KUMAR
SINGH(210101120085), towards the partial fulfilment for
award of the degree ([Link].) under the guidance of “Ms.
ARYALOPA MALA” and no part there of has been
submitted by them for any degree to the best of my
knowledge.

Signature of Project Guide

Name of the student Name of the Guide


Shivam Kumar Singh Ms. Aryalopa Mala

2
ACKNOWLEDGEMENT

I Would like to acknowledge all those without whom this project


would not have been successful. Firstly, I would wish to thank our
Computer Science teacher Ms. Aryalopa mala who guided me
throughout the project and gave his immense support. He made us
understand how to successfully complete. This project and without
him, the project would not have been complete. This project has
been a source to learn and bring our theoretical knowledge to the
real-life world. So, I would really acknowledge his help and
guidance for this project. I would also like to thank my parents who
have always been there whenever needed. Once again, thanks to
everyone for making this project successful.

Submitted by:
Shivam Kumar Singh (210101120085)

3
TABLE OF CONTENT

S no. Topic Range of the Page Num


1. ABSTRACT 5
2. INTRODUCTION 6-9
3. Existing work and proposed work 10-15

4. CODE 16-18
5. OUTPUT 19-20
6. Conclusion and Future work.… 21

4
ABSTARCT
Researchers have been studying different methods to effectively predict the
stock market price. Useful prediction systems allow traders to get better insights
about data such as: future trends. Also, investors have a major benefit since the
analysis give future conditions of the market. One such method is to use
machine learning algorithms for forecasting. This project’s objective is to
improve the quality of output of stock market predicted by using stock value. A
number of researchers have come up with various ways to solve this problem,
mainly there are traditional methods so far, such as artificial neural network is a
way to get hidden patterns and classify the data which is used in predicting stock
market. This project proposes a different method for prognosting stock market
prices. It does not fit the data to a specific model; rather we are identifying the
latent dynamics existing in the data using machine learning architectures. In this
work we use Machine learning architectures Long Short-Term Memory (LSTM),
Convolutional Neural Network (CNN) and Hybrid approach of LSTM + CNN for
the price forecasting of NSE listed companies and differentiating their
performance. On a long term basis, sling window approach has been applied and
the performance was assessed by using root mean square error.

5
Introduction
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 National Stock Exchange (NSE) and the Bombay
Stock Exchange (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

Time Series Analysis


The definition of forecasting can be like this the valuation of some upcoming
result or results by analysing 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)

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

The analysis [1] of time consist 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.

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 has 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

7
progress and if the company works well, than 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 analysing the world economy,
followed by country analysis and also sector analysis, and last the company level
analysis.

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 changes in trends and finally that history (of prices)
tends to repeat itself that is especially due to the market science.

1.2 Applications
 Business

 Companies

8
 Insurance company

 Government Agency

 This application is helpful for stock investors, sellers, buyers, brokers.

1.3 Objectives
A stock market prediction is described as an action of attempting to classify
the future value of the company stock or other financial investment traded on
the stock exchange. The forthcoming price of a stock of the successful
estimation is called the Yield significant profit. This helps you to invest wisely
for making good profits.

1.4 Motivation
The future price of a stock is the main motivation behind the stock price
prediction. In various cases like business and industry, environmental science,
finance and economics motivation can be useful. The future value of the
company’s stock can be determining.

1.5 Organization of Report


Chapter 2 contains a literature survey that provides a summary of individual
paper. Chapter 3 provides an overview of existing work for stock price
prediction that has been done using LSTM, CNN and Hybrid Approach of
LSTM+CNN. 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.

9
[Link] WORK AND PROPOSED WORK

3.1 Overview of Existing Work


Stock Price Prediction by Machine Learning present to estimate the stock
future value and machine learning technique like LSTM for existing work.
This machine-learning algorithm is to perform the best predicting result of the
stock future price. LSTM is capable to catching the modifications in the
behaviour of the stock price for the indicated period in this proposed system.
Propose [3] a machine learning-based normalization for stock price prediction.
The dataset utilized for analysis was selected from Yahoo Finance. It consists
of approximately 9 lakh records of the required Stock price and other relevant
data. The data reflected the stock price at some time intervals for every day of
the year. It contains various data like date, symbol, open price, close price,
low price, high price and volume. Here, the data for only one company was
considered. All the data was available in a file of CSV format which was first
read and transformed into a data frame using the Pandas library in Python. The
normalization of the data was performed through the sklearn library in Python
and the data were divided into training and testing sets. The experiment set
was kept as 20% of the available dataset. This paper focuses on two
architecture Regression-based Model and LSTM. The Regression-based
Model is employed for predicting unbroken values through some given
autonomous values Regression uses a given linear function for predicting
continuous values of the most important amongst them and made the
predictions using these. LSTM architecture is able to identify the changes in
trends which show evident from the result. LSTM is identified as the best
model for the proposed methodology.

10
[Link] Work:-

The system presented here composes of five modules:-

1. Input as Dataset

2. Pre processing

3. Data splitting

4. Build & Model train Lstm, CNN and Hybrid approach of LSTM+CNN

5. Output as Predicted Result

Attribute such as: price of open, high, low, close, adjusted close price taken
from huge dataset are fed as input to the models for training to pre-processthe
data techniques like normalization & one hot encoding in applied on dataset.

11
After this data is divided in two sets namely training & testing which are ratio
of 80:20 respectively. Then, this set are used to train a model using 3 different
approaches: LSTM, CNN and Hybrid approach of LSTM+CNNS. Finally, all
these modules are evaluated using Root mean square error.

Working of 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 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.

12
 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.2. Working of CNN model

13
 Layer of CNN model:
o Convolution
o MAX Pooling
o Dropout
o Flatten
o Dense
o Activation
 Convolution: In the Convolution extract the featured from the input
image. It given the output in matrix form.
 MAX Pooling: In the MAX polling it takes the largest element from a
rectified feature map.
 Dropout: Dropout is randomly selected neurons are ignored during
training.
 Flatten: Flatten feed output into a fully connected layer. It gives data in
list form.
 Dense: A Linear operation in which every input is connected to every
output by weight. It followed by a nonlinear activation function.
 Activation: It used sigmoid function and predict the probability 0 and
Applications of CNN includes:
 Decoding Facial Recognition
 Analyzing Documents

3.2.3. Hybrid Approach of LSTM + CNN


In the hybrid approach, the Convolutional Neural Networks (CNNs) offer
benefits in choosing sensible options and Long Short-Term Memory (LSTM)
networks have proven sensible skills to find out to learn sequential data. Each
approaches are reported to produce improved result. CNNs to possess to
convolute filters over every input layer so as to get the simple options and CNNs

14
have shown enhancements in computer vision, natural language processing and
different tasks [14]. CNN may be a powerful tool to pick out features in order to
improve the prediction accuracy [15]. The capabilities of LSTMs in learning data
series by considering the previous outputs [16]

The multiple convolutional filters slide over the matrix to produce a new feature
map and also the filters have numerous completely different sizes to generate
different features. The Maxpooling layer is to calculate the most value as a
corresponding feature to a particular filter. The output vectors of the Max-pooling
layer become inputs to the LSTM networks to measure the long-run dependencies
of feature sequences. One in all the benefits of the LSTMs is that the ability to
capture the sequential data by considering the previous data. This layer takes the
output vectors from the dropout layer as inputs. This layer include a set number
of units or cells and also the input of every cell is that the output from the dropout
layer. The final output of this layer has the same number of units within the
network the outputs from LSTMs are merged and combined in one matrix then
passed to a fully connected layer. The array is converted into a single output in
the range between 0 and 1 using the fully connected layer, in order to be finally
classified using sigmoid function.

15
CODE

16
17
18
OUTPUT

19
20
Conclusion and Future Work
In report, we will compare a machine learning models like LSTM model, the
CNN model and also the hybrid approach of LSTM + CNN model. We have a
tendency to train the model using the data of NSE listed companies to predict the
stock future value. This is shows the proposed method is capable to distinctive
around interrelation with the data. Also, it is evident from the results that, Hybrid
approach of LSTM+CNN model is capable to identify the changes in trends. For
the projected method the Hybrid approach of LSTM+CNN is known as the best
model. It uses the information given at a specific instant for prediction. Even if
the other two models LSTM and CNN are utilized in a lot of other time-dependent
data analysis, it is not outperforming over the Hybrid approach of LSTM+CNN
architecture in this case. This is often because of quick changes occur in stock
market. The changes in the stock market is not always be in a regular pattern or
not always follow the continuous cycle. Based on the companies and sectors, the
existence of the trends and the period of their existence will differ. The analysis
of this type of cycles and trends can offer a more profit to the investors. In future
work, we add more stock market data and compare more model to improve
accuracy of predicted stock price. In the future, for better accuracy model can be
trained with more varied and detailed data. Also, other algorithms along with
proposed can be used to create a new hybrid model.

21

You might also like