Skip to content

FakeJenton/Stock-Analyzing-Tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Stock Analyzer

A comprehensive stock analysis tool that combines historical performance analysis with news sentiment to recommend potentially profitable stocks.

🌐 Now with Interactive Web Dashboard! - Share your stock analysis with anyone via a beautiful web interface.

Features

  • 🌐 Interactive Web Dashboard:

    • Beautiful, user-friendly interface
    • Interactive charts and visualizations
    • Real-time stock analysis
    • Mobile-friendly design
    • Deploy to the web for free (Streamlit Cloud)
    • Share with anyone - no installation required
  • πŸ” Stock Screener & Discovery:

    • Automatically discover top performing stocks
    • 60+ curated stocks across 8 sectors
    • Preset lists: Top 10, Tech Giants, FAANG+, Finance, and more
    • No need to know which stocks to analyze - the tool finds them for you
    • Customizable screening criteria
  • Historical Performance Analysis: Analyzes stock performance using technical indicators including:

    • Moving averages (20, 50, 200-day)
    • Relative Strength Index (RSI)
    • Price momentum and returns
    • Volatility metrics
  • News Sentiment Analysis: Fetches and analyzes recent news articles to gauge market sentiment:

    • Alpha Vantage (recommended): Pre-calculated sentiment scores with bullish/bearish indicators
    • News API: Real-time news with TextBlob sentiment analysis
    • Aggregated sentiment metrics across multiple sources
  • Smart Recommendations: Combines both analyses to provide actionable stock recommendations:

    • Weighted scoring system
    • Multiple recommendation levels (Strong Buy, Buy, Hold, Watch, Avoid)
    • Detailed explanations for each recommendation

Installation

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)

Setup

  1. Clone the repository:
git clone <your-repo-url>
cd First-Project
  1. Install required packages:
pip install -r requirements.txt
  1. Download TextBlob corpora (optional, only needed if using News API):
python -m textblob.download_corpora
  1. Configure API keys:
cp .env.example .env

Edit .env and add your API key(s):

Option 1: Alpha Vantage (Recommended)

ALPHA_VANTAGE_API_KEY=your_actual_api_key_here
DATA_SOURCE=alpha_vantage

Get a free Alpha Vantage API key: Sign up at https://www.alphavantage.co/support/#api-key

Alpha Vantage provides:

  • Historical stock data
  • Pre-calculated news sentiment (bullish/bearish indicators)
  • All-in-one solution with one API key

Option 2: yfinance + News API

DATA_SOURCE=yfinance
NEWS_API_KEY=your_actual_api_key_here

Get a free News API key: Sign up at https://newsapi.org/

Usage

🌐 Web Dashboard (Recommended)

Launch the interactive web dashboard:

streamlit run app.py

The dashboard will open in your browser at http://localhost:8501

Features:

  • πŸ“Š Interactive stock selection
  • πŸ“ˆ Real-time analysis with progress tracking
  • 🎨 Beautiful visualizations and charts
  • πŸ“± Mobile-friendly interface
  • πŸš€ Easy to share and deploy

Deploy to the web for free: See DEPLOYMENT.md for instructions on deploying to Streamlit Cloud and sharing with others.

πŸ’» Command Line Interface

Basic Usage - Analyze default stocks (AAPL, GOOGL, MSFT, TSLA, AMZN):

python main.py

Analyze Specific Stocks - Provide stock symbols as command-line arguments:

python main.py AAPL MSFT NVDA

Analyze Multiple Stocks:

python main.py AAPL GOOGL MSFT AMZN TSLA META NVDA

Configuration

Edit .env file to customize:

# Alpha Vantage API Key (recommended)
ALPHA_VANTAGE_API_KEY=your_api_key_here

# News API Key (optional, if using yfinance)
NEWS_API_KEY=your_api_key_here

# Data source: 'alpha_vantage' or 'yfinance'
DATA_SOURCE=alpha_vantage

# Default stocks to analyze
DEFAULT_STOCKS=AAPL,GOOGL,MSFT,TSLA,AMZN

# Number of days of historical data to analyze
HISTORICAL_DAYS=90

# Number of days back to fetch news articles
NEWS_DAYS_BACK=7

# Minimum sentiment score threshold
MIN_SENTIMENT_SCORE=0.1

How It Works

1. Data Collection

  • Alpha Vantage mode: Fetches historical stock prices and news with sentiment from Alpha Vantage
  • yfinance mode: Fetches historical stock prices using yfinance and news from News API

2. Performance Analysis

The tool calculates:

  • Returns: 7-day, 14-day, 30-day, and total returns
  • Moving Averages: 20, 50, and 200-day MAs
  • RSI: Relative Strength Index to identify overbought/oversold conditions
  • Momentum Score: Composite score based on multiple technical indicators

3. Sentiment Analysis

  • Analyzes news article headlines and descriptions
  • Uses TextBlob for natural language processing
  • Calculates polarity scores (negative to positive)
  • Aggregates sentiment across multiple articles

4. Recommendation Engine

  • Combines performance score (60% weight) and sentiment score (40% weight)
  • Generates overall recommendation score (0-100)
  • Provides recommendation levels:
    • Strong Buy (80-100): High potential
    • Buy (70-79): Good potential
    • Hold/Consider (60-69): Moderate potential
    • Hold (50-59): Neutral
    • Watch (40-49): Low potential
    • Avoid (0-39): Poor outlook

Output Example

================================================================================
           STOCK RECOMMENDATIONS
================================================================================

+--------+--------+----------------+--------+-----------+------------+-------+
| Symbol | Price  | Recommendation | Score  | 7d Return | 30d Return | News  |
+========+========+================+========+===========+============+=======+
| NVDA   | $495.50| Strong Buy     | 85.3   | +5.20%    | +12.40%    | 18    |
+--------+--------+----------------+--------+-----------+------------+-------+
| MSFT   | $378.90| Buy            | 72.1   | +2.10%    | +8.30%     | 15    |
+--------+--------+----------------+--------+-----------+------------+-------+
| AAPL   | $182.30| Hold/Consider  | 65.5   | +1.50%    | +4.20%     | 20    |
+--------+--------+----------------+--------+-----------+------------+-------+

Project Structure

First-Project/
β”œβ”€β”€ app.py                       # 🌐 Web dashboard (Streamlit)
β”œβ”€β”€ main.py                      # CLI application entry point
β”œβ”€β”€ requirements.txt             # Python dependencies
β”œβ”€β”€ .env.example                 # Environment variables template
β”œβ”€β”€ .env                         # Your configuration (create this)
β”œβ”€β”€ README.md                    # This file
β”œβ”€β”€ DEPLOYMENT.md                # Web deployment guide
β”œβ”€β”€ runtime.txt                  # Python version for deployment
β”œβ”€β”€ packages.txt                 # System packages for deployment
β”œβ”€β”€ .streamlit/
β”‚   β”œβ”€β”€ config.toml              # Streamlit configuration
β”‚   └── secrets.toml.example     # Secrets template for deployment
└── src/
    β”œβ”€β”€ stock_fetcher.py         # Fetches historical stock data (yfinance)
    β”œβ”€β”€ news_fetcher.py          # Fetches news articles (News API)
    β”œβ”€β”€ alpha_vantage_fetcher.py # Fetches stock data (Alpha Vantage)
    β”œβ”€β”€ alpha_vantage_news.py    # Fetches news with sentiment (Alpha Vantage)
    β”œβ”€β”€ performance_analyzer.py  # Analyzes stock performance
    β”œβ”€β”€ sentiment_analyzer.py    # Analyzes news sentiment
    └── recommender.py           # Generates recommendations

Technical Details

Dependencies

  • alpha-vantage: Alpha Vantage API client for stock data and news sentiment
  • yfinance: Yahoo Finance API wrapper for stock data (alternative source)
  • pandas/numpy: Data manipulation and analysis
  • newsapi-python: News API client (alternative source)
  • textblob: Natural language processing for sentiment analysis (used with News API)
  • colorama: Terminal color output
  • tabulate: Formatted table display
  • requests: HTTP library for API calls

Scoring Algorithm

Performance Score (0-100):

  • Base score: 50 (neutral)
  • Positive recent returns: +points
  • Price above moving averages: +points
  • Optimal RSI range (40-60): +points
  • Oversold (RSI < 30): +points (reversal potential)
  • Overbought (RSI > 70): -points

Sentiment Score (0-100):

  • Based on average news article polarity
  • Boosted by high positive article ratio
  • Reduced by high negative article ratio

Combined Score:

  • 60% Performance + 40% Sentiment
  • Normalized to 0-100 scale

Limitations and Disclaimers

⚠️ Important: This tool is for educational and informational purposes only.

  • Not Financial Advice: Recommendations are algorithmic and should not be considered professional financial advice
  • No Guarantees: Past performance does not guarantee future results
  • Market Risk: All investments carry risk
  • Data Limitations: Analysis quality depends on data availability and accuracy
  • API Limits: News API has rate limits on free tier
  • Do Your Research: Always conduct thorough research before making investment decisions
  • Consult Professionals: Consider consulting with a licensed financial advisor

Troubleshooting

Alpha Vantage rate limits

  • Free tier: 5 API calls per minute, 500 calls per day
  • The tool automatically waits 12 seconds between requests to respect rate limits
  • For analyzing 5 stocks, expect ~2 minutes (5 stocks Γ— 2 API calls Γ— 12 seconds)
  • Consider upgrading to a paid plan for faster analysis

No news data appearing

  • Alpha Vantage: Verify your API key is correct in .env
  • News API: Verify your API key and check rate limits (free tier: 100 requests/day)
  • Ensure internet connection is active
  • Check API rate limits haven't been exceeded

Stock data not loading

  • Verify stock symbols are correct
  • Check internet connection
  • Some stocks may not have sufficient historical data
  • If using Alpha Vantage, wait for rate limit delays (normal behavior)

TextBlob errors

  • Only needed if using News API mode
  • Run: python -m textblob.download_corpora

Switching between data sources

  • Edit .env and change DATA_SOURCE=alpha_vantage or DATA_SOURCE=yfinance
  • Alpha Vantage is slower but provides better sentiment data
  • yfinance is faster but requires separate News API key

Future Enhancements

Potential improvements:

  • Add more technical indicators (MACD, Bollinger Bands)
  • Implement machine learning predictions
  • Add portfolio optimization
  • Create web dashboard
  • Support for cryptocurrencies
  • Real-time price alerts
  • Backtesting capabilities

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

This project is open source and available for educational purposes.

Acknowledgments

  • Yahoo Finance for stock data (via yfinance)
  • News API for news articles
  • TextBlob for sentiment analysis

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages