/** * HTML Report Generator - Creates interactive performance reports */ class ReportGenerator { constructor(strategy, strategyName) { this.strategy = strategy; this.name = strategyName || 'Strategy Report'; } generate() { const m = this.strategy.metrics; return ` ${this.name} - Performance Report

${this.name}

Generated by FxMathQuant Web - AI-Powered Strategy Generator

Profit Factor
${m.profitFactor.toFixed(2)}
Win Rate
${m.winRate.toFixed(1)}%
Total Trades
${m.totalTrades}
Max Drawdown
${m.maxDrawdown.toFixed(2)}%
Total Profit
$${m.totalProfit.toFixed(2)}
Final Balance
$${m.finalBalance.toFixed(2)}
Avg Win
$${m.avgWin.toFixed(2)}
Avg Loss
$${Math.abs(m.avgLoss).toFixed(2)}

Equity Curve

Strategy Rules

BUY when ALL of the following conditions are true:

${this.generateRulesHTML()}
Parameters:
ATR Period: ${this.strategy.atrPeriod} | SL Multiplier: ${this.strategy.slMultiplier.toFixed(2)} | TP Multiplier: ${this.strategy.tpMultiplier.toFixed(2)}
${this.generateTradesTable()}
`; } generateRulesHTML() { return this.strategy.rules.map((rule, index) => { let ruleText = ''; if (rule.type === 'simple') { ruleText = `${rule.left.price.toUpperCase()}[${rule.left.shift}] ${rule.operator} ${rule.right.price.toUpperCase()}[${rule.right.shift}]`; } else { ruleText = `(${rule.left.price1.toUpperCase()}[${rule.left.shift1}] ${rule.left.op} ${rule.left.price2.toUpperCase()}[${rule.left.shift2}]) ${rule.operator} (${rule.right.price.toUpperCase()}[${rule.right.shift}] × ${rule.right.multiplier})`; } return `
${index + 1}. ${ruleText}
`; }).join(''); } generateTradesTable() { const trades = this.strategy.metrics.trades || []; if (trades.length === 0) return ''; // Show first 50 trades const displayTrades = trades.slice(0, 50); return `

Trade History ${trades.length > 50 ? '(First 50 trades)' : ''}

${displayTrades.map((trade, i) => ` `).join('')}
# Type Entry Exit Profit Reason
${i + 1} ${trade.type} ${trade.entry.toFixed(5)} ${trade.exit.toFixed(5)} $${trade.profit.toFixed(2)} ${trade.reason.replace('_', ' ')}
`; } }