Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

ย 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ˆ Stock Trend Analyzer

An end-to-end predictive analytics platform for stock trend forecasting, powered by Machine Learning and LLM-driven financial insights.

Python Scikit-learn LangChain Streamlit OpenAI


๐Ÿ“Œ Overview

Stock Trend Analyzer is a full-stack machine learning application that:

  • ๐Ÿ“Š Predicts stock price trends using ML forecasting models
  • ๐Ÿค– Generates AI-powered financial insights using LangChain + OpenAI
  • ๐Ÿ“‰ Visualizes predictions on a real-time interactive dashboard
  • ๐Ÿ” Analyzes historical patterns to surface actionable trading signals
  • ๐Ÿ’ก Explains predictions in plain English using LLM-generated commentary

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   DATA SOURCES                          โ”‚
โ”‚         Yahoo Finance API / CSV Historical Data         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ”‚
                       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                 DATA PIPELINE                           โ”‚
โ”‚     Pandas โ€ข NumPy โ€ข Feature Engineering โ€ข Cleaning     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ”‚
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ–ผ            โ–ผ            โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  ML Models   โ”‚ โ”‚  SQL DB  โ”‚ โ”‚   LangChain  โ”‚
โ”‚ (Scikit-learnโ”‚ โ”‚(Storage) โ”‚ โ”‚ + OpenAI LLM โ”‚
โ”‚  + PyTorch)  โ”‚ โ”‚          โ”‚ โ”‚  (Insights)  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
          โ”‚            โ”‚            โ”‚
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                       โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              STREAMLIT DASHBOARD                        โ”‚
โ”‚     Real-time Charts โ€ข Predictions โ€ข AI Commentary      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ› ๏ธ Tech Stack

Category Technology
Language Python 3.10+
ML Models Scikit-learn, PyTorch, LSTM
LLM / AI LangChain, OpenAI GPT-4
Data Processing Pandas, NumPy, SciPy
Visualization Streamlit, Matplotlib, Plotly
Database SQL (SQLite / PostgreSQL)
Data Source Yahoo Finance API (yfinance)
DevOps Git, Docker

โœจ Key Features

  • ๐Ÿ“ˆ Multi-model forecasting โ€” LSTM, Random Forest, Linear Regression
  • ๐Ÿค– LLM-powered commentary โ€” AI explains predictions in plain English
  • ๐Ÿ“Š Interactive dashboard โ€” real-time Streamlit charts with zoom/filter
  • ๐Ÿ” Technical indicators โ€” RSI, MACD, Bollinger Bands, Moving Averages
  • ๐Ÿ“‰ Anomaly detection โ€” flags unusual price movements automatically
  • ๐Ÿ’พ Historical backtesting โ€” evaluate model accuracy on past data
  • โšก Fast predictions โ€” sub-second inference on trained models
  • ๐ŸŽฏ Multi-stock support โ€” analyze any ticker (AAPL, TSLA, GOOGL, etc.)

๐Ÿš€ Quick Start

Prerequisites

Python 3.10+
OpenAI API Key (for LLM insights)

Installation

# Clone the repository
git clone https://github.com/jeevan1098/Stock-Trend-Analyzer
cd Stock-Trend-Analyzer

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Set environment variables
cp .env.example .env
# Add OPENAI_API_KEY to .env

Run the App

# Launch Streamlit dashboard
streamlit run app.py

# App opens at http://localhost:8501

๐Ÿ“ก How It Works

1. Data Collection

import yfinance as yf

# Fetch historical stock data
stock = yf.Ticker("AAPL")
df = stock.history(period="2y")

2. Feature Engineering

# Technical indicators
df['RSI'] = compute_rsi(df['Close'], window=14)
df['MACD'] = compute_macd(df['Close'])
df['BB_upper'], df['BB_lower'] = compute_bollinger(df['Close'])
df['MA_50'] = df['Close'].rolling(50).mean()
df['MA_200'] = df['Close'].rolling(200).mean()

3. ML Prediction

from sklearn.ensemble import RandomForestRegressor

model = RandomForestRegressor(n_estimators=100)
model.fit(X_train, y_train)
predictions = model.predict(X_test)

4. LLM Insight Generation

from langchain.chains import LLMChain

# Generate plain English explanation of prediction
insight = chain.run(
    ticker="AAPL",
    prediction=predictions[-1],
    trend="upward",
    confidence=0.87
)
# Output: "Apple stock shows strong bullish momentum..."

๐Ÿ“Š Model Performance

Model MAE RMSE Rยฒ Score
LSTM Neural Network 2.34 3.12 0.91
Random Forest 2.87 3.76 0.88
Linear Regression 4.21 5.43 0.79
Ensemble (Best) 1.98 2.67 0.93

๐Ÿ“‚ Project Structure

Stock-Trend-Analyzer/
โ”‚
โ”œโ”€โ”€ app.py                    # Streamlit dashboard entry point
โ”œโ”€โ”€ requirements.txt          # Python dependencies
โ”œโ”€โ”€ .env.example              # Environment variables template
โ”‚
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ fetch_data.py         # Yahoo Finance data ingestion
โ”‚   โ”œโ”€โ”€ preprocess.py         # Data cleaning + feature engineering
โ”‚   โ””โ”€โ”€ indicators.py         # Technical indicators (RSI, MACD, BB)
โ”‚
โ”œโ”€โ”€ models/
โ”‚   โ”œโ”€โ”€ lstm_model.py         # LSTM neural network
โ”‚   โ”œโ”€โ”€ random_forest.py      # Random Forest regressor
โ”‚   โ”œโ”€โ”€ ensemble.py           # Ensemble model combiner
โ”‚   โ””โ”€โ”€ evaluate.py           # Model evaluation metrics
โ”‚
โ”œโ”€โ”€ llm/
โ”‚   โ”œโ”€โ”€ langchain_agent.py    # LangChain + OpenAI integration
โ”‚   โ””โ”€โ”€ insight_generator.py  # LLM financial commentary
โ”‚
โ”œโ”€โ”€ dashboard/
โ”‚   โ”œโ”€โ”€ charts.py             # Plotly/Matplotlib visualizations
โ”‚   โ””โ”€โ”€ components.py         # Streamlit UI components
โ”‚
โ””โ”€โ”€ tests/
    โ”œโ”€โ”€ test_models.py         # Model accuracy tests
    โ””โ”€โ”€ test_pipeline.py       # Data pipeline tests

๐ŸŽฏ Use Cases

  • ๐Ÿ“Š Individual investors โ€” get AI-powered stock analysis instantly
  • ๐Ÿฆ Financial analysts โ€” automate trend reporting with LLM commentary
  • ๐Ÿ“š ML researchers โ€” benchmark forecasting models on financial data
  • ๐ŸŽ“ Students โ€” learn applied ML + LLM integration on real-world data

๐Ÿ”ฎ Future Improvements

  • Add sentiment analysis from financial news (Reuters, Bloomberg)
  • Real-time streaming data with Apache Kafka
  • Portfolio optimization using Modern Portfolio Theory
  • Options pricing with Black-Scholes model
  • Deploy on AWS Lambda for serverless predictions

๐Ÿค Connect

Jeevan Babu Gotru

LinkedIn Portfolio Email GitHub


โญ Star this repo if you found it useful!

Built with โค๏ธ | MS Computer Science @ University of South Alabama

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages