Skip to content

Aurelien7877/Financial-News_for_stock_prediciton

Repository files navigation

Financial News Anlysis for stock prediciton with Machine Learning approachs

📌 Project Overview

Objective

Develop an NLP-powered sentiment analysis engine to predict stock movements using financial news data to help traders in their daily decisions.

ChatGPT Image 23 juin 2025, 13_17_54

Methodology

  1. Sentiment Analysis ✅​
    --> Analyze the sentiments and perspectives within the texts to discern the global sentiment of a document​

  2. Topic Modeling​ ✅ --> Identify and categorize key themes in the texts to obtain a comprehensive understanding of the topics.​

  3. Aspect Based Sentiment​ ✅ ​--> Analyze specific aspects in the text to understand sentiment nuances or specific perspectives .​ ​

  4. Historical Sentiment Records​ (Next steps) --> Explore temporal trends in sentiment analysis to understand the evolution of opinions over time ​ ​

mermaid
graph TD
    A[Raw Financial News] --> B(Sentiment Analysis)
    B --> C(Topic Modeling)
    C --> D(Aspect-Based Analysis)
    D --> E(Temporal Trend Analysis)
    E --> F[Stock Movement Prediction]

🔍 Core Components

1. Sentiment Analysis Models

Model Architecture Epochs Classes Accuracy
DistilRoberta Transformer 10 2 100% (overfit)
FinancialBERT BERT-base 10 2 99% (overfit)
FinancialLarge RoBERTa-large 5 3 92%
What I chose to finetune:

Two-Class Sentiment Analysis:​​

  • Data classified into Negative or Positive sentiments​​
  • Fine-tuning with a 4-layer architecture​​
  • Training conducted over 10 epochs​ Capture d’écran 2025-06-23 à 13 27 30

Three-Class Sentiment Analysis:​​

  • Data categorized into Negative, Neutral, and Positive sentiments​​
  • Fine-tuning with a 4-layer architecture​​
  • Model trained for 5 epochs​​
Capture d’écran 2025-06-23 à 13 28 06

The results weren't good with the fine tunned models, it decreased some performance, especially the 3 class predictions. Let's moove on with the topic detection.

2. Topic Modeling Approach

I tested 3 LDA approachs. Linear discriminant analysis (LDA) is an approach used in supervised machine learning to solve multi-class classification problems. LDA separates multiple classes with multiple features through data dimensionality reduction.

Model Pros Cons
LDA 1 Robust, complete Buggy code
LDA 2 (BART) StackExchange fine-tuned Very slow
LDA 3 (Gensim) Clear, interactive visu Alpha balancing tricky

Gensim visualisations with alpha manipulation :

Capture d’écran 2025-06-23 à 13 35 27

Hybrid Solution choosen:

  • LDA for probabilistic topic assignment
  • BERT for semantic embedding
  • Weighted concatenation (α = 0.4)

Key Parameters:

  • 10 main financial topics
  • 3 subtopics per category
Capture d’écran 2025-06-23 à 13 36 22 Capture d’écran 2025-06-23 à 13 36 36 Capture d’écran 2025-06-23 à 13 36 59

3. Aspect-Based Analysis (ABSA)

Targeted goal: Be able to obtain a balanced analysis for a relevant measure of a sentiment associated to a speciic company or theme in a sentence where the opinion are mixed.

Aspect-Based Sentiment Analysis: Unlike general sentiment analysis, ABSA focuses on extracting sentiments associated with specific aspectsmentioned in a text.

Example Output:

{
  "text": "Bank A reported 15% revenue growth but increased debt",
  "aspects": [
    {"term": "revenue", "sentiment": "positive", "score": 0.82},
    {"term": "debt", "sentiment": "negative", "score": -0.76}
  ]
}

After identifying aspects, the model determines the sentiment (positive, negative, neutral) for each aspect in each document.

  • Version that identify the aspect by extracting nouns:
Capture d’écran 2025-06-23 à 13 38 26
  • Version after LDA topics injected
Capture d’écran 2025-06-23 à 13 38 48 Capture d’écran 2025-06-23 à 13 39 03

Results & Deliverables

Achievements

  • Good detection results with a big increase with LDA topic injection
  • Aspect-level sentiment extraction

Challenges

  • PhraseBank dataset limitation
  • Dependency chain between modules
  • Alpha parameter sensitivity in LDA-BERT hybrid

Next Steps

  1. More data integration
  2. Web scraper for historical sentiment
  3. Unified prediction engine
  4. Real-time API deployment

Dataset Example

{
  "sentence": "Orion Corp reported Q3 earnings fall due to R&D costs",
  "label": "negative",
  "topics": ["pharma", "earnings"],
  "aspects": {
    "earnings": -0.68,
    "R&D": 0.12
  }
}

Technical Stack

  • NLP Models: HuggingFace Transformers, Gensim, SpaCy
  • Visualization: PyLDAvis, Matplotlib
  • Infrastructure: Python 3.9, PyTorch 2.0

Aurélien Pouxviel, Data Scientist.

About

Financial News Sentiment Analysis for Stock Prediction

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors