Emerging Markets Currency Devaluation Risk Predictor
Assess the potential risk of currency devaluation in an emerging market by inputting key economic indicators.
Macroeconomic Imbalances
External & Domestic Factors
Risk Assessment
Overall Devaluation Risk: ( points)
Key Risk Factors:
Disclaimer: This tool provides a simplified assessment of currency devaluation risk based on input parameters. It is for informational purposes only and does not constitute financial advice. Currency markets are complex and subject to many unforeseen factors. Always consult with a qualified financial professional for investment decisions.
No significant risk factors identified based on inputs.
'; } else { const ul = document.createElement('ul'); ul.classList.add('list-disc', 'pl-5'); summaryMessages.forEach(msg => { const li = document.createElement('li'); li.textContent = msg; ul.appendChild(li); }); riskSummaryDiv.appendChild(ul); } // Scroll to results resultsDiv.scrollIntoView({ behavior: 'smooth' }); } /** * Generates a PDF report of the tool's inputs and calculated results. */ async function generatePdf() { // Show loading spinner pdfSpinner.classList.remove('hidden'); downloadPdfBtn.disabled = true; // Disable button during PDF generation // Create a temporary div to render PDF content into const pdfContentDiv = document.createElement('div'); pdfContentDiv.className = 'pdf-content-hidden'; // Hidden and styled for print document.body.appendChild(pdfContentDiv); // Add title to PDF content const title = document.createElement('h1'); title.className = 'text-2xl font-bold text-gray-800 text-center mb-6'; title.textContent = 'Emerging Markets Currency Devaluation Risk Report'; pdfContentDiv.appendChild(title); // Add input values to PDF content const inputsSection = document.createElement('div'); inputsSection.className = 'grid grid-cols-1 md:grid-cols-2 gap-4 mb-6'; pdfContentDiv.appendChild(inputsSection); // Collect input values const inputGroups = document.querySelectorAll('.input-group'); inputGroups.forEach(group => { const labelElement = group.querySelector('label'); const inputElement = group.querySelector('input, select'); if (labelElement && inputElement) { const div = document.createElement('div'); div.className = 'mb-2'; let value = ''; if (inputElement.tagName === 'SELECT') { value = inputElement.options[inputElement.selectedIndex].text; } else { value = inputElement.value; } div.innerHTML = `${labelElement.textContent} ${value}`; inputsSection.appendChild(div); } }); // Add risk assessment results to PDF content if visible if (!resultsDiv.classList.contains('hidden')) { const resultsSection = document.createElement('div'); resultsSection.className = 'mt-8 p-6 bg-gray-50 rounded-lg shadow-inner'; resultsSection.innerHTML = `Risk Assessment
Overall Devaluation Risk: ${riskLevelSpan.textContent} (${riskScoreSpan.textContent} points)
${riskSummaryDiv.innerHTML}
`;
pdfContentDiv.appendChild(resultsSection);
}
try {
const canvas = await html2canvas(pdfContentDiv, {
scale: 2, // Increase scale for better resolution in PDF
useCORS: true // Required if you have external images/resources (though none here)
});
const imgData = canvas.toDataURL('image/png');
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({
orientation: 'portrait',
unit: 'px',
format: 'a4'
});
const imgWidth = pdf.internal.pageSize.getWidth() - 40; // Subtract margins (20px each side)
const imgHeight = (canvas.height * imgWidth) / canvas.width;
let position = 20; // Initial Y position with top margin
pdf.addImage(imgData, 'PNG', 20, position, imgWidth, imgHeight);
// If content overflows, add new pages. This is a basic check.
let heightLeft = imgHeight;
heightLeft -= (pdf.internal.pageSize.getHeight() - 40); // Subtract current page usable height
while (heightLeft >= 0) {
position = heightLeft - imgHeight + 20; // Calculate position for next page
pdf.addPage();
pdf.addImage(imgData, 'PNG', 20, position, imgWidth, imgHeight);
heightLeft -= (pdf.internal.pageSize.getHeight() - 40);
}
pdf.save('EM_Currency_Devaluation_Risk_Report.pdf');
} catch (error) {
console.error("Error generating PDF:", error);
// Provide user feedback without alert()
const messageBox = document.createElement('div');
messageBox.textContent = "Failed to generate PDF. Please try again or check console for details.";
messageBox.style.cssText = `
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #f8d7da;
color: #721c24;
padding: 15px 25px;
border-radius: 8px;
border: 1px solid #f5c6cb;
z-index: 1000;
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
font-family: 'Inter', sans-serif;
`;
document.body.appendChild(messageBox);
setTimeout(() => messageBox.remove(), 5000); // Remove after 5 seconds
} finally {
// Hide loading spinner and re-enable button
pdfSpinner.classList.add('hidden');
downloadPdfBtn.disabled = false;
// Remove the temporary PDF content div from the DOM
if (pdfContentDiv.parentNode) {
pdfContentDiv.parentNode.removeChild(pdfContentDiv);
}
}
}
});