diff --git a/Stock prediction b/Stock prediction new file mode 100644 index 00000000..15a7ccc8 --- /dev/null +++ b/Stock prediction @@ -0,0 +1,333 @@ +import { Card } from "@/components/ui/card"; +import { TrendingUp, TrendingDown, Target } from "lucide-react"; + +interface PredictionStats { + currentPrice: number; + predictedPrice: number; + confidence: number; + change: number; + changePercent: number; +} + +interface StockPredictionCardProps { + stats: PredictionStats; + ticker: string; + companyName?: string; +} + +export const StockPredictionCard = ({ stats, ticker, companyName }: StockPredictionCardProps) => { + const isPositive = stats.change >= 0; + + return ( + +
+
+
+

{ticker.toUpperCase()}

+ {companyName && ( +

{companyName}

+ )} +
+
+ {isPositive ? ( + + ) : ( + + )} + + {isPositive ? '+' : ''}{stats.changePercent.toFixed(2)}% + +
+
+ +
+
+

Current Price

+

${stats.currentPrice.toFixed(2)}

+
+
+

30-Day Prediction

+

${stats.predictedPrice.toFixed(2)}

+
+
+ +
+
+ + Confidence: + {stats.confidence}% +
+
+ Expected Change: + + ${Math.abs(stats.change).toFixed(2)} + +
+
+
+
+ ); +}; +import { useState } from "react"; +import { Button } from "@/components/ui/button"; +import { Input } from "@/components/ui/input"; +import { Card } from "@/components/ui/card"; +import { Badge } from "@/components/ui/badge"; +import { StockChart } from "@/components/StockChart"; +import { StockPredictionCard } from "@/components/StockPredictionCard"; +import { generateMockStockData, popularTickers } from "@/utils/mockData"; +import { TrendingUp, BarChart3, Activity, Sparkles } from "lucide-react"; +import { useToast } from "@/hooks/use-toast"; + +const Index = () => { + const [ticker, setTicker] = useState(""); + const [isLoading, setIsLoading] = useState(false); + const [stockData, setStockData] = useState(null); + const { toast } = useToast(); + + const handlePredict = async () => { + if (!ticker.trim()) { + toast({ + title: "Error", + description: "Please enter a stock ticker symbol", + variant: "destructive", + }); + return; + } + + setIsLoading(true); + + // Simulate API call delay + setTimeout(() => { + const data = generateMockStockData(ticker); + setStockData(data); + setIsLoading(false); + + toast({ + title: "Prediction Complete", + description: `Generated 30-day forecast for ${ticker.toUpperCase()}`, + }); + }, 2000); + }; + + const handleTickerClick = (selectedTicker: string) => { + setTicker(selectedTicker); + }; + + return ( +
+ {/* Hero Section */} +
+ {/* Background gradient */} +
+ +
+
+
+ + AI-Powered +
+ +

+ Stock Price +
+ Predictor +

+ +

+ Get AI-powered stock price predictions with interactive charts and confidence intervals. + Enter any ticker symbol and see the future unfold. +

+
+ + {/* Prediction Input */} + +
+
+ +

Make a Prediction

+
+ +
+ setTicker(e.target.value.toUpperCase())} + className="flex-1 text-lg bg-input border-border focus:ring-primary" + onKeyPress={(e) => e.key === 'Enter' && handlePredict()} + /> + +
+ + {/* Popular Tickers */} +
+

Popular stocks:

+
+ {popularTickers.map((popularTicker) => ( + handleTickerClick(popularTicker)} + > + {popularTicker} + + ))} +
+
+
+
+
+
+ + {/* Results Section */} + {stockData && ( +
+
+ {/* Prediction Stats */} +
+ +
+ + {/* Chart */} + + + + + {/* Disclaimer */} + +
+ +
+

Investment Disclaimer

+

+ This prediction is for educational purposes only and should not be used as financial advice. + Stock prices are volatile and predictions may not reflect actual market performance. + Always consult with a financial advisor before making investment decisions. +

+
+
+
+
+
+ )} +
+ ); +}; + +export default Index; +export const generateMockStockData = (ticker: string) => { + const today = new Date(); + const dates: string[] = []; + const historicalPrices: number[] = []; + const predictedPrices: number[] = []; + + // Base price varies by ticker + const basePrices: { [key: string]: number } = { + 'AAPL': 175, + 'TSLA': 240, + 'GOOGL': 135, + 'MSFT': 420, + 'AMZN': 145, + 'NVDA': 450, + 'META': 320, + 'NFLX': 485, + }; + + // Company names mapping + const companyNames: { [key: string]: string } = { + 'AAPL': 'Apple Inc.', + 'TSLA': 'Tesla, Inc.', + 'GOOGL': 'Alphabet Inc.', + 'MSFT': 'Microsoft Corporation', + 'AMZN': 'Amazon.com, Inc.', + 'NVDA': 'NVIDIA Corporation', + 'META': 'Meta Platforms, Inc.', + 'NFLX': 'Netflix, Inc.', + }; + + let basePrice = basePrices[ticker.toUpperCase()] || 100; + + // Generate 60 days of historical data + for (let i = 59; i >= 0; i--) { + const date = new Date(today); + date.setDate(date.getDate() - i); + dates.push(date.toLocaleDateString()); + + // Add some realistic price movement + const volatility = 0.03; // 3% daily volatility + const randomChange = (Math.random() - 0.5) * 2 * volatility; + basePrice *= (1 + randomChange); + + historicalPrices.push(basePrice); + predictedPrices.push(null as any); // No predictions for historical data + } + + // Generate 30 days of predicted data + let predictedBasePrice = basePrice; + const trend = Math.random() > 0.5 ? 1.002 : 0.998; // Slight upward or downward trend + + for (let i = 1; i <= 30; i++) { + const date = new Date(today); + date.setDate(date.getDate() + i); + dates.push(date.toLocaleDateString()); + + // Add trend and some randomness to predictions + const volatility = 0.02; // Slightly less volatile for predictions + const randomChange = (Math.random() - 0.5) * 2 * volatility; + predictedBasePrice *= trend * (1 + randomChange); + + historicalPrices.push(null as any); // No historical data for future dates + predictedPrices.push(predictedBasePrice); + } + + return { + dates, + historicalPrices, + predictedPrices, + currentPrice: basePrice, + predictedPrice: predictedBasePrice, + change: predictedBasePrice - basePrice, + changePercent: ((predictedBasePrice - basePrice) / basePrice) * 100, + confidence: Math.floor(Math.random() * 20) + 75, // 75-95% confidence + companyName: companyNames[ticker.toUpperCase()] || `${ticker.toUpperCase()} Corp.`, + }; +}; + +export const popularTickers = [ + 'AAPL', 'TSLA', 'GOOGL', 'MSFT', 'AMZN', 'NVDA', 'META', 'NFLX' +];