AI-Powered Market Making Strategy Simulator
Simulate a market-making strategy and analyze its performance under various market conditions with AI insights.
Simulation Parameters
Higher value means more price swings.
Positive for uptrend, negative for downtrend.
Simulation Results
Key Performance Metrics
| Metric | Value |
|---|---|
| Total P&L | $0.00 |
| Realized P&L | $0.00 |
| Unrealized P&L | $0.00 |
| Max Drawdown | $0.00 |
| Sharpe Ratio (Annualized) | 0.00 |
| Final Capital | $0.00 |
Cumulative P&L Over Time
AI-Powered Insights
Could not generate AI analysis. Please try again.
"; if (result.candidates && result.candidates[0] && result.candidates[0].content && result.candidates[0].content.parts[0]) { text = result.candidates[0].content.parts[0].text; } aiContainer.innerHTML = text; } catch (error) { console.error("Error fetching AI insights:", error); aiContainer.innerHTML = `Error generating AI insights.
`; } }; // --- PDF Export Logic --- /** * Exports the visible analysis summary (performance table, chart, and AI insights) to a PDF document. */ window.downloadPDF = async () => { // Make it global for onclick attribute const btn = document.getElementById('pdf-button-container')?.querySelector('button'); if (!btn) return; btn.disabled = true; btn.textContent = 'Generating PDF...'; const content = document.getElementById('summary-for-pdf'); if (!content) { showMessageBox("PDF Error", "Content for PDF not found."); btn.disabled = false; btn.textContent = 'Download Analysis as PDF'; return; } try { // Temporarily adjust chart and table sizes for better PDF rendering const chartCanvas = pnlTrendChartCanvas; const originalChartWidth = chartCanvas.style.width; const originalChartHeight = chartCanvas.style.height; chartCanvas.style.width = '1000px'; // Larger size for better quality capture chartCanvas.style.height = '500px'; if (pnlChartInstance) { pnlChartInstance.resize(); // Trigger Chart.js to redraw with new dimensions } const summaryTable = performanceSummaryTable; const originalTableWidth = summaryTable.style.width; summaryTable.style.width = 'fit-content'; // Allow table to expand naturally for capture const canvas = await html2canvas(content, { scale: 2, // Increase scale for better resolution useCORS: true, logging: false, backgroundColor: '#ffffff' // Ensure the background is white for PDF }); // Restore original chart and table sizes chartCanvas.style.width = originalChartWidth; chartCanvas.style.height = originalChartHeight; if (pnlChartInstance) { pnlChartInstance.resize(); } summaryTable.style.width = originalTableWidth; const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; // Determine orientation based on content width. If the captured canvas is very wide, use landscape. const orientation = canvas.width > canvas.height * 1.5 ? 'landscape' : 'portrait'; const pdf = new jsPDF({ orientation: orientation, unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const imgWidth = pdfWidth - 20; // 10mm margin on each side let imgHeight = (canvas.height * imgWidth) / canvas.width; let finalImgWidth = imgWidth; let finalImgHeight = imgHeight; if (finalImgHeight > pdfHeight - 20) { // If image is taller than page height finalImgHeight = pdfHeight - 20; finalImgWidth = (canvas.width * finalImgHeight) / canvas.height; } const x = (pdfWidth - finalImgWidth) / 2; const y = (pdfHeight - finalImgHeight) / 2; pdf.addImage(imgData, 'PNG', x, y, finalImgWidth, finalImgHeight); pdf.save(`Market_Making_Simulation_Analysis_${new Date().toISOString().slice(0, 10)}.pdf`); showMessageBox("PDF Generated", "Your Market Making Strategy Simulation analysis PDF has been successfully downloaded."); } catch(e) { console.error("PDF Generation Error: ", e); showMessageBox("PDF Error", "An error occurred while generating the PDF. Please ensure all content is visible and try again."); } finally { btn.disabled = false; btn.textContent = 'Download Analysis as PDF'; } }; // --- Initial Setup --- // No initial simulation run, user explicitly clicks. });