Sem Proj-III Stock
Sem Proj-III Stock
Submitted By
Gaurav Kishor Badgujar
Guided by
Miss. Kirtee Agrawal
Submitted to
Mahatma Gandhi Shikshan Mandalache
Dadasaheb Dr. Suresh G. Patil College,
Chopda.425107
Affiliated to
1|Page
Stock Market Price Prediction
Prediction
CERTIFICATE
This is to certify that Gaurav Kishor Badgujar
Date:
Place: Chopda
2|Page
Stock Market Price Prediction
Prediction
DECLARATION
I am Gaurav Kishor Badgujar the student of Masters of
Date: -
Place: -
Gaurav Kishor Badgujar
3|Page
Stock Market Price Prediction
Prediction
ACKNOWLEDGEMENT
I take this opportunity to express a great pleasure in
submitting this report on Stock Market Price Prediction” for
Masters of Computer Science.
In completion of this project work Report, we are grateful to
Head of Department Asst. Prof. Mrs. Arati B. Patil for she’s
timely kind cooperation and providing required facilities.
I am thankful to our guide Miss. Kirtee Agrawal for their
valuable guidance, kind of suggestion, constant encouragement
and excellent co-operation and valuable helps.
I also like to pay humble gratitude to our parents for providing
moral support for completion of this project Report on.
4|Page
Stock Market Price Prediction
Prediction
TABLE OF
CONTENTS
Certificates 02
Declaration 03
Acknowledgement 04
Abstraction 06
Introduction 08
4 Methodology 20
5|Page
Stock Market Price Prediction
Prediction
Abstract
6|Page
Stock Market Price Prediction
Prediction
challenges involved in forecasting stock prices, a field of immense relevance for
investors, financial analysts, and researchers. Accurate predictions can help
mitigate risks, enhance portfolio performance, and guide investment decisions.
Traditional prediction models relied heavily on technical analysis, fundamental
analysis, and market sentiment, which often required extensive manual
evaluation. However, the advent of advanced technologies like machine
learning (ML), deep learning (DL), and natural language processing (NLP) has
revolutionized predictive capabilities by offering automated, data-driven, and
scalable solutions.
Machine learning algorithms such as regression models, decision trees, and
support vector machines (SVM) analyze historical data and discern patterns to
project future stock movements. Meanwhile, deep learning approaches,
including recurrent neural networks (RNN) and long short-term memory
networks (LSTM), excel in handling sequential data and predicting time series
trends. Sentiment analysis, leveraging NLP, gauges public opinion and news
sentiment, which are key drivers of market behavior. These innovations are
often combined to enhance prediction accuracy, such as integrating technical
indicators with social media sentiment analysis.
Despite technological advancements, stock price prediction remains complex
due to market volatility, macroeconomic factors, geopolitical events, and the
presence of random noise in the data. Furthermore, biases in data, overfitting in
models, and computational challenges pose significant obstacles. Addressing
these limitations requires robust preprocessing techniques, real-time data
integration, and the development of interpretable models. Ethical
considerations, including data privacy and the impact of algorithmic trading on
market stability, are also critical.
7|Page
Stock Market Price Prediction
Prediction
Chapter 1
Introduction
Introduction
The stock market is one of the most complex systems globally, with prices
constantly fluctuating due to a wide array of factors, including economic news,
corporate earnings reports, geopolitical events, and investor sentiment. Investors
and financial institutions have long sought ways to predict future stock prices in
order to maximize returns and minimize risks. However, stock price prediction
remains a difficult challenge due to the inherent volatility, noise, and
unpredictability of financial markets.
Traditionally, stock market price prediction has relied on fundamental analysis,
which involves analyzing financial statements, earnings reports, and
macroeconomic data, as well as technical analysis, which focuses on historical
price movements and trading volumes. However, these methods often struggle
to predict price movements accurately, especially in the short term. As a result,
there has been growing interest in applying machine learning techniques to
predict stock prices and market trends.
Machine learning (ML) offers a promising approach to stock market prediction
by leveraging historical data and complex patterns that are difficult for
traditional models to capture. ML algorithms can identify correlations and
trends in large datasets, making them more adept at predicting future price
movements than human-driven models. By training models on historical stock
data, including daily opening and closing prices, trading volumes, and technical
indicators such as moving averages, Relative Strength Index (RSI), and
Bollinger Bands, machine learning algorithms can uncover hidden patterns and
relationships in the data.
Furthermore, recent advances in deep learning and neural networks have shown
promise in improving prediction accuracy by mimicking human decision-
8|Page
Stock Market Price Prediction
Prediction
making processes and learning from large, high-dimensional datasets. These
methods can capture intricate nonlinear relationships and make predictions
based on past price movements, news sentiment, and even social media trends.
The aim of this project is to explore the potential of machine learning
techniques to predict stock market prices. By employing various ML models
such as linear regression, decision trees, support vector machines (SVM),
random forests, and deep learning approaches, this project seeks to develop a
robust system that can forecast stock prices and help investors make informed
decisions. The project also aims to evaluate the predictive performance of
different models using several accuracy metrics and analyze the effectiveness of
technical indicators and other features in improving prediction results.
In addition to stock price prediction, this project investigates the challenges and
limitations of machine learning in financial markets, including overfitting,
model interpretability, and the impact of external factors such as news events
and market sentiment. Ultimately, the goal is to determine the feasibility of
using machine learning as a tool for making more informed and reliable
predictions in the unpredictable and volatile environment of the stock market.
while absolute accuracy in stock price prediction may remain elusive, ongoing
innovations in AI and data analytics are significantly enhancing the ability to
forecast trends and guide strategic decision-making. This field continues to
evolve, underscoring the interplay between financial expertise and
computational intelligence. Future research should focus on hybrid models that
integrate multiple data sources, explainable AI to interpret predictions, and
adaptive algorithms to handle dynamic market conditions. This synergy of
technology and finance holds great promise for transforming stock market
analysis into a more precise and informed science.
9|Page
Stock Market Price Prediction
Prediction
1.1 Problem statement
he stock market is a highly dynamic environment characterized by complex
interactions between various factors, such as economic conditions, company
performance, investor behavior, and external events. Predicting stock prices
accurately remains one of the most challenging tasks in finance due to the
inherent uncertainty and volatility present in the market. Despite the availability
of vast amounts of historical data, current methods still struggle to provide
reliable and consistent predictions over both short and long-term horizons.
Traditional stock market prediction methods, such as technical analysis and
fundamental analysis, rely on expert knowledge and heuristic rules to forecast
price movements. However, these approaches are limited by their inability to
adapt to new patterns and often fail to capture complex, nonlinear relationships
within the data. Additionally, the reliance on human intuition can introduce
biases and errors in predictions.
In recent years, machine learning (ML) techniques have gained significant
attention for their potential to address these limitations. Machine learning
algorithms can automatically learn patterns from historical data and provide
predictions based on empirical evidence, rather than relying on predefined rules.
However, the application of machine learning to stock market prediction faces
several key challenges:
1. High Volatility and Noise: Stock prices are subject to unpredictable
fluctuations, often driven by factors outside of historical trends. This
noise can make it difficult for machine learning models to identify clear
patterns and relationships, leading to inaccurate predictions.
2. Data Complexity and Dimensionality: The stock market is influenced
by a wide range of variables, including technical indicators, economic
data, market sentiment, and global events. Incorporating all relevant
factors into a prediction model introduces significant complexity and the
10 | P a g e
Stock Market Price Prediction
Prediction
risk of overfitting, where a model learns the noise rather than the
underlying patterns.
11 | P a g e
Stock Market Price Prediction
Prediction
1.2 Objective
1. Develop Predictive Models Using Machine Learning Algorithms:
• To explore different machine learning algorithms, such as linear
regression, decision trees, random forests, support vector machines
(SVM), and deep learning models like neural networks, to determine the
most effective approach for stock market prediction.
2. Incorporate Technical Indicators and Feature Engineering:
• To integrate various technical indicators, such as moving averages (MA),
Relative Strength Index (RSI), Bollinger Bands, and MACD, as features
in the prediction models.
5. Address Data Challenges and Preprocessing:
• To preprocess historical stock data to remove noise, handle missing
values, and normalize the dataset for efficient model training.
• To handle challenges posed by noisy and volatile data, which may
otherwise lead to poor model performance.
4 .Evaluate Model Performance and Accuracy:
• To evaluate the performance of the machine learning models using
appropriate metrics such as Mean Absolute Error (MAE), Root Mean
Squared Error (RMSE), and R-squared, and identify the most accurate
model.
6. Handle Model Overfitting and Ensure Generalization:
• To apply techniques like regularization, hyperparameter tuning, and
cross-validation to prevent overfitting and ensure the models generalize
well to new, unseen data.
7. Analyze the Impact of External Factors:
• To explore the potential influence of external factors like macroeconomic
data, news sentiment, and social media trends on stock price movements
and incorporate them into the models (if applicable).
12 | P a g e
Stock Market Price Prediction
Prediction
1.3Need of Project
Stock market prediction has always been a complex and critical problem for
investors, traders, and financial analysts. Accurate forecasting of stock prices
can potentially lead to significant profits and improved investment strategies.
However, due to the unpredictable nature of the market, traditional methods
often fail to provide reliable predictions, especially in short-term market
movements. This has created a pressing need for more advanced techniques that
can better capture the complexities and dynamics of stock price behavior.
1. High Complexity and Volatility of Stock Markets:
• Dynamic Nature: The stock market is affected by a multitude of factors
such as company performance, economic indicators, geopolitical events,
and investor sentiment. Traditional models struggle to account for all
these dynamic influences, often leading to inaccurate predictions.
• Volatility: Stock prices exhibit high volatility, and even small changes in
market conditions can lead to significant price fluctuations. Machine
learning models, with their ability to process vast amounts of data, can
potentially capture underlying patterns that are difficult for traditional
models to identify.
1. Data Sources:
• Historical Stock Data: The project will use publicly available stock data,
which includes daily stock prices (open, close, high, low), trading
volume, and other relevant market information for a specific set of stocks
over a chosen period (e.g., past 5-10 years).
• Technical Indicators: Common technical indicators like Moving
Averages (MA), Relative Strength Index (RSI), Bollinger Bands, and
MACD will be used as features in the models to capture patterns that
could indicate future price movements.
2. Machine Learning Models:
• The project will explore a range of machine learning techniques,
including but not limited to:
o Supervised Learning: Regression models such as Linear
Regression, Support Vector Machines (SVM), and Random Forests
for predicting continuous stock prices.
o Deep Learning: Neural networks, including feedforward networks
and more advanced techniques like Long Short-Term Memory
(LSTM) networks, which are well-suited for time series
forecasting.
3. Feature Engineering:
• Data preprocessing will be an essential part of this project, where raw
stock data will be cleaned, normalized, and transformed into features that
14 | P a g e
Stock Market Price Prediction
Prediction
machine learning models can use effectively.
• Key features will include stock prices, volume, technical indicators, and
other relevant metrics that can help models predict future price trends.
4. Model Optimization and Fine-tuning:
• The project will involve selecting the best model based on performance
and optimizing its parameters using techniques such as grid search,
random search, or hyperparameter tuning to achieve the most accurate
predictions.
15 | P a g e
Stock Market Price Prediction
Prediction
Chapter 2
Related Concept
16 | P a g e
Stock Market Price Prediction
Prediction
o Long Short-Term Memory (LSTM): A type of RNN specifically
designed to address the vanishing gradient problem in long
17 | P a g e
Stock Market Price Prediction
Prediction
2.4. Model Evaluation and Validation
Literature Review
.1 Literature Review
1. Stock Market Characteristics
• Volatility and Non-Linearity: Stock prices are highly volatile and non-linear,
influenced by market sentiment, global events, and company-specific factors.
• Efficient Market Hypothesis (EMH): The hypothesis states that stock prices
reflect all available information, making them unpredictable to an extent. This
serves as a baseline to challenge with ML.
2. Machine Learning Techniques
• Traditional Methods:
o Linear Regression and Moving Averages for trend analysis.
o Deep Learning:
3. Related Work
• Studies combining technical indicators (e.g., RSI, MACD) with ML algorithms.
• Integration of sentiment analysis from news and social media for predictive
modeling.
• Hybrid models combining statistical techniques and deep learning for higher
accuracy.
4. Challenges
• Overfitting due to limited training data or high model complexity.
19 | P a g e
Stock Market Price Prediction
Prediction
Chapter 4
Methodology
1. Data Collection
• Sources:
o Stock market APIs (e.g., Yahoo Finance, Alpha Vantage).
o Historical price data, trading volume, and corporate financials.
o News and social media sentiment (e.g., Twitter, Reddit).
• Types of Data:
o Time-series data (prices, volume).
o Technical indicators (moving averages, Bollinger Bands).
o Sentiment analysis scores.
2. Data Preprocessing
3. Model Selection
6. Deployment
20 | P a g e
Stock Market Price Prediction
Prediction
• Use frameworks like Flask or FastAPI for deploying predictive models as
RESTful APIs.
• Visualize results using dashboards built with tools like Dash or Tableau.
7. Incorporating Feedback
21 | P a g e
Stock Market Price Prediction
Prediction
Chapter 5
Hardware and Software requirement
1. Processor:
• Minimum: Dual-Core Processor (e.g., Intel Core i3 or AMD
equivalent)
• Recommended: Quad-Core Processor (e.g., Intel Core i5/i7 or AMD
Ryzen 5/7)
2. RAM:
1. Minimum: 4 GB
2. Recommended: 8 GB or higher (to handle large datasets and
faster processing)
3. Storage:
1. Minimum: 20 GB free disk space
2. Recommended: SSD with at least 50 GB free space (for faster
data processing and model training)
4. Display:
A monitor with standard resolution (1920 x 1080) for visualizing
results and graphs.
5. Input Devices:
Keyboard and mouse for data input and system navigation
22 | P a g e
Stock Market Price Prediction
Prediction
PROCESSOR INTEL i5 OR HIGHER
Libraries :
• Data Processing:
1. Pandas
2. Numpy
• Feature Extraction:
1. Urllib
2. re (regular expressions)
• Machine Learning:
1. scikit-learn
2. xgboost (optional)
3. TensorFlow / Keras:
23 | P a g e
Stock Market Price Prediction
Prediction
• Visualization
1. Matplotlib
2. Seaborn
• Integrated Development Environment (IDE):
1. Jupyter Notebook (recommended for ease of visualization)
2. PyCharm or Visual Studio Code (for structured development)
• Dataset:
1. HDFC, Asian Paint etc (e.g., from Kaggle or PhishTank).
• Deployment Tools:
1. Flask or FastAPI for creating a web interface for the detection
system.
24 | P a g e
Stock Market Price Prediction
Prediction
Chapter 6
Implementation
Implementation
Step 1: Data Collection
1. Source Stock Data:
o You will need historical stock data, which includes features like
daily stock prices (open, close, high, low), trading volume, and any
other relevant financial data.
o Data can be sourced from various platforms such as:
▪ Yahoo Finance API
▪ Alpha Vantage API
▪ Quandl API
▪ Google Finance (via web scraping)
2. Example (using Yahoo Finance API with Python's yfinance library):
import yfinance as yf
# Download stock data for a specific company, e.g., 'AAPL' (Apple) from
Yahoo Finance
data = yf.download("AAPL", start="2010-01-01", end="2024-01-01")
print(data.head())
25 | P a g e
Stock Market Price Prediction
Prediction
3. Normalization:
o Normalize the data to bring all features to a common scale, which helps in
improving model performance.
4. Split Data into Training and Testing Sets:
o Typically, 70%-80% of the data is used for training, and the rest is kept for
testing and evaluation.
Step 6: Visualization
1. Plotting Stock Prices:
o Visualize actual and predicted stock prices to understand the
model's performance.
28 | P a g e
Stock Market Price Prediction
Prediction
Code of Model:-
#**************** IMPORT PACKAGES ********************
from flask import Flask, render_template, request, flash, redirect, url_for
from alpha_vantage.timeseries import TimeSeries
import pandas as pd
import numpy as np
from statsmodels.tsa.arima.model import ARIMA
from sklearn.metrics import mean_squared_error
import matplotlib.pyplot as plt
plt.style.use('ggplot')
import math, random
from datetime import datetime
import datetime as dt
import yfinance as yf
import tweepy
import preprocessor as p
import re
from sklearn.linear_model import LinearRegression
from textblob import TextBlob
import constants as ct
from Tweet import Tweet
import nltk
nltk.download('punkt')
# Ignore Warnings
import warnings
warnings.filterwarnings("ignore")
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
29 | P a g e
Stock Market Price Prediction
Prediction
#***************** FLASK *****************************
app = Flask( name )
#To control caching so as to save and retrieve plot figs on client side
@app.after_request
def add_header(response):
response.headers['Pragma'] = 'no-cache'
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
response.headers['Expires'] = '0'
return response
@app.route('/')
def index():
return render_template('index.html')
@app.route('/insertintotable',methods = ['POST'])
def insertintotable():
nm = request.form['nm']
quantity = Quantity_date.values
size = int(len(quantity) * 0.80)
train, test = quantity[0:size], quantity[size:len(quantity)]
#fit in model
predictions = arima_model(train, test)
#plot graph
fig = plt.figure(figsize=(7.2,4.8),dpi=65)
plt.plot(test,label='Actual Price')
plt.plot(predictions,label='Predicted Price')
32 | P a g e
Stock Market Price Prediction
Prediction
plt.legend(loc=4)
plt.savefig('static/ARIMA.png')
plt.close(fig)
print()
print("#####################################################
#########################")
arima_pred=predictions[-2]
print("Tomorrow's",quote," Closing Price Prediction by
ARIMA:",arima_pred)
#rmse calculation
error_arima = math.sqrt(mean_squared_error(test, predictions))
print("ARIMA RMSE:",error_arima)
print("#####################################################
#########################")
return arima_pred, error_arima
def LSTM_ALGO(df):
#Split data into training set and test set
dataset_train=df.iloc[0:int(0.8*len(df)),:]
dataset_test=df.iloc[int(0.8*len(df)):,:]
############# NOTE #################
#TO PREDICT STOCK PRICES OF NEXT N DAYS, STORE
PREVIOUS N DAYS IN MEMORY WHILE TRAINING
# HERE N=7
###dataset_train=pd.read_csv('Google_Stock_Price_Train.csv')
training_set=df.iloc[:,4:5].values# 1:2, to store as numpy array else Series
33 | P a g e
Stock Market Price Prediction
Prediction
obj will be stored
#select cols using above manner to select as float64 type, view in var
explorer
#Feature Scaling
from sklearn.preprocessing import MinMaxScaler
sc=MinMaxScaler(feature_range=(0,1))#Scaled values btween 0,1
training_set_scaled=sc.fit_transform(training_set)
#In scaling, fit_transform for training, transform for test
34 | P a g e
Stock Market Price Prediction
Prediction
#Building RNN
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Dropout
from keras.layers import LSTM
#Initialise RNN
regressor=Sequential()
35 | P a g e
Stock Market Price Prediction
Prediction
#Add o/p layer
regressor.add(Dense(units=1))
#Compile
regressor.compile(optimizer='adam',loss='mean_squared_error')
#Training
regressor.fit(X_train,y_train,epochs=25,batch_size=32 )
#For lstm, batch_size=power of 2
#Testing
###dataset_test=pd.read_csv('Google_Stock_Price_Test.csv')
real_stock_price=dataset_test.iloc[:,4:5].values
#To predict, we need stock prices of 7 days before the test set
#So combine train and test set to get the entire data set
dataset_total=pd.concat((dataset_train['Close'],dataset_test['Close']),axis=0
)
testing_set=dataset_total[ len(dataset_total) -len(dataset_test) -7: ].values
testing_set=testing_set.reshape(-1,1)
#-1=till last row, (-1,1)=>(80,1). otherwise only (80,0)
#Feature scaling
testing_set=sc.transform(testing_set)
#Testing Prediction
predicted_stock_price=regressor.predict(X_test)
plt.legend(loc=4)
plt.savefig('static/LSTM.png')
plt.close(fig)
error_lstm = math.sqrt(mean_squared_error(real_stock_price,
predicted_stock_price))
#Forecasting Prediction
forecasted_stock_price=regressor.predict(X_forecast)
lstm_pred=forecasted_stock_price[0,0]
37 | P a g e
Stock Market Price Prediction
Prediction
print()
print("#######################################################
#######################")
print("Tomorrow's ",quote," Closing Price Prediction by LSTM:
",lstm_pred)
print("LSTM RMSE:",error_lstm)
print("#######################################################
#######################")
return lstm_pred,error_lstm
#***************** LINEAR REGRESSION SECTION
******************
def LIN_REG_ALGO(df):
#No of days to be forcasted in future
forecast_out = int(7)
#Price after n days
df['Close after n days'] = df['Close'].shift(-forecast_out)
#New df with only relevant data
df_new=df[['Close','Close after n days']]
# Feature Scaling===Normalization
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)
X_to_be_forecasted=sc.transform(X_to_be_forecasted)
#Training
clf = LinearRegression(n_jobs=-1)
clf.fit(X_train, y_train)
#Testing
y_test_pred=clf.predict(X_test)
y_test_pred=y_test_pred*(1.04)
plt2.legend(loc=4)
plt2.savefig('static/LR.png')
plt2.close(fig)
polarity += sentence.sentiment.polarity
if polarity>0:
pos=pos+1
if polarity<0:
neg=neg+1
global_polarity += sentence.sentiment.polarity
if count > 0:
tw_list.append(tw2)
tweet_list.append(Tweet(tw, polarity))
count=count-1
if len(tweet_list) != 0:
global_polarity = global_polarity / len(tweet_list)
else:
global_polarity = global_polarity
neutral=ct.num_of_tweets-pos-neg
if neutral<0:
neg=neg+neutral
neutral=20
42 | P a g e
Stock Market Price Prediction
Prediction
print()
print("#######################################################
#######################")
print("Positive Tweets :",pos,"Negative Tweets :",neg,"Neutral Tweets
:",neutral)
print("#######################################################
#######################")
labels=['Positive','Negative','Neutral']
sizes = [pos,neg,neutral]
explode = (0, 0, 0)
fig = plt.figure(figsize=(7.2,4.8),dpi=65)
fig1, ax1 = plt.subplots(figsize=(7.2,4.8),dpi=65)
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
startangle=90)
# Equal aspect ratio ensures that pie is drawn as a circle
ax1.axis('equal')
plt.tight_layout()
plt.savefig('static/SA.png')
plt.close(fig)
#plt.show()
if global_polarity>0:
print()
print("#####################################################
#########################")
print("Tweets Polarity: Overall Positive")
print("#####################################################
#########################")
tw_pol="Overall Positive"
else:
print()
43 | P a g e
Stock Market Price Prediction
Prediction
print("#####################################################
#########################")
print("Tweets Polarity: Overall Negative")
print("#####################################################
#########################")
tw_pol="Overall Negative"
return global_polarity,tw_list,tw_pol,pos,neg,neutral
#**************GET DATA
***************************************
quote=nm
#Try-except to check if valid stock symbol
try:
get_historical(quote)
except:
return render_template('index.html',not_found=True)
else:
arima_pred, error_arima=ARIMA_ALGO(df)
lstm_pred, error_lstm=LSTM_ALGO(df)
df, lr_pred, forecast_set,mean,error_lr=LIN_REG_ALGO(df)
# Twitter Lookup is no longer free in Twitter's v2 API
# polarity,tw_list,tw_pol,pos,neg,neutral =
retrieving_tweets_polarity(quote)
polarity, tw_list, tw_pol, pos, neg, neutral = 0, [], "Can't fetch tweets,
Twitter Lookup is no longer free in API v2.", 0, 0, 0
47 | P a g e
Stock Market Price Prediction
Prediction
Chapter 7
Pseudo code
48 | P a g e
Stock Market Price Prediction
Prediction
model (usually 80% of the data) and the other for testing the model’s
performance (usually 20%).
Step 3: Feature Selection
Purpose: Identify which data columns (features) will be used to predict the
target variable (e.g., closing price of the stock).
• Features: The features (independent variables) are typically
technical indicators like SMA_50, SMA_200, and RSI, which are
expected to help predict future stock prices.
• Target: The target variable (dependent variable) is the stock’s
closing price, which is what the model will predict.
• Split Data into Features and Target: The dataset is separated
49 | P a g e
Stock Market Price Prediction
Prediction
o MAE (Mean Absolute Error): The average of the absolute
differences between the predicted and actual values. A lower
MAE indicates better accuracy.
o RMSE (Root Mean Squared Error): A measure of how well
the model's predictions match the actual values, with more
weight given to larger errors.
o R² (R-squared): The proportion of variance in the target
variable that the model can explain. A value closer to 1 means
the model explains most of the variance.
Step 6: Making Predictions
• Preprocessing: The new data is preprocessed to match the format
used during training.
• Prediction: The trained model predicts the stock price for the future
based on the latest processed data.
Step 7: Data Visualization
• Visualization: To better understand the model’s performance, we
visualize the actual vs predicted stock prices. This helps us see how
well the model tracks stock price trends and where it might have
gone wrong.
• Graphing: A graph is plotted showing the true stock prices (actual)
vs. predicted values (predictions). This visual representation can
provide insights into the accuracy of the model.
50 | P a g e
Stock Market Price Prediction
Prediction
4.2 Snapshot of Output
51 | P a g e
Stock Market Price Prediction
Prediction
Fig 2.2 :Stock Price Prediction
52 | P a g e
Stock Market Price Prediction
Prediction
Figure 3.2: APPLE STOCK DATA
53 | P a g e
Stock Market Price Prediction
Prediction
Conclusion
In this project, we developed a stock market price prediction model using
machine learning techniques. The goal was to predict future stock prices based
on historical data, incorporating both price-related features and technical
indicators like moving averages (SMA) and the Relative Strength Index (RSI).
Key Steps Involved:
1. Data Collection: We gathered historical stock data using APIs such as
Yahoo Finance, including essential data points like the opening, closing,
high, low prices, and trading volume.
2. Data Preprocessing: The collected data was cleaned and preprocessed
by handling missing values, normalizing the features, and adding useful
technical indicators. This allowed us to prepare the data in a form that
could be fed into machine learning models.
3. Feature Selection: Key features like moving averages and RSI were
selected to help the model learn patterns from historical data, with the
closing price as the target variable.
4. Model Selection and Training: We selected an appropriate machine
learning model (e.g., Linear Regression, Random Forest, or LSTM) to
predict stock prices and trained the model using the preprocessed data.
5. Model Evaluation: The performance of the model was evaluated using
metrics like Mean Absolute Error (MAE), Root Mean Squared Error
(RMSE), and R-squared (R²), providing insights into how well the
model performed in predicting stock prices.
6. Making Predictions: After evaluating the model's accuracy, it was used
to predict future stock prices, providing valuable insights for investors or
traders looking to make informed decisions.
7. Visualization: We used data visualization techniques to display the
comparison between actual and predicted stock prices, offering a clear
understanding of how well the model performed.
Findings:
• The model demonstrated reasonable predictive power, although stock
market prediction remains a challenging task due to the volatile and non-
linear nature of financial markets.
• The inclusion of technical indicators like moving averages and RSI
helped improve the model's performance, highlighting their importance in
stock price forecasting.
Future Work:
• Model Improvement: Experimenting with more complex models, such
as LSTM (Long Short-Term Memory) networks, which are designed to
handle time series data, could improve performance further.
• Real-Time Data: Integrating real-time data feeds to make live predictions can
make the model more useful for active trading.
Stock market price prediction is an area of significant interest and
challenge, driven by the promise of transforming financial analysis,
54 | P a g e
Stock Market Price Prediction
Prediction
investment strategies, and economic planning. While the inherent
volatility of stock markets makes precise predictions difficult,
advancements in technology have brought us closer to extracting
meaningful patterns and trends. The fusion of traditional financial
expertise with cutting-edge artificial intelligence (AI) and machine
learning (ML) tools has opened new pathways for improving prediction
accuracy. However, this journey also highlights the complexities,
limitations, and future opportunities that define the domain.
55 | P a g e
Stock Market Price Prediction
Prediction
To overcome these limitations, the future of stock market price prediction
must emphasize hybrid approaches that combine the strengths of multiple
methodologies. For example, integrating econometric models with
56 | P a g e
Stock Market Price Prediction
Prediction
References
3) https://www.geeksforgeeks.org/machine-learning/
4) https://www.kaggle.com/
5) https://www.tensorflow.org/
6) https://www.yahoofinanceapi.com/
7) https://www.alphavantage.com/
57 | P a g e
Stock Market Price Prediction
Prediction
58 | P a g e
Stock Market Price Prediction
Prediction