Option Valuation and Greeks Dashboard

Option Valuation and Greeks Dashboard

Calculate option prices and sensitivities using the Black-Scholes model.

Valuation & Greeks

Option Price vs. Stock Price

Saved Scenarios

No scenarios saved yet. Use the "Save Scenario" button on the Calculator tab.

No scenarios saved yet. Use the "Save Scenario" button on the Calculator tab.

`; return; } scenariosContainer.innerHTML = ''; state.scenarios.forEach((scenario, index) => { const { inputs, results } = scenario; scenariosContainer.innerHTML += `

Scenario ${index + 1}

Inputs: S=${inputs.S}, K=${inputs.K}, T=${inputs.T_days}d, r=${inputs.r_pct}%, v=${inputs.v_pct}%

Results: Price=${results.price ? `$${results.price.toFixed(2)}` : 'N/A'}, Delta=${results.delta ? results.delta.toFixed(2) : 'N/A'}

`; }); document.querySelectorAll('.remove-scenario-btn').forEach(btn => btn.addEventListener('click', handleRemoveScenario)); }; // --- EVENT HANDLERS --- const getInputs = () => { const S = parseFloat(document.getElementById('stockPrice').value); const K = parseFloat(document.getElementById('strikePrice').value); const T_days = parseFloat(document.getElementById('maturity').value); const r_pct = parseFloat(document.getElementById('riskFreeRate').value); const v_pct = parseFloat(document.getElementById('volatility').value); const type = document.getElementById('optionType').value; return { S, K, T: T_days / 365, r: r_pct / 100, v: v_pct / 100, type, T_days, r_pct, v_pct }; }; const handleCalculate = () => { const inputs = getInputs(); const results = calculateBlackScholes(inputs); renderResults(results); renderPriceChart(inputs); }; const handleSaveScenario = () => { const inputs = getInputs(); const results = calculateBlackScholes(inputs); state.scenarios.push({ inputs, results }); renderScenarios(); alert('Scenario saved! Check the Scenario Analysis tab.'); }; const handleRemoveScenario = (e) => { const index = parseInt(e.target.dataset.index); state.scenarios.splice(index, 1); renderScenarios(); }; const handleDownloadPdf = () => { const { jsPDF } = window.jspdf; const pdfContent = document.getElementById('pdf-content'); document.querySelectorAll('.no-print').forEach(el => el.style.visibility = 'hidden'); Chart.defaults.animation = false; html2canvas(pdfContent, { scale: 2, useCORS: true, backgroundColor: '#ffffff' }).then(canvas => { document.querySelectorAll('.no-print').forEach(el => el.style.visibility = 'visible'); Chart.defaults.animation = true; const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgWidth = pdfWidth - 20; const imgHeight = canvas.height * imgWidth / canvas.width; pdf.addImage(imgData, 'PNG', 10, 10, imgWidth, imgHeight); pdf.save('Option-Valuation-Report.pdf'); }); }; // --- TABBING LOGIC --- let currentTabIndex = 0; const updateTabButtons = () => { prevTabBtn.disabled = currentTabIndex === 0; nextTabBtn.disabled = currentTabIndex === tabContents.length - 1; }; const switchTab = (index) => { tabButtons.forEach(btn => btn.classList.remove('active')); tabContents.forEach(content => content.classList.remove('active')); tabButtons[index].classList.add('active'); tabContents[index].classList.add('active'); currentTabIndex = index; updateTabButtons(); }; tabButtons.forEach((button, index) => button.addEventListener('click', () => switchTab(index))); prevTabBtn.addEventListener('click', () => { if (currentTabIndex > 0) switchTab(currentTabIndex - 1); }); nextTabBtn.addEventListener('click', () => { if (currentTabIndex < tabContents.length - 1) switchTab(currentTabIndex + 1); }); // --- INITIALIZATION --- if (calculateBtn) { calculateBtn.addEventListener('click', handleCalculate); saveScenarioBtn.addEventListener('click', handleSaveScenario); downloadPdfBtn.addEventListener('click', handleDownloadPdf); handleCalculate(); // Initial calculation on load updateTabButtons(); } else { console.error("Essential dashboard elements could not be found."); } });
Scroll to Top