A Flask web application that analyzes recent Reddit discussions for a given stock symbol to gauge public sentiment. It fetches posts, performs sentiment analysis using NLP, filters for quality discussions, and visualizes the sentiment trend.
- Reddit Data Fetching: Retrieves recent posts mentioning a stock symbol from relevant subreddits (e.g., r/stocks, r/wallstreetbets, r/investing).
- Sentiment Analysis: Uses NLTK's VADER to calculate sentiment scores for fetched posts.
- Quality Filtering: Implements a scoring mechanism to filter out low-quality or irrelevant posts based on length, Reddit score, and sentiment intensity.
- Trend Visualization: Generates and displays a plot showing the daily average sentiment trend using Matplotlib.
- Web Interface: Provides a clean, responsive, dark-mode UI built with Flask, HTML, CSS, and JavaScript for easy interaction.
- Backend: Python, Flask
- Data Fetching: Praw (for Reddit API)
- NLP: NLTK (VADER for sentiment)
- Data Handling: Pandas
- Visualization: Matplotlib
- Frontend: HTML, CSS, JavaScript
-
Clone the repository (if you haven't already):
git clone <your-repository-url> cd stock # Navigate into the project directory
-
Create a virtual environment (recommended):
python -m venv venv # Activate it: # Windows: .\venv\Scripts\Activate.ps1 # macOS/Linux: # source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.env
file in the project root (stock/
) with your Reddit API credentials:REDDIT_CLIENT_ID=your_client_id REDDIT_CLIENT_SECRET=your_client_secret REDDIT_USER_AGENT=your_user_agent_string (e.g., MyStockAnalyzer/0.1 by u/YourUsername)
(You can get credentials by creating a 'script' app on Reddit: https://www.reddit.com/prefs/apps)
-
Navigate to the
src
directory:cd src
-
Run the Flask application:
flask run --host=0.0.0.0
(The
--host=0.0.0.0
makes it accessible on your local network; use127.0.0.1
or omit for local access only) -
Open your web browser and go to
http://127.0.0.1:5000
(or your machine's IP address if using0.0.0.0
). -
Enter a stock symbol (e.g., AAPL, TSLA, GME) and click "Analyze".
-
View the sentiment analysis results, trend plot, and top relevant posts.