import { useState, useMemo } from 'react'; import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, ReferenceLine } from 'recharts'; import { Calculator, ChevronDown, ChevronUp, IndianRupee } from 'lucide-react'; import { getOverallReturnBreakdown } from '../data/recommendations'; interface PortfolioSimulatorProps { className?: string; } export default function PortfolioSimulator({ className = '' }: PortfolioSimulatorProps) { const [startingAmount, setStartingAmount] = useState(100000); const [showBreakdown, setShowBreakdown] = useState(false); const breakdown = useMemo(() => getOverallReturnBreakdown(), []); // Calculate portfolio values over time const portfolioData = useMemo(() => { let value = startingAmount; return breakdown.dailyReturns.map(day => { value = value * day.multiplier; return { date: new Date(day.date).toLocaleDateString('en-IN', { month: 'short', day: 'numeric' }), value: Math.round(value), return: day.return, cumulative: day.cumulative, }; }); }, [breakdown.dailyReturns, startingAmount]); const currentValue = portfolioData.length > 0 ? portfolioData[portfolioData.length - 1].value : startingAmount; const totalReturn = ((currentValue - startingAmount) / startingAmount) * 100; const profitLoss = currentValue - startingAmount; const isPositive = profitLoss >= 0; const handleAmountChange = (e: React.ChangeEvent) => { const value = parseInt(e.target.value.replace(/,/g, ''), 10); if (!isNaN(value) && value >= 0) { setStartingAmount(value); } }; const formatCurrency = (value: number) => { return new Intl.NumberFormat('en-IN', { style: 'currency', currency: 'INR', maximumFractionDigits: 0, }).format(value); }; return (

Portfolio Simulator

{/* Input Section */}
{[10000, 50000, 100000, 500000].map(amount => ( ))}
{/* Results Section */}
Current Value
{formatCurrency(currentValue)}
Profit/Loss
{isPositive ? '+' : ''}{formatCurrency(profitLoss)} ({isPositive ? '+' : ''}{totalReturn.toFixed(1)}%)
{/* Chart */} {portfolioData.length > 0 && (
formatCurrency(v).replace('₹', '')} className="text-gray-500 dark:text-gray-400" width={60} /> [formatCurrency(value as number), 'Value']} />
)} {/* Daily Breakdown (Collapsible) */} {showBreakdown && (
{portfolioData.map((day, idx) => ( ))}
Date Return Value
{day.date} = 0 ? 'text-green-600 dark:text-green-400' : 'text-red-600 dark:text-red-400' }`}> {day.return >= 0 ? '+' : ''}{day.return.toFixed(1)}% {formatCurrency(day.value)}
)}

Simulated returns based on AI recommendation performance. Past performance does not guarantee future results.

); }