Skip to content

AmmarsGeeks/Stock-Sentiment-MLOps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stock Sentiment Analysis & Ranking System 📈

A comprehensive MLOps solution for analyzing financial news sentiment and ranking stocks based on market impact.

Python 3.9+ Gradio Transformers


🏗️ Infrastructure

Data Pipeline

  1. Data Ingestion: Curated financial news data from Kaggle News Sentiment Dataset.
  2. Local Storage: News articles stored in SQLite database with schema:
    • articles(id, title, content, date, source)
    • sentiments(article_id, label, score)
  3. Real-time Processing:
    • Continuous model validation using incremental learning.
    • Automated data versioning with DVC.

MLOps Architecture

Data Layer (SQLite) → Processing Layer → Model Serving → Application Layer (Gradio)

🤖 Sentiment Analysis

  • Technical Implementation: Base Model: FinBERT (Financial Domain BERT).

  • Custom Training:

Fine-tuned on Kaggle dataset (10,000 labeled articles).

Dynamic threshold adjustment based on market volatility.

  • Processing Flow::

Text cleaning (stopwords, lemmatization).

Context-aware sentiment scoring.

Confidence-based filtering (score > 0.7).

Visualization

Interactive Plotly histograms.

Real-time sentiment distribution updates.

🏆 Ranking System

Algorithm Components

Ranking Score = 
  (Sentiment Strength × 0.5) + 
  (Article Volume × 0.3) + 
  (Recency Factor × 0.2)

Key Metrics

Sentiment Strength: Weighted average of confidence scores.

Article Volume: log(n_articles) scaled 0-1.

Recency Factor: Exponential decay (24h half-life).

🚀 Getting Started

Installation

git clone https://github.com/AmmarsGeeks/Stock-Sentiment-MLOps
cd stock-sentiment-mlops
pip install -r requirements.txt

Configuration

# Copy the example environment file:
cp .env.example .env

Edit .env to include:

Database path.

Model parameters.

Run Application

python main.py

📊 API Reference

GET /analyze

Fetch sentiment analysis for a specific company:

curl http://localhost:8000/analyze?company=Apple

POST /rank

Rank multiple companies based on news sentiment:

curl -X POST http://localhost:8000/rank \
  -H "Content-Type: application/json" \
  -d '{"companies": ["Apple", "Microsoft", "Google"]}'

🛠️ Technologies Used

Rank multiple companies based on news sentiment:

Python: Core programming language.

Gradio: For building the web interface.

Transformers: For sentiment analysis using FinBERT.

SQLite: For local data storage.

Plotly: For interactive visualizations.

🤝 Acknowledgments

Kaggle: For providing the News Sentiment Analysis Dataset.

Hugging Face: For the FinBERT model.

Gradio: For the easy-to-use web interface framework.

Releases

No releases published

Packages

No packages published