Asset Drawdown Strategy Simulator

Initial Setup

Market Assumptions

E.g., Advisory fees, fund expense ratios.

Select Your Withdrawal Strategy

Asset Drawdown Simulation Results

Please complete the previous steps and click "Run Simulation" to see your results.

Funds remained after ${simulationPeriod} years.

`; summaryMsg += `

Final Portfolio Value: ${formatCurrency(currentBalance)}

`; } summaryMsg += `

Total Amount Withdrawn over ${fundsDepletedYear !== -1 && fundsDepletedYear < simulationPeriod ? fundsDepletedYear : simulationPeriod} years: ${formatCurrency(totalWithdrawn)}

`; simulationSummaryEl.innerHTML = summaryMsg; notesContainerEl.style.display = 'block'; downloadPdfBtn.style.display = 'block'; }); // PDF Download downloadPdfBtn?.addEventListener('click', function () { const { jsPDF } = window.jspdf; const pdfOutputArea = document.getElementById('dsPdfOutputArea'); if (!pdfOutputArea || simulationSummaryEl.innerHTML.includes("Please complete the previous steps")) { alert('Please run the simulation first before downloading PDF.'); return; } html2canvas(pdfOutputArea, { scale: 1.2, useCORS: true, backgroundColor: '#ffffff', windowWidth: pdfOutputArea.scrollWidth, windowHeight: pdfOutputArea.scrollHeight }) .then(canvas => { const imgData = canvas.toDataURL('image/jpeg', 0.85); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); // Changed to portrait A4 const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const margin = 30; let contentWidth = pdfWidth - 2 * margin; let contentHeight = pdfHeight - 2 * margin; const canvasWidth = canvas.width; const canvasHeight = canvas.height; // Calculate aspect ratio const imgRatio = canvasWidth / canvasHeight; const pdfRatio = contentWidth / contentHeight; let finalImgWidth, finalImgHeight; if (imgRatio > pdfRatio) { // Image is wider than target area finalImgWidth = contentWidth; finalImgHeight = finalImgWidth / imgRatio; } else { // Image is taller or same aspect ratio finalImgHeight = contentHeight; finalImgWidth = finalImgHeight * imgRatio; if (finalImgWidth > contentWidth) { // Recalc if too wide after height fit finalImgWidth = contentWidth; finalImgHeight = finalImgWidth / imgRatio; } } // Check if content is too small, then use its original size (but capped) if (canvasWidth < finalImgWidth && canvasHeight < finalImgHeight) { finalImgWidth = Math.min(canvasWidth, contentWidth); finalImgHeight = Math.min(canvasHeight, contentHeight); // Recalculate one dimension based on aspect ratio if one was capped if (finalImgWidth === contentWidth && (finalImgWidth / imgRatio < finalImgHeight) ) finalImgHeight = finalImgWidth / imgRatio; else if (finalImgHeight === contentHeight && (finalImgHeight * imgRatio < finalImgWidth)) finalImgWidth = finalImgHeight * imgRatio; } const x = (pdfWidth - finalImgWidth) / 2; let y = margin; // If image is still larger than one page, it will be clipped. // For truly multi-page, more complex logic for splitting canvas or multiple html2canvas calls needed. // This is a single-page capture. pdf.addImage(imgData, 'JPEG', x, y, finalImgWidth, finalImgHeight, undefined, 'MEDIUM'); pdf.save('Asset_Drawdown_Simulation.pdf'); }) .catch(err => { console.error("Error generating PDF:", err); alert("Error generating PDF. See console for details."); }); }); // Initial Setup switchTab('portfolioTab'); });
Scroll to Top