A Python tool that analyzes investment sentiment for S&P 500 stocks using web scraping and AI-powered analysis.
- Validates stock symbols against S&P 500 company list
- Performs targeted Google searches for recent stock analysis articles
- Scrapes and processes article content while filtering out ads and irrelevant content
- Uses OpenAI's GPT model to generate investment sentiment analysis
- Provides clear Buy/Sell/Hold recommendations with supporting rationale
- Python 3.6+
- OpenAI API key set in environment variables
- Required Python packages:
requestsbeautifulsoup4googlesearch-pythonopenaitiktoken
- Clone this repository
- Install required packages:
pip install requests beautifulsoup4 googlesearch-python openai tiktoken
- Run the program
- Enter a valid S&P 500 stock symbol when prompted
- Wait for the analysis to complete
- Review the AI-generated sentiment analysis and investment recommendation
validate()checks if the input symbol exists in S&P 500scan()performs Google searches for recent stock analysisscrape()extracts relevant content from search resultssentiment()uses GPT to analyze the aggregated content- Results are presented with specific reasons for the recommendation
project.py- Main program logicstocks.csv- S&P 500 company databasetest_project.py- Unit testsURLs.txt- Cached search results
Run the test suite:
pytest test_project.py- Depends on Google search results availability
- Requires active internet connection
- Analysis quality depends on OpenAI API availability
- Limited to S&P 500 stocks only