Sovereign Debt Crisis Probability Estimator

Sovereign Debt Crisis Probability Estimator

Estimated Sovereign Debt Crisis Probability

--%

Key Risk Factors:

Interpretation:

The estimated probability is based on a simplified model and should be used for illustrative purposes only. A higher percentage indicates a higher potential for a sovereign debt crisis based on the provided indicators.

${message}

`; document.body.appendChild(messageBox); } /** * Calculates the sovereign debt crisis probability based on a heuristic model. * Assigns risk points based on predefined thresholds for various indicators. * @returns {object} An object containing the estimated probability and a list of contributing risk factors. */ function calculateCrisisProbability() { const countryName = countryNameInput.value.trim(); const debtGdpRatio = parseFloat(debtGdpRatioInput.value); const shortTermDebtReserves = parseFloat(shortTermDebtReservesInput.value); const currentAccountBalance = parseFloat(currentAccountBalanceInput.value); const gdpGrowth = parseFloat(gdpGrowthInput.value); const inflationRate = parseFloat(inflationRateInput.value); const fiscalBalance = parseFloat(fiscalBalanceInput.value); const externalDebtGdp = parseFloat(externalDebtGdpInput.value); const politicalStability = parseFloat(politicalStabilityInput.value); // Input validation if (!countryName || isNaN(debtGdpRatio) || isNaN(shortTermDebtReserves) || isNaN(currentAccountBalance) || isNaN(gdpGrowth) || isNaN(inflationRate) || isNaN(fiscalBalance) || isNaN(externalDebtGdp) || isNaN(politicalStability)) { showMessageBox("Please fill in all input fields with valid numerical values."); return { probability: 0, factors: ["Invalid or missing input data."] }; } if (politicalStability < 0 || politicalStability > 10) { showMessageBox("Political Stability Index must be between 0 and 10."); return { probability: 0, factors: ["Invalid political stability index."] }; } let totalRiskPoints = 0; const riskFactors = []; // --- Heuristic Model for Risk Assessment --- // Higher points mean higher risk // Debt-to-GDP Ratio if (debtGdpRatio > 120) { totalRiskPoints += 30; // Very high risk riskFactors.push("High Debt-to-GDP Ratio (Very Risky)"); } else if (debtGdpRatio > 90) { totalRiskPoints += 20; // High risk riskFactors.push("High Debt-to-GDP Ratio"); } else if (debtGdpRatio > 60) { totalRiskPoints += 10; // Warning signal riskFactors.push("Debt-to-GDP Ratio is a Warning Signal"); } // Short-term Debt as % of Foreign Reserves (Liquidity) if (shortTermDebtReserves > 100) { totalRiskPoints += 25; // Very high illiquidity risk riskFactors.push("High Short-term Debt vs. Reserves (Illiquidity Risk)"); } else if (shortTermDebtReserves > 70) { totalRiskPoints += 15; // High illiquidity risk riskFactors.push("Short-term Debt vs. Reserves is High"); } else if (shortTermDebtReserves > 40) { totalRiskPoints += 5; // Moderate illiquidity risk riskFactors.push("Short-term Debt vs. Reserves is Moderate"); } // Current Account Balance (% of GDP) - Large deficit is negative if (currentAccountBalance < -5) { totalRiskPoints += 20; // Large deficit, high risk riskFactors.push("Large Current Account Deficit"); } else if (currentAccountBalance < -2) { totalRiskPoints += 10; // Moderate deficit riskFactors.push("Current Account Deficit"); } else if (currentAccountBalance > 2) { totalRiskPoints -= 5; // Surplus is positive } // Real GDP Growth (Annual %) - Negative or very low growth is negative if (gdpGrowth < 0) { totalRiskPoints += 25; // Recession, high risk riskFactors.push("Negative GDP Growth (Recession)"); } else if (gdpGrowth < 1) { totalRiskPoints += 15; // Stagnant growth riskFactors.push("Low GDP Growth"); } else if (gdpGrowth > 3) { totalRiskPoints -= 5; // Strong growth } // Inflation Rate (Annual %) - High inflation is negative if (inflationRate > 10) { totalRiskPoints += 20; // Hyperinflation risk riskFactors.push("Very High Inflation"); } else if (inflationRate > 5) { totalRiskPoints += 10; // High inflation riskFactors.push("High Inflation"); } else if (inflationRate < 2) { totalRiskPoints -= 5; // Low/stable inflation } // Government Fiscal Balance (% of GDP) - Large deficit is negative if (fiscalBalance < -8) { totalRiskPoints += 25; // Very large deficit, high risk riskFactors.push("Very Large Fiscal Deficit"); } else if (fiscalBalance < -4) { totalRiskPoints += 15; // Large deficit riskFactors.push("Large Fiscal Deficit"); } else if (fiscalBalance > 0) { totalRiskPoints -= 5; // Surplus is positive } // External Debt as % of GDP - High external debt is negative if (externalDebtGdp > 80) { totalRiskPoints += 20; // Very high external debt riskFactors.push("High External Debt-to-GDP"); } else if (externalDebtGdp > 50) { totalRiskPoints += 10; // Moderate external debt riskFactors.push("Moderate External Debt-to-GDP"); } // Political Stability Index (0-10, 10=Most Stable) - Lower score is negative if (politicalStability < 3) { totalRiskPoints += 25; // Very unstable riskFactors.push("Very Low Political Stability"); } else if (politicalStability < 6) { totalRiskPoints += 15; // Unstable riskFactors.push("Low Political Stability"); } else if (politicalStability > 8) { totalRiskPoints -= 5; // High stability } // Normalize risk points to a percentage (0-100%) // Max theoretical risk points could be around 25*8 = 200, but let's cap and scale const maxPossibleRiskPoints = 200; // An arbitrary max for normalization let probability = (totalRiskPoints / maxPossibleRiskPoints) * 100; probability = Math.max(0, Math.min(100, probability)); // Clamp between 0 and 100 // If no specific risk factors were identified but total risk is high, add a general note if (riskFactors.length === 0 && probability > 0) { riskFactors.push("General risk factors identified based on input values."); } else if (riskFactors.length === 0 && probability === 0) { riskFactors.push("No significant risk factors identified for a sovereign debt crisis."); } return { probability: probability.toFixed(2), factors: riskFactors }; } /** * Populates the results tab with calculated probability and risk factors. */ function displayResults() { const results = calculateCrisisProbability(); probabilityOutput.textContent = `${results.probability}%`; riskFactorsList.innerHTML = ''; // Clear previous list if (results.factors && results.factors.length > 0) { results.factors.forEach(factor => { const li = document.createElement('li'); li.textContent = factor; riskFactorsList.appendChild(li); }); } else { const li = document.createElement('li'); li.textContent = "No specific risk factors identified."; riskFactorsList.appendChild(li); } // Update interpretation text based on probability let interpretationMessage = "The estimated probability is based on a simplified heuristic model and should be used for illustrative purposes only. "; const prob = parseFloat(results.probability); if (prob >= 75) { interpretationMessage += "A very high probability suggests significant vulnerabilities and a high potential for a sovereign debt crisis. Urgent policy action may be required."; } else if (prob >= 50) { interpretationMessage += "A high probability indicates notable risks and potential for a crisis. Close monitoring and proactive measures are advisable."; } else if (prob >= 25) { interpretationMessage += "A moderate probability suggests some underlying risks that warrant attention. Continued vigilance is recommended."; } else { interpretationMessage += "A low probability indicates a relatively stable outlook based on the provided indicators."; } interpretationText.textContent = interpretationMessage; showTab(1); // Switch to results tab } /** * Generates and downloads a PDF report of the estimation. */ async function downloadPdf() { // Ensure jsPDF and html2canvas are loaded if (typeof window.jspdf === 'undefined' || typeof window.html2canvas === 'undefined' || typeof window.jspdf.AcroForm === 'undefined') { showMessageBox("PDF generation libraries are still loading or failed to load. Please ensure internet connectivity and try again in a moment."); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); // Initialize a new PDF document // Initialize currentY for content positioning let currentY = 20; const marginX = 15; const lineHeight = 7; // --- Title --- doc.setFontSize(22); doc.text("Sovereign Debt Crisis Probability Report", doc.internal.pageSize.getWidth() / 2, currentY, { align: 'center' }); currentY += 15; // --- Input Parameters Section --- doc.setFontSize(14); doc.text("1. Input Parameters", marginX, currentY); currentY += 10; doc.setFontSize(12); const inputs = [ { label: "Country Name", value: countryNameInput.value }, { label: "Debt-to-GDP Ratio", value: `${debtGdpRatioInput.value}%` }, { label: "Short-term Debt (% of Foreign Reserves)", value: `${shortTermDebtReservesInput.value}%` }, { label: "Current Account Balance (% of GDP)", value: `${currentAccountBalanceInput.value}%` }, { label: "Real GDP Growth (Annual %)", value: `${gdpGrowthInput.value}%` }, { label: "Inflation Rate (Annual %)", value: `${inflationRateInput.value}%` }, { label: "Government Fiscal Balance (% of GDP)", value: `${fiscalBalanceInput.value}%` }, { label: "External Debt (% of GDP)", value: `${externalDebtGdpInput.value}%` }, { label: "Political Stability Index (0-10)", value: `${politicalStabilityInput.value}` } ]; inputs.forEach(input => { doc.text(`${input.label}: ${input.value}`, marginX, currentY); currentY += lineHeight; }); currentY += 10; // Add some space after inputs // --- Estimated Probability Section --- doc.setFontSize(14); doc.text("2. Estimated Crisis Probability", marginX, currentY); currentY += 10; doc.setFontSize(36); const results = calculateCrisisProbability(); // Recalculate to ensure latest data doc.setTextColor(255, 0, 0); // Red color for probability doc.text(`${results.probability}%`, doc.internal.pageSize.getWidth() / 2, currentY, { align: 'center' }); doc.setTextColor(0, 0, 0); // Reset color to black currentY += 25; // --- Risk Factors Breakdown Section --- doc.setFontSize(14); doc.text("3. Key Risk Factors", marginX, currentY); currentY += 10; doc.setFontSize(12); results.factors.forEach(factor => { doc.text(`• ${factor}`, marginX + 5, currentY); currentY += lineHeight; }); currentY += 10; // --- Interpretation Section --- doc.setFontSize(14); doc.text("4. Interpretation", marginX, currentY); currentY += 10; doc.setFontSize(12); const splitText = doc.splitTextToSize(interpretationText.textContent, doc.internal.pageSize.getWidth() - 2 * marginX); doc.text(splitText, marginX, currentY); currentY += (splitText.length * lineHeight) + 10; doc.save(`Sovereign_Debt_Report_${countryNameInput.value.replace(/\s/g, '_')}.pdf`); } // --- Event Listeners --- tabButtons.forEach((button, index) => { if (button) { button.addEventListener('click', function() { showTab(index); }); } }); prevButton.addEventListener('click', function() { showTab(currentTab - 1); }); nextButton.addEventListener('click', function() { showTab(currentTab + 1); }); calculateButton.addEventListener('click', displayResults); downloadPdfButton.addEventListener('click', downloadPdf); // --- Initialization --- showTab(0); // Show initial tab });
Scroll to Top