NLPStock is a comprehensive tool that analyzes news articles to explain stock price movements. It fetches financial news from various sources, processes the text using Natural Language Processing (NLP) techniques, and generates explanations for why stocks are moving up or down.
- Multi-Source News Fetching: Collects news from US, European, Nordic, and Baltic sources
- Advanced NLP Processing: Extracts key sentences, named entities, and keywords from articles
- LLM-Powered Summarization: Uses Groq's LLama 3 model to generate insightful explanations
- Modular Architecture: Clean separation between data fetching, NLP processing, and summarization
NLPStock/ ├── data_fetchers/ # Fetch news from various sources ├── nlp_processing/ # Process news articles ├── summarization/ # Summarize news articles └── utils/ # Utility functions └── STOCK_DB/ # Stock data and news articles ├── run.py # Main entry point └── requirements.txt # Dependencies
-
Clone the repository: git clone https://github.com/evaks1/NLPStock.git cd NLPStock
-
Install dependencies: pip install -r requirements.txt
-
Create and activate virtual environment: python -m venv venv source venv/bin/activate # Linux/Mac venv\Scripts\activate # Windows
-
Create a
.envfile in the root directory with your API keys: GROQ_API_KEY=your_groq_api_key ALPHA_VANTAGE_API_KEY=your_alpha_vantage_api_key
-
Fetch news for a specific stock: python run.py --symbol AAPL --exchange US --change 1.5 --fetch-news
-
Fetch news for multiple stocks from a file: python run.py --symbols-file symbols.txt --exchanges-file exchanges.txt --fetch-news
-
Process all stocks in the database: python run.py --all
Where symbols.txt contains one symbol per line and exchanges.txt contains the corresponding exchanges.
--symbol: Stock symbol to analyze (e.g., AAPL, MSFT)--exchange: Stock exchange (default: US)--change: Daily change percentage (default: 0.01)--all: Process all stocks with news data--fetch-news: Fetch news before analysis--symbols-file: Path to a file containing symbols to fetch news for--exchanges-file: Path to a file containing exchanges for the symbols
For each stock, the script will:
- Fetch news articles
- Process the articles to extract key information
- Generate an explanation for the stock movement
- Save the results to the database
-
News Fetching: The system fetches recent news articles about the specified stock from various financial news sources.
-
Text Processing: Articles are processed using NLP techniques to:
- Extract key sentences relevant to stock movement
- Identify named entities (companies, people, locations)
- Extract important keywords and financial terms
-
Summarization: The processed text is sent to an LLM (Groq's LLama 3) which generates a concise explanation of why the stock is moving.
-
Classification: Based on the price change, the stock is classified as a "gainer" or "loser", and the summary is tailored accordingly.
- Python 3.8+
- NLTK
- spaCy
- Groq API access
- BeautifulSoup4
- Requests
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- NLTK for natural language processing
- spaCy for named entity recognition
- Groq for LLM API access
- BeautifulSoup for web scraping