This project is a comprehensive stock market prediction application that combines Deep Learning (LSTM) for technical analysis with Large Language Models (GPT via OpenRouter) for fundamental news sentiment analysis. It provides multi-timeframe forecasts (7-day, 30-day, 6-month) and actionable investment recommendations.
- Dual-Engine Analysis:
- Technical: LSTM (Long Short-Term Memory) neural networks trained on historical price data.
- Fundamental: AI-powered sentiment analysis of real-time news articles using GPT-3.5/4.
- Multi-Timeframe Predictions: Short-term (7 days), medium-term (30 days), and long-term (6 months).
- Consolidated Insights: Combines technical and fundamental signals into a weighted final prediction with confidence scores.
- Interactive Dashboards:
- Streamlit UI: A data-science focused dashboard with detailed charts and metrics.
- Flask UI: A modern web interface for easy access.
- Comprehensive Reporting: Detailed breakdown of market trends, sector performance, volatility events, and buy/sell signals.
-
Clone the repository (if applicable) or navigate to the project directory.
-
Install dependencies:
pip install -r requirements.txt
-
Set up Environment Variables: Create a
.envfile in the root directory with your API keys:OPENROUTER_API_KEY=your_openrouter_api_key NEWSORG_API_KEY=your_newsapi_key STOCK_API_BASE_URL=http://127.0.0.1:8000
Note: You can get a free NewsAPI key from newsapi.org.
You can run the application in three ways depending on your preference:
This provides the most detailed visualization and control.
- Start the integrated API server:
python Models/integrated_api.py
- In a separate terminal, launch the Streamlit app:
streamlit run streamlit_ui.py
- Open your browser at
http://localhost:8501.
A simplified web interface.
- Start the Flask server:
python flask_app.py
- Open your browser at
http://localhost:5000.
Run a quick analysis directly in your terminal.
- Run the master predictor:
python master_predictor.py
- Enter the stock symbol (e.g.,
RELIANCE.NS,TCS.NS) when prompted.
-
Data Ingestion:
- Fetches historical stock candle data via the internal API.
- Retrieves the latest news articles for the target company via NewsAPI.
-
Technical Analysis (LSTM Pipeline):
- Preprocesses data with dynamic lookback windows.
- Trains a custom LSTM neural network on multiple timeframes (Daily, Weekly, Monthly).
- Generates future price sequences for 7, 30, and 180 days.
-
Fundamental Analysis (News Pipeline):
- Sentiment Analysis: Evaluates news articles for positive/negative sentiment, weighted by recency.
- Market Context: Analyzes broader sector trends and market conditions.
- Event Detection: Identifies catalysts like earnings, mergers, or regulatory changes.
- LLM Processing: Uses OpenRouter (GPT) to synthesize this information into quantitative impact scores.
-
Ensemble Prediction:
- Combines the LSTM price targets with the News Sentiment impact.
- Applies weighting (default: 50% Technical / 50% Fundamental) to calculate the final target price.
- Calculates a Confidence Score based on the agreement between the two models.
-
Output:
- Generates a final recommendation: STRONG BUY, BUY, HOLD, SELL, or STRONG SELL.
- Visualizes the predicted price path and key metrics.
flask_app.py: Main entry point for the Flask web application.streamlit_ui.py: Main entry point for the Streamlit dashboard.master_predictor.py: CLI orchestration script.Models/: Contains the core logic.stock_prediction.py: LSTM model implementation.news.py: News fetching and LLM analysis logic.integrated_api.py: FastAPI backend for the Streamlit app.
Api/: Internal data API (likely for raw stock data).
This tool is for educational purposes only. Always conduct your own research before making investment decisions.