Evaluates market sentiment of desired stocks using recent news articles.
Program by Tauria and Grace.
- The Big Idea
- Instructions
- Running the Web App
- Implementation
- Results
- Project Evolution
- Project Structure
- Attribution
- AI Assistance Statement
This project builds a web app that takes a stock ticker, pulls recent news articles from Yahoo Finance, and analyzes how positive or negative the overall market sentiment is. It also shows whether the stock price has been rising, falling, or staying flat over the past three months.
The main goal was to apply Python to real-world financial data and understand how the finance community reacts to news. Our product is a web app optimized for ease of use. The user enters a ticker, then gets a clear summary. This makes stock analysis more accessible to students, investors, or anyone curious about how news tone might relate to price trends.
You need:
- Python 3.9+
- pip
- An OpenAI API key
Everything else installs automatically.
git clone <your-repo-url>
cd <project-folder>
project/
│
├── app.py
├── analysis.py
├── requirements.txt
├── README.md
├── .env
│
├── templates/
│ ├── index.html
│ ├── result.html
│ └── error.html
│
└── static/
└── styles.css
macOS / Linux:
python3 -m venv venv
source venv/bin/activate
Windows:
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
This installs all of the necessary libraries.
Create a .env file in the root folder and input your OpenAI API key:
OPENAI_API_KEY=your_key_here
That’s the only key needed. HuggingFace and NLTK run locally.
Run this command in your terminal:
python app.py
This initiates the Flask server.
The app automatically checks for the VADER sentiment lexicon when it runs. You may see an error such as:
LookupError: Resource vader_lexicon not found
If you do, run the following command once:
python -c "import nltk; nltk.download('vader_lexicon')"
This installs the NLTK data used by the VADER sentiment model.
Once the server launches, open your browser at: http://127.0.0.1:5000
- Enter a stock ticker
- Click Analyze
- View results
- Click Search another stock to run again
Below is the general flow the app follows:
The home page shows a form where the user types in a stock ticker. After they submit it, the program uses that ticker to start the analysis.
The app uses yfinance to download the last three months of closing prices.
It compares the first and last prices to decide whether the stock has been rising, falling, or stagnant during that period.
The app sends a request to the Yahoo Finance Search API to get recent news articles related to the ticker. The app analyzes five of the most recent articles returned by the Yahoo Finance Search API.
The app downloads and reads the full text of each article using newspaper3k.
If it cannot get the full text, it uses the article title instead.
Each article is analyzed using three different tools:
- HuggingFace transformer
- OpenAI model
- NLTK VADER
Each tool gives a score between –1 and 1, representing negative to positive sentiment.
-
HuggingFace model:
The article text is split into 400-character chunks. Each chunk is analyzed separately, and the scores are averaged to produce a final HuggingFace sentiment score. -
OpenAI model:
Only the first 4000 characters of each article are sent to the model. This prevents exceeding token limits and ensures consistent JSON output. -
NLTK VADER:
VADER processes the full text when it is available.
These constraints ensure each model runs reliably without exceeding length or token limits.
The app averages the three scores for each article to assign a final label (Positive, Neutral, or Negative).
Then, it averages all article scores to generate the overall sentiment for the entire stock.
The final sentiment label uses the following thresholds:
- Positive if the combined score is greater than +0.2
- Negative if the combined score is less than -0.2
- Neutral otherwise
The program shows a summary of the stock’s recent news sentiment. At the top of the results page, the 3-month price trend and the overall sentiment score across all models are displayed.
Below that, the app lists five recent news articles pulled from Yahoo Finance. Each article card shows the title, its link, and a combined sentiment score for that article. If the user wants more detail, they can click “More details” to expand a small section that displays the individual scores from HuggingFace, OpenAI, and VADER. If desired, the user can click the “Search another stock” button to be taken back to the input page.
This project underwent a series of major changes during its development. Initially, it only pulled article headlines and ran one sentiment model. During testing, it became clear that using headlines alone was too limited, so full article text extraction was added.
Once the sentiment analysis worked, the project was expanded to include price-trend data to give more context behind the news. At that point, two additional models (HuggingFace and VADER) were added to give a more balanced output and explore the differences between analysis tools.
Next was the user interface. The early version of the interface was plain, and several rounds of layout adjustments were made to make the information easier to read. Originally, only the overall sentiment was going to be displayed, but both the per article scores and individual model scores were included for transparency and user understanding. Small visual improvements were made throughout, including matching styles between pages and reorganizing how the results are presented.
The project uses:
yfinanceto get stock data- Yahoo Finance public search API to find news articles
newspaper3kto extract article text- Three sentiment analysis models:
- HuggingFace
transformers nltkVADERopenaiAPI
- HuggingFace
flaskto run the web app
All libraries are open source.
ChatGPT was used during the project, mainly for:
- Formatting the UI, such as refining the CSS and HTML templates
- Debugging the code
- Guiding web app design decisions to improve the user experience

