Alternative Data Hedge Fund Strategy Builder

Alternative Data Hedge Fund Strategy Builder

Define Your Strategy

Create alternative data signals and define simple long/short trading rules based on their thresholds.

General Parameters

Alternative Data Signals & Rules

Maximum Drawdown: ${(backtestResultsSummary.maxDrawdown * 100).toFixed(2)}%

`; } // 4. Monthly Performance Breakdown if (backtestPerformed && backtestCumulativeValues.length > 0) { pdfHtmlContent += `

Monthly Performance Breakdown

`; pdfHtmlContent += ``; for (let i = 0; i < historicalData.length; i++) { const monthData = historicalData[i]; const monthlyStrategyReturnDisplay = (backtestMonthlyStrategyReturns[i] * 100).toFixed(2); const cumulativeValueDisplay = backtestCumulativeValues[i + 1].toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); pdfHtmlContent += ` `; } pdfHtmlContent += `
MonthSignal ValueAsset Return (%)Strategy PositionStrategy Return (%)Cumulative Value ($)
${i + 1} ${monthlySignalValuesUsed[i]} ${monthData.assetReturn.toFixed(2)} ${monthlyTradeDecisions[i]} ${monthlyStrategyReturnDisplay} $${cumulativeValueDisplay}
`; } // Set the HTML content to the hidden container pdfRenderContainer.innerHTML = pdfHtmlContent; try { // Create a canvas from the hidden container const canvas = await html2canvas(pdfRenderContainer, { useCORS: true, scale: 2, // Increase scale for better resolution logging: false // Disable logging for cleaner console }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF('p', 'mm', 'a4'); // 'p' for portrait, 'mm' for millimeters, 'a4' size const imgWidth = 210; // A4 width in mm const pageHeight = 297; // A4 height in mm const imgHeight = canvas.height * imgWidth / canvas.width; let heightLeft = imgHeight; let position = 0; // Add image with calculated height for multi-page support pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight); heightLeft -= pageHeight; while (heightLeft >= 0) { position = heightLeft - imgHeight; pdf.addPage(); pdf.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight); heightLeft -= pageHeight; } pdf.save('alternative_data_strategy_report.pdf'); } catch (error) { console.error('Error generating PDF:', error); alertUser('Failed to generate PDF. Please try again or check console for errors.'); } finally { // Clear the content of the hidden container pdfRenderContainer.innerHTML = ''; } }); // --- Custom Alert Function (instead of alert()) --- function alertUser(message) { let msgBox = document.getElementById('user-message-box'); if (!msgBox) { msgBox = document.createElement('div'); msgBox.id = 'user-message-box'; msgBox.className = 'fixed inset-x-0 top-0 flex items-center justify-center p-4 z-50'; msgBox.innerHTML = ` `; document.body.appendChild(msgBox); document.getElementById('close-user-message').addEventListener('click', () => { msgBox.classList.add('hidden'); }); } document.getElementById('user-message-text').textContent = message; msgBox.classList.remove('hidden'); setTimeout(() => { msgBox.classList.add('hidden'); }, 5000); // Hide after 5 seconds } // Initial rendering renderSignalsInputs(); renderMonthlyDataInputs(); // Render data table for initial 12 months });
Scroll to Top