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.
-
π 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
- Python 3.8 or higher
- pip (Python package manager)
- Clone the repository:
git clone <your-repo-url>
cd First-Project- Install required packages:
pip install -r requirements.txt- Download TextBlob corpora (optional, only needed if using News API):
python -m textblob.download_corpora- Configure API keys:
cp .env.example .envEdit .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/
Launch the interactive web dashboard:
streamlit run app.pyThe 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.
Basic Usage - Analyze default stocks (AAPL, GOOGL, MSFT, TSLA, AMZN):
python main.pyAnalyze Specific Stocks - Provide stock symbols as command-line arguments:
python main.py AAPL MSFT NVDAAnalyze Multiple Stocks:
python main.py AAPL GOOGL MSFT AMZN TSLA META NVDAEdit .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- Alpha Vantage mode: Fetches historical stock prices and news with sentiment from Alpha Vantage
- yfinance mode: Fetches historical stock prices using
yfinanceand news from News API
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
- Analyzes news article headlines and descriptions
- Uses TextBlob for natural language processing
- Calculates polarity scores (negative to positive)
- Aggregates sentiment across multiple articles
- 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
================================================================================
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 |
+--------+--------+----------------+--------+-----------+------------+-------+
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
- 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
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
- 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
- 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
- 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
- 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)
- Only needed if using News API mode
- Run:
python -m textblob.download_corpora
- Edit
.envand changeDATA_SOURCE=alpha_vantageorDATA_SOURCE=yfinance - Alpha Vantage is slower but provides better sentiment data
- yfinance is faster but requires separate News API key
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
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is open source and available for educational purposes.
- Yahoo Finance for stock data (via yfinance)
- News API for news articles
- TextBlob for sentiment analysis