Investment Portfolio Dashboard
Total Value
$0
Day's Gain/Loss
$0 (0%)
Total Gain/Loss
$0
Portfolio Value (Live)
Asset Allocation
Holdings
| Ticker | Quantity | Current Price | Day's Change | Market Value | Total Gain/Loss |
|---|
Add New Holding
Manage All Holdings
| Ticker | Quantity | Purchase Price | Action |
|---|
Error: A required library is missing.
'; return; } // --- DATA MANAGEMENT --- let holdings = JSON.parse(localStorage.getItem('ipd_holdings')) || []; const getSampleData = () => [ { id: 1, ticker: 'AAPL', class: 'US Equity', qty: 50, purchasePrice: 150.25, currentPrice: 195.50, prevPrice: 194.80 }, { id: 2, ticker: 'MSFT', class: 'US Equity', qty: 30, purchasePrice: 300.50, currentPrice: 420.75, prevPrice: 422.10 }, { id: 3, ticker: 'VOO', class: 'US Equity', qty: 20, purchasePrice: 400.00, currentPrice: 480.25, prevPrice: 479.90 }, { id: 4, ticker: 'VXUS', class: 'International Equity', qty: 100, purchasePrice: 55.75, currentPrice: 62.50, prevPrice: 62.60 }, { id: 5, ticker: 'BND', class: 'Bonds', qty: 150, purchasePrice: 75.10, currentPrice: 72.50, prevPrice: 72.45 }, ]; if (holdings.length === 0) holdings = getSampleData(); const saveState = () => localStorage.setItem('ipd_holdings', JSON.stringify(holdings)); // --- CHART INSTANCES & UTILITIES --- let valueChart, allocChart; const tabButtons = document.querySelectorAll('.ipd-tab-button'); const tabContents = document.querySelectorAll('.ipd-tab-content'); const nextBtn = document.getElementById('ipd-next-btn'); const prevBtn = document.getElementById('ipd-prev-btn'); const formatCurrency = (val, dec=2) => val.toLocaleString('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: dec, maximumFractionDigits: dec }); // --- RENDER FUNCTIONS --- const renderAll = () => { try { const processedData = holdings.map(h => ({ ...h, marketValue: h.qty * h.currentPrice, totalGainLoss: (h.currentPrice - h.purchasePrice) * h.qty, dayChange: (h.currentPrice - h.prevPrice) * h.qty })); renderKPIs(processedData); renderValueChart(processedData); renderAllocationChart(processedData); renderHoldingsTable(processedData); renderManageTable(); updateNavButtons(); } catch(error) { console.error("Dashboard rendering failed:", error); } }; const renderKPIs = (data) => { const totalValue = data.reduce((sum, d) => sum + d.marketValue, 0); const totalDayChange = data.reduce((sum, d) => sum + d.dayChange, 0); const totalGainLoss = data.reduce((sum, d) => sum + d.totalGainLoss, 0); const dayChangePercent = totalValue > 0 ? (totalDayChange / (totalValue - totalDayChange)) * 100 : 0; document.getElementById('ipd-value-kpi').textContent = formatCurrency(totalValue); const dayChangeEl = document.getElementById('ipd-day-change-kpi'); dayChangeEl.innerHTML = `${formatCurrency(totalDayChange)} (${dayChangePercent.toFixed(2)}%)`; dayChangeEl.className = totalDayChange >= 0 ? 'positive' : 'negative'; const totalGainEl = document.getElementById('ipd-total-gain-kpi'); totalGainEl.textContent = formatCurrency(totalGainLoss); totalGainEl.className = totalGainLoss >= 0 ? 'positive' : 'negative'; }; const renderValueChart = (data) => { // This is a simplified simulation const totalValue = data.reduce((sum, d) => sum + d.marketValue, 0); const seriesData = [totalValue * 0.995, totalValue * 0.998, totalValue * 0.997, totalValue * 1.002, totalValue]; const options = { chart: { type: 'area', height: 350, toolbar: { show: false }, sparkline: { enabled: true } }, series: [{ name: 'Portfolio Value', data: seriesData }], stroke: { curve: 'smooth', width: 2 }, fill: { type: 'gradient', gradient: { opacityFrom: 0.6, opacityTo: 0, stops: [0, 100] } }, colors: ['var(--ipd-primary-color)'] }; if(valueChart) valueChart.destroy(); document.querySelector("#ipd-value-chart").innerHTML = ''; valueChart = new ApexCharts(document.querySelector("#ipd-value-chart"), options); valueChart.render(); }; const renderAllocationChart = (data) => { const alloc = data.reduce((acc, h) => { acc[h.class] = (acc[h.class] || 0) + h.marketValue; return acc; }, {}); const options = { chart: { type: 'donut', height: 350 }, series: Object.values(alloc), labels: Object.keys(alloc), legend: { position: 'bottom' } }; if(allocChart) allocChart.destroy(); document.querySelector("#ipd-allocation-chart").innerHTML = ''; allocChart = new ApexCharts(document.querySelector("#ipd-allocation-chart"), options); allocChart.render(); }; const renderHoldingsTable = (data) => { const tbody = document.getElementById('ipd-holdings-tbody'); tbody.innerHTML = ''; data.sort((a,b) => b.marketValue - a.marketValue).forEach(h => { const dayChangeClass = h.dayChange >= 0 ? 'positive' : 'negative'; const totalGainClass = h.totalGainLoss >= 0 ? 'positive' : 'negative'; tbody.innerHTML += `${h.ticker}
