diff --git a/src/routes/stocks/[tickerID]/forecast/+page.svelte b/src/routes/stocks/[tickerID]/forecast/+page.svelte index 119ad786..e5705555 100644 --- a/src/routes/stocks/[tickerID]/forecast/+page.svelte +++ b/src/routes/stocks/[tickerID]/forecast/+page.svelte @@ -14,6 +14,27 @@ let changeEBITDA = 0; let changeEPS = 0; + const price = data?.getStockQuote?.price?.toFixed(2) || 0; + + const calculatePriceChange = (targetPrice) => + targetPrice && price ? ((targetPrice / price - 1) * 100)?.toFixed(2) : 0; + + const numOfAnalyst = data?.getAnalystRating?.numOfAnalyst || 0; + const avgPriceTarget = data?.getAnalystRating?.avgPriceTarget || 0; + const medianPriceTarget = data?.getAnalystRating?.medianPriceTarget || 0; + const lowPriceTarget = data?.getAnalystRating?.lowPriceTarget || 0; + const highPriceTarget = data?.getAnalystRating?.highPriceTarget || 0; + const consensusRating = data?.getAnalystRating?.consensusRating; + + const lowChange = calculatePriceChange(lowPriceTarget); + const medianChange = calculatePriceChange(medianPriceTarget); + const avgChange = calculatePriceChange(avgPriceTarget); + const highChange = calculatePriceChange(highPriceTarget); + const rawAnalystList = data?.getAnalystRating?.recommendationList || []; + const recommendationList = + rawAnalystList?.length > 5 ? rawAnalystList?.slice(-6, -1) : rawAnalystList; + const categories = ["Strong Buy", "Buy", "Hold", "Sell", "Strong Sell"]; + function findIndex(data) { const currentYear = new Date().getFullYear(); @@ -35,6 +56,13 @@ return index; // Return the index or -1 if not found } + function getTotalForDate(index) { + return categories.reduce( + (sum, cat) => sum + recommendationList[index][cat], + 0, + ); + } + const calculateChange = (current, previous) => { if (previous !== undefined && previous !== 0) { const change = (Math.abs(current) / Math.abs(previous) - 1) * 100; @@ -115,24 +143,29 @@
- The 15 analysts with 12-month price forecasts for SMCI stock - have an average target of 74.53, with a low estimate of 32.5 - and a high estimate of 135. The average target predicts an - increase of 125.37% from the current stock price of 33.07. + The {numOfAnalyst} analysts with 12-month price forecasts for {$stockTicker} + stock have an median target of {medianPriceTarget}, with a low + estimate of {lowPriceTarget} + and a high estimate of {highPriceTarget}. The median target + predicts an increase of {medianChange}% from the current stock + price of {price}.