Skip to main content

Financial news sentiment analysis using LSTM

Project description

fin-sentiment

Financial News Sentiment Analysis using LSTM

fin-sentiment is a Python package that analyzes the sentiment of financial news headlines using an LSTM-based deep learning model. It helps traders, investors, and analysts gauge market sentiment by classifying news as positive, neutral, or negative.


Features

  • 📰 Fetch latest financial news for any company
  • 🤖 LSTM-based sentiment classification
  • 📊 Aggregate sentiment analysis across multiple headlines
  • ⚡ Simple, intuitive API
  • 🎯 Trained on real financial news data

Installation

pip install fin-sentiment

Quick Start

from fin_sentiment.news_fetcher import fetch_company_news
from fin_sentiment.analyzer import SentimentAnalyzer

# Step 1: Fetch latest news for a company
news = fetch_company_news("TCS", limit=10)

# Step 2: Initialize sentiment analyzer
analyzer = SentimentAnalyzer()

# Step 3: Analyze each news headline
for article in news:
    sentiment = analyzer.analyze(article["title"])
    print(f"{article['title']}{sentiment}")

# Step 4: Get overall market sentiment
overall = analyzer.overall_sentiment(news)
print(f"Market Mood: {overall}")

# Step 5: Analyze a custom headline
custom_sentiment = analyzer.analyze("Stock prices surged after positive earnings report")
print(custom_sentiment)  # Output: positive

API Reference

Module: fin_sentiment.news_fetcher

fetch_company_news(company_name: str, limit: int = 10) -> list

Fetches the latest news headlines for a specified company from financial sources.

Parameters:

  • company_name (str): Name of the company to fetch news for
  • limit (int): Maximum number of headlines to retrieve (default: 10)

Returns: List of news articles with titles and metadata

Example:

news = fetch_company_news("Infosys", limit=5)

Module: fin_sentiment.analyzer

SentimentAnalyzer()

Initializes the LSTM-based sentiment analysis model.

Example:

analyzer = SentimentAnalyzer()

.analyze(text: str) -> str

Analyzes the sentiment of a single text string.

Parameters:

  • text (str): The headline or text to analyze

Returns: Sentiment label: "positive", "neutral", or "negative"

Example:

sentiment = analyzer.analyze("Company shares hit record high")
print(sentiment)  # Output: positive

.overall_sentiment(news_list: list) -> str

Aggregates sentiment across multiple news headlines to determine overall market mood.

Parameters:

  • news_list (list): List of news articles (with "title" key)

Returns: Overall sentiment: "positive", "neutral", or "negative"

Example:

overall = analyzer.overall_sentiment(news)
print(overall)  # Output: neutral

Example Output

TCS shares rise 5% after strong Q3 results → positive
TCS faces data breach allegations → negative
TCS announces dividend payout → positive
Market closes flat amid mixed signals → neutral

Market Mood: neutral

Model Details

Property Details
Architecture LSTM (Long Short-Term Memory)
Framework PyTorch
Dataset Financial headlines from multiple market sources
Classes Positive, Neutral, Negative
Output Softmax probability distribution → final label

Use Cases

  • 📈 Trading Signals: Gauge market sentiment before making trades
  • 📰 News Monitoring: Track sentiment trends for specific companies
  • 🤖 Automated Analysis: Integrate sentiment into trading bots
  • 📊 Market Research: Analyze sentiment patterns over time

Requirements

  • Python 3.7+
  • PyTorch
  • NumPy
  • Requests (for news fetching)
  • Feedparser

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fin_sentiment-0.1.4.tar.gz (64.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fin_sentiment-0.1.4-py3-none-any.whl (64.4 MB view details)

Uploaded Python 3

File details

Details for the file fin_sentiment-0.1.4.tar.gz.

File metadata

  • Download URL: fin_sentiment-0.1.4.tar.gz
  • Upload date:
  • Size: 64.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for fin_sentiment-0.1.4.tar.gz
Algorithm Hash digest
SHA256 bb4903b6419ec69fef366e37b57dd8c68174f0911970825c852bf31426cc89e1
MD5 0327e03162f444f62d64933aeaef1d11
BLAKE2b-256 723ef175ec1ba476e2c93857948e3810e5765e8598a960dad13a23f7bc57a5ab

See more details on using hashes here.

File details

Details for the file fin_sentiment-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: fin_sentiment-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 64.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for fin_sentiment-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9477396b6c2c83bdc3d4549c6f5bea6a98254368a2ab5143943a014da6af5226
MD5 a8a82fda6c0458003eccf0f64cc4dba7
BLAKE2b-256 4da43fd1a873e9fc1ecfac5c2f6bc68e389a96f0191fd4dc9f7b889c024fd6fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page