Python Projects

Stock Price Prediction Using Machine Learning

Stock Price Prediction Using Machine Learning

Stock Price Prediction Using Python and Flask

Stock Price Prediction is a Flask-based stock analysis web application developed as StockSense AI. The project combines the latest available stock market data with technical analysis and a simple trend-based forecast to provide users with useful stock insights through a modern and interactive dashboard.

The application retrieves stock information using the yfinance library and processes historical price data with Python, Pandas, and NumPy. It calculates the Relative Strength Index (RSI), generates BUY, HOLD, or SELL recommendations, provides a simple next-close forecast, and presents stock information through interactive charts and financial metrics.

The frontend uses an AI-focused interface with features such as AI-Powered Analysis, AI Analysis Engine, AI Market Insights, and an interactive Stock Assistant. The project documentation describes these as AI-style features, while the actual prediction logic uses explainable RSI and linear-trend calculations rather than a trained machine learning model.

Project Overview

Project NameStock Price Prediction
Project TypeStock Market Analysis Web Application
FrameworkFlask
Programming LanguagePython
FrontendHTML, CSS, JavaScript, Bootstrap
Data SourceYahoo Finance through yfinance
Data ProcessingPandas and NumPy
Technical IndicatorRelative Strength Index (RSI)
ChartsChart.js
DatabaseNot Used
APIFlask JSON API Endpoints
DeveloperUPDATEGADH

Introduction

Understanding stock market data requires more than simply viewing the current price of a company. Investors and learners often need historical price information, trading volume, technical indicators, financial metrics, and trend information in one place.

The Stock Price Prediction project provides a web-based solution for this purpose. Users can enter a stock symbol such as AAPL, TSLA, or MSFT, after which the application retrieves available market data and prepares an interactive stock analysis.

The application calculates RSI to determine the current momentum condition and generates a simple BUY, HOLD, or SELL recommendation. It also analyzes the latest 30 closing prices using a straight-line trend to estimate the next closing price.

The result is displayed through a modern StockSense AI interface containing stock information, technical analysis, charts, financial metrics, AI-style insights, and a Stock Assistant.

How Stock Price Prediction Works

  1. The user enters a valid stock symbol on the homepage.
  2. The frontend sends a request to the Flask stock API.
  3. The backend retrieves approximately one year of historical data using yfinance.
  4. The application calculates the latest price and price change.
  5. The backend calculates the RSI using historical closing prices.
  6. A BUY, HOLD, or SELL recommendation is generated according to the RSI value.
  7. The latest 30 closing prices are used to calculate a simple linear trend.
  8. The trend is projected to estimate the next available trading-day closing price.
  9. The results are returned to the frontend through JSON responses.
  10. The dashboard displays the stock analysis using charts, cards, tables, and financial information.

AI Features

The project interface is designed around StockSense AI and contains several AI-focused components.

AI-Powered Analysis

The homepage presents an AI-Powered Analysis interface where users can enter a stock symbol and request an analysis.

AI Analysis Engine

The application includes an AI Analysis Engine section that processes the available stock data and displays the generated stock insights.

AI Market Insights

After analyzing a stock, the interface displays AI Market Insights containing the generated recommendation and prediction information.

AI Says Recommendation

The result interface presents the generated BUY, HOLD, or SELL recommendation using an AI-style presentation.

Stock Assistant

The dashboard contains a Stock Assistant that allows users to ask supported questions about prediction, RSI, or recommendation. The assistant communicates with the /api/insights/<symbol> endpoint and returns a short response based on the application’s calculations.

Important: The project README explains that the “AI” functionality uses lightweight and explainable techniques. It does not contain a trained neural network or a separate advanced machine learning model.

Prediction and Technical Analysis

RSI-Based Recommendation

The application calculates the Relative Strength Index (RSI) using a 14-period calculation.

  • RSI below 30: BUY
  • RSI above 70: SELL
  • RSI between 30 and 70: HOLD

If there is insufficient data to calculate RSI, the application returns a HOLD status indicating insufficient RSI data.

Next Close Forecast

The application uses the most recent approximately 30 closing prices and fits a straight-line trend using NumPy. The resulting trend is projected forward to estimate the next trading day’s closing price.

This is a simple, transparent trend calculation and should not be interpreted as a guaranteed market prediction.

Available Features

  • Stock Symbol Search: Search for a stock using its market symbol.
  • Latest Stock Price: Displays the latest available closing price.
  • Price Change: Shows price movement and percentage change.
  • RSI Analysis: Calculates the Relative Strength Index.
  • BUY/HOLD/SELL Recommendation: Generates a recommendation from RSI thresholds.
  • Next Close Forecast: Estimates the next trading-day closing price using a recent linear trend.
  • One-Year Price Chart: Displays approximately one year of stock price history.
  • Volume Chart: Displays historical trading volume, including the latest 30-day volume visualization.
  • Financial Summary: Displays available market and company information.
  • Market Capitalization: Shows the available market cap.
  • P/E Ratio: Displays the available trailing P/E ratio.
  • Dividend Yield: Displays available dividend yield information.
  • 52-Week High and Low: Shows available yearly price limits.
  • Average Volume: Displays the available average trading volume.
  • Sector and Industry: Displays available company classification information.
  • Historical Data Table: Displays recent historical stock data.
  • CSV Export: Allows users to download complete historical stock data as CSV.
  • JSON API: Provides stock data and chart information through a Flask API.
  • Stock Assistant: Provides supported prediction, RSI, and recommendation responses.
  • Responsive Dashboard: Provides a modern dark-themed stock analysis interface.

Project Modules

1. Homepage and AI Analysis

The homepage provides the StockSense AI interface where users enter a stock symbol and start the analysis.

2. Stock Data Module

The backend retrieves stock information and historical market data from Yahoo Finance using yfinance.

3. RSI Analysis Module

This module calculates RSI from historical closing prices and generates the corresponding recommendation.

4. Prediction Module

The prediction module uses the recent closing prices to calculate a simple linear trend and estimate the next closing price.

5. Dashboard Module

The dashboard presents price information, recommendation, charts, financial metrics, historical data, and CSV download functionality.

6. Stock Assistant Module

The Stock Assistant communicates with the insights API and responds to supported questions related to prediction, RSI, and recommendation.

7. API Module

The application provides JSON endpoints for stock data and AI-style insights.

API Endpoints

The application provides the following Flask API endpoints:

  • GET /api/stock/<symbol> – Returns stock summary, RSI, recommendation, and chart data.
  • POST /api/insights/<symbol> – Returns prediction, RSI, recommendation, and a short AI-style response.
  • GET /download/<symbol> – Downloads historical stock data as a CSV file.

Technology Stack

  • Python – Main programming language
  • Flask 3.1.1 – Web framework
  • yfinance 0.2.61 – Yahoo Finance market data
  • Pandas 2.2.3 – Data processing
  • NumPy 2.2.6 – Numerical calculations and trend fitting
  • Jinja2 – Flask template rendering
  • Bootstrap – Responsive interface
  • JavaScript – Frontend interactions
  • Chart.js – Price and volume charts
  • Font Awesome – Interface icons

Software and Tools Required

  • Python
  • Visual Studio Code
  • Web Browser
  • Internet Connection for retrieving Yahoo Finance data

Project Installation

Step 1: Extract the Project

Extract the Stock Price Prediction ZIP file and open the project folder in Visual Studio Code.

Step 2: Create a Virtual Environment

python -m venv venv

Step 3: Activate the Virtual Environment

For Windows:

venv\Scripts\activate

Step 4: Install Dependencies

The ZIP contains the dependency file named requi.txt. Install the required packages using:

pip install -r requi.txt

Step 5: Run the Application

The project provides main.py as the launcher:

python main.py

The Flask application runs on port 5000. Open the local application address displayed by Flask in your browser.

How to Use the Project

  1. Start the Flask application.
  2. Open the homepage in a web browser.
  3. Enter a stock symbol such as AAPL, TSLA, or MSFT.
  4. Click Analyze with AI.
  5. Review the current price and price change.
  6. Check the AI-style BUY, HOLD, or SELL recommendation.
  7. Review the RSI score.
  8. Read the AI Market Insights.
  9. Open the Full Dashboard for detailed information.
  10. Analyze the one-year price chart and volume chart.
  11. Review financial information such as market cap, P/E ratio, dividend yield, 52-week high, 52-week low, average volume, sector, and industry.
  12. Use the Stock Assistant to ask supported questions about prediction or recommendation.
  13. Download the historical stock data as a CSV file when required.

Project Benefits

  • Provides a complete Flask-based stock analysis application.
  • Uses market data retrieved through yfinance.
  • Provides RSI-based technical analysis.
  • Includes a simple and explainable next-close forecast.
  • Provides AI-style stock analysis through the frontend interface.
  • Includes an interactive Stock Assistant.
  • Displays price and volume charts.
  • Provides useful financial company information.
  • Supports CSV export of historical stock data.
  • Provides JSON API endpoints for frontend communication.
  • Useful for students learning Python, Flask, APIs, financial data processing, and data visualization.

Project Limitations

The application’s forecast is based on historical price trends and does not use a trained machine learning model. The recommendation is based on RSI thresholds, while the next-close estimate uses a simple linear trend over recent closing prices.

The project does not include fundamental valuation models, news sentiment analysis, advanced machine learning models, deep learning, user authentication, or watchlist management.

The generated prediction and recommendation should therefore be considered an educational analysis rather than guaranteed financial or investment advice.

Conclusion

Stock Price Prediction is a practical Python Flask project that demonstrates how stock market data can be retrieved, processed, analyzed, and visualized through a modern web application. Its StockSense AI interface combines AI-style presentation with transparent technical analysis methods such as RSI-based recommendations and linear trend forecasting.

Keywords: Stock Price Prediction, Stock Price Prediction Using Python, Stock Prediction Flask, StockSense AI, Python Stock Market Project, Flask Stock Analysis, Stock Market Analysis Python, yfinance Python Project, RSI Stock Prediction, Stock Prediction Project, AI Stock Analysis, Python Flask Project

Source Code Available

Interested in This Project?

Get the complete source code for this project at a very affordable price — perfect for your portfolio, college submission, or learning. Message us on WhatsApp and we'll get back to you instantly!

Full source code included Step-by-step setup guide Instant delivery on WhatsApp Instant reply on WhatsApp
Chat on WhatsApp

We usually reply within a few minutes

Leave a Reply

Your email address will not be published. Required fields are marked *

Chat with us