ht High-Frequency Trading Strategy Simulator

High-Frequency Trading Strategy Simulator

Test automated trading strategies against simulated real-time market data.

Configure Simulation

Trading Strategy

Market Conditions

Live Simulation

Simulation Complete

The simulation has ended. You can now download the full trade report.

${totalTrades}

`; } function initChart() { const ctx = document.getElementById('price-chart').getContext('2d'); if (priceChart) priceChart.destroy(); priceChart = new Chart(ctx, { type: 'line', data: { labels: [], datasets: [{ label: 'Price', data: [], borderColor: '#22d3ee', tension: 0.1, pointRadius: 0 }] }, options: { responsive: true, maintainAspectRatio: false, scales: { x: { type: 'timeseries', time: { unit: 'second' } }, y: { ticks: { callback: v => `$${v.toFixed(2)}` } } } } }); } // --- PDF GENERATION --- async function generatePdfReport() { if (simulation.state.running) stopSimulation(); downloadPdfBtn.disabled = true; downloadPdfBtn.textContent = 'Generating...'; const { pnl, trades, wins, losses } = simulation.state; const totalTrades = wins + losses; const winRate = totalTrades > 0 ? (wins / totalTrades * 100) : 0; const tableRows = trades.map(t => `${t.time.toLocaleString()}${t.type}${t.shares}$${t.price.toFixed(2)}$${t.pnl.toFixed(2)}`).join(''); const reportHtml = `

HFT Strategy Performance Report

Strategy: ${simulation.config.strategy} | Date: ${new Date().toLocaleDateString()}

NET P/L
$${pnl.toFixed(2)}
WIN RATE
${winRate.toFixed(1)}%
TOTAL TRADES
${totalTrades}
AVG P/L PER TRADE
$${(pnl / totalTrades || 0).toFixed(2)}
Trade Log
${tableRows}
TimestampTypeSharesPriceP/L
`; const pdfTemplate = document.getElementById('pdf-template'); pdfTemplate.innerHTML = reportHtml; pdfTemplate.classList.remove('invisible'); try { const { jsPDF } = window.jspdf; const canvas = await html2canvas(pdfTemplate.querySelector('.pdf-page'), { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(), pdfHeight = (canvas.height * pdfWidth) / canvas.width; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); pdf.save('HFT_Simulation_Report.pdf'); } catch (e) { console.error('PDF Generation Error:', e); } finally { downloadPdfBtn.disabled = false; downloadPdfBtn.textContent = 'Download Trade Report'; pdfTemplate.classList.add('invisible'); pdfTemplate.innerHTML = ''; } } // --- EVENT LISTENERS --- startBtn.addEventListener('click', startSimulation); stopBtn.addEventListener('click', stopSimulation); downloadPdfBtn.addEventListener('click', generatePdfReport); // --- INITIALIZATION --- switchTab(0); });
Scroll to Top