Feature: AI Stock Rating
Relevant source files
The following files were used as context for generating this wiki page:
The Greenline application provides users with a suite of AI-driven insights to analyze stocks. The core of this is the "Rating Analysis" feature, which presents a consolidated rating score and detailed metrics for a given stock ticker. This rating is sourced from an external data provider and visualized in a dedicated component.
This primary rating feature is complemented by other AI-powered tools integrated into the stock analysis page, including an AI-Generated Critical Summary, an Interactive Ticker Chat, and a Price Forecasting model. Together, these features provide a multi-faceted, AI-enhanced view of a stock's performance and potential.
Stock Rating Component
The StockRating component is the primary UI for displaying the rating analysis. It fetches, processes, and visualizes rating data from an external API.
Sources: client/src/components/StockRating/index.tsx, client/src/app/quote/[ticker]/page.tsx:13, 119
Data Fetching and State Management
When the component mounts, it triggers an asynchronous fetchRating function inside a useEffect hook. This function sends a GET request to the Financial Modeling Prep API to retrieve rating data for the specified stock ticker. The component manages the request's lifecycle through loading, error, and ratingData state variables.
Sources: client/src/components/StockRating/index.tsx:39-58
The following diagram illustrates the data fetching sequence.
Data Structure
The data received from the API is stored in the ratingData state, which conforms to the RatingData interface. This structure contains an overall score and recommendation, as well as detailed scores for six individual financial metrics.
Sources: client/src/components/StockRating/index.tsx:16-34
The table below details the key fields in the RatingData interface.
| Field | Type | Description |
|---|---|---|
symbol | string | The stock ticker symbol. |
date | string | The date of the rating. |
rating | string | The overall rating (e.g., "A", "B"). |
ratingScore | number | The overall numeric score (1-5). |
ratingRecommendation | string | The overall recommendation (e.g., "Strong Buy"). |
ratingDetailsDCFScore | number | Discounted Cash Flow score. |
ratingDetailsDCFRecommendation | string | DCF recommendation. |
ratingDetailsROEScore | number | Return on Equity score. |
ratingDetailsROERecommendation | string | ROE recommendation. |
ratingDetailsROAScore | number | Return on Assets score. |
ratingDetailsROARecommendation | string | ROA recommendation. |
ratingDetailsDEScore | number | Debt to Equity score. |
ratingDetailsDERecommendation | string | DE recommendation. |
ratingDetailsPEScore | number | Price to Earnings score. |
ratingDetailsPERecommendation | string | PE recommendation. |
ratingDetailsPBScore | number | Price to Book score. |
ratingDetailsPBRecommendation | string | PB recommendation. |
Sources: client/src/components/StockRating/index.tsx:16-34
UI and Visualization
The component uses several visual elements to present the analysis clearly.
- Overall Rating: The main score and recommendation are displayed prominently, with colors dynamically applied by the
getScoreColorandgetRecommendationColorfunctions based on the values.
Sources: client/src/components/StockRating/index.tsx:60-79, 178-186 - Recommendation Breakdown: A circular chart visualizes the percentage of "Buy" recommendations among the six detailed metrics. This is calculated by the
getRecommendationCountsfunction.
Sources: client/src/components/StockRating/index.tsx:118-138, 188-200 - Progress Bars: Horizontal progress bars show the percentage breakdown of "Buy", "Hold", and "Sell" recommendations across all metrics.
Sources: client/src/components/StockRating/index.tsx:202-233 - Detailed Metrics Table: A table lists each of the six financial metrics (DCF, ROE, etc.), its score out of 5, and its specific recommendation.
Sources: client/src/components/StockRating/index.tsx:168-176, 239-261
Related AI-Powered Features
The application integrates other AI/ML capabilities to provide a holistic analytical experience alongside the core rating feature.
AI-Generated Critical Summary
The StockSummary component identifies significant daily price changes (greater than 2%) over the past six months and uses the OpenAI API (gpt-3.5-turbo) to generate a concise explanation for each event.
Sources: client/src/components/StockSummary/index.tsx
The process for generating the summary is as follows:
Interactive Ticker Chat
The TickerChat component provides a conversational interface for users to "chat" with a stock ticker. It uses the OpenAI API (gpt-4o-mini) to generate responses. The model is primed with a system message to respond as if it were the stock ticker itself.
Sources: client/src/components/TickerChat/index.tsx
The interaction flow is shown below.
Price Forecasting
The StockChart component includes a "Forecast" feature that predicts future stock prices. When activated, it sends the historical price data to a local backend service.
Sources: client/src/components/StockChart/index.tsx
The forecasting process is as follows:
- The user clicks the "Forecast" button.
- The
getForecastfunction is called, setting theisForecastingstate to true. - A
POSTrequest is made tohttp://localhost:8000/forecast/with the historical price data and a forecast horizon of 5 days. - The backend service returns a JSON response containing forecasted dates, prices, and confidence intervals.
- The component combines the historical and forecasted data, sorts it by date, and updates its state to re-render the chart with the forecast.
Sources: client/src/components/StockChart/index.tsx:118-144
Integration
All AI-related components—StockRating, StockSummary, TickerChat, and StockChart—are integrated into the main stock quote page, located at /app/quote/[ticker]/page.tsx. This page serves as the central hub for a user to perform a deep analysis of a specific stock.
Sources: client/src/app/quote/[ticker]/page.tsx
The following diagram shows the component hierarchy on the stock quote page.
Conclusion
The AI Stock Rating feature is a central part of the Greenline application's analytical toolkit. While the StockRating component provides a structured, data-driven rating from an external source, it is enhanced by a suite of other AI tools. These include generative AI for creating narrative summaries (StockSummary) and enabling interactive conversations (TickerChat), as well as predictive modeling for price forecasting (StockChart). This combination of features provides users with a comprehensive and modern approach to stock analysis.