Expected Shortfall (ES) Calculator
Calculate Value at Risk (VaR) and Expected Shortfall (ES) based on historical return data.
Analysis Results
Expected Shortfall (ES) Analysis Report
Input Parameters
Analysis Results
Interpretation
Confidence Level: ${confidenceLevel}%
${initialInvestment > 0 ? `Initial Investment: ${formatCurrency(initialInvestment)}
` : ''}Value at Risk (VaR): ${varPercent.toFixed(2)}% ${initialInvestment > 0 ? ` (${formatCurrency(varPercent / 100 * initialInvestment)})` : ''}
With ${confidenceLevel}% confidence, the maximum expected loss over one period is ${varPercent.toFixed(2)}%. ${initialInvestment > 0 ? ` This amounts to ${formatCurrency(varPercent / 100 * initialInvestment)} on an initial investment of ${formatCurrency(initialInvestment)}.` : ''} Alternatively, there is a ${(100 - confidenceLevel).toFixed(1)}% chance that the loss will exceed this amount.
Expected Shortfall (ES): ${cvarPercent.toFixed(2)}% ${initialInvestment > 0 ? ` (${formatCurrency(cvarPercent / 100 * initialInvestment)})` : ''}
If losses exceed the VaR estimate (i.e., in the worst ${(100 - confidenceLevel).toFixed(1)}% of cases), the average expected loss (Expected Shortfall) over one period is ${cvarPercent.toFixed(2)}%. ${initialInvestment > 0 ? ` This amounts to ${formatCurrency(cvarPercent / 100 * initialInvestment)} on an initial investment of ${formatCurrency(initialInvestment)}.` : ''}
`; resultsSectionEl.style.display = 'block'; pdfDownloadBtn.style.display = 'block'; // Prepare PDF content document.getElementById('pdfReportDate').textContent = `Report generated on: ${new Date().toLocaleDateString()}`; document.getElementById('pdfConfidenceLevel').textContent = `Confidence Level: ${confidenceLevel}%`; document.getElementById('pdfInitialInvestment').textContent = initialInvestment > 0 ? `Initial Investment: ${formatCurrency(initialInvestment)}` : 'Initial Investment: Not specified'; document.getElementById('pdfNumObservations').textContent = `Number of Observations: ${n}`; document.getElementById('pdfVaRPercent').textContent = `Value at Risk (VaR): ${varPercent.toFixed(2)}%`; document.getElementById('pdfVaRValue').textContent = initialInvestment > 0 ? `VaR Monetary Value: ${formatCurrency(varPercent / 100 * initialInvestment)}` : 'VaR Monetary Value: N/A'; document.getElementById('pdfESPercent').textContent = `Expected Shortfall (ES): ${cvarPercent.toFixed(2)}%`; // Changed label document.getElementById('pdfESValue').textContent = initialInvestment > 0 ? `ES Monetary Value: ${formatCurrency(cvarPercent / 100 * initialInvestment)}` : 'ES Monetary Value: N/A'; // Changed label document.getElementById('pdfVaRInterpretation').textContent = `VaR Interpretation: With ${confidenceLevel}% confidence, the maximum expected loss is ${varPercent.toFixed(2)}%. There's a ${(100-confidenceLevel).toFixed(1)}% chance of losses exceeding this.`; document.getElementById('pdfESInterpretation').textContent = `ES Interpretation: In the worst ${(100-confidenceLevel).toFixed(1)}% of scenarios, the average expected loss (Expected Shortfall) is ${cvarPercent.toFixed(2)}%.`; // Changed label }); loadSampleBtn.addEventListener('click', function() { returnDataEl.value = sampleData; errorMessagesEl.style.display = 'none'; resultsSectionEl.style.display = 'none'; pdfDownloadBtn.style.display = 'none'; }); resetBtn.addEventListener('click', function() { returnDataEl.value = ''; confidenceLevelEl.value = '95'; initialInvestmentEl.value = '10000'; resultsSectionEl.style.display = 'none'; pdfDownloadBtn.style.display = 'none'; errorMessagesEl.style.display = 'none'; resultsOutputEl.innerHTML = ''; }); pdfDownloadBtn.addEventListener('click', function() { const elementToPrint = document.getElementById('pdfReportContent'); elementToPrint.style.display = 'block'; const opt = { margin: [15, 10, 15, 10], filename: 'expected_shortfall_analysis_report.pdf', // Updated filename image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2, useCORS: true, logging: false }, jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' } }; html2pdf().from(elementToPrint).set(opt).save().then(() => { elementToPrint.style.display = 'none'; }).catch(err => { console.error("Error generating PDF:", err); elementToPrint.style.display = 'none'; }); }); });