Portfolio Rebalancer

Your Assets:

Rebalancing Summary:

Total Current Portfolio Value: $0.00

Total Target Allocation: 0.00%

(This tool performs cash-neutral rebalancing)

Rebalancing Actions:

Asset Name Current Value ($) Current Weight (%) Target Weight (%) Target Value ($) Action Amount ($)

Current vs. Target Allocation:

Total Current Portfolio Value: $${data.totalCurrentValue.toFixed(2)}

Total Target Allocation: ${data.totalTargetWeight.toFixed(2)}%

(This tool performs cash-neutral rebalancing)

Rebalancing Actions:

${rebalanceTableHtml}

Current vs. Target Allocation Chart:

${data.chartDataURL ? `` : '

Chart not available.

'}
`; const tempDiv = document.createElement('div'); tempDiv.innerHTML = pdfContentHtml; document.body.appendChild(tempDiv); // Temporarily add to DOM to ensure styles apply const options = { margin: 10, filename: 'Portfolio_Rebalance_Results.pdf', image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2, logging: true, dpi: 192, letterRendering: true }, jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' } }; html2pdf().set(options).from(tempDiv).save().finally(() => { document.body.removeChild(tempDiv); }); } // Event Listeners on DOMContentLoaded document.addEventListener('DOMContentLoaded', function() { const addAssetBtn = document.getElementById('addAssetBtn'); const calculateRebalanceBtn = document.getElementById('calculateRebalanceBtn'); const resetBtn = document.getElementById('resetBtn'); const downloadPdfBtn = document.getElementById('downloadPdfBtn'); // Initial setup: Add a few default assets resetCalculator(); if (addAssetBtn) addAssetBtn.addEventListener('click', () => addAsset()); if (calculateRebalanceBtn) calculateRebalanceBtn.addEventListener('click', calculateRebalance); if (resetBtn) resetBtn.addEventListener('click', resetCalculator); if (downloadPdfBtn) downloadPdfBtn.addEventListener('click', downloadPdf); });
Scroll to Top