Changed around line 1
+ // Sample stock data
+ const stocks = [
+ { name: 'Apple', ticker: 'AAPL', lowVol: true, highDiv: false, highQual: true },
+ { name: 'Microsoft', ticker: 'MSFT', lowVol: true, highDiv: false, highQual: true },
+ { name: 'AT&T', ticker: 'T', lowVol: true, highDiv: true, highQual: false },
+ { name: 'Coca-Cola', ticker: 'KO', lowVol: true, highDiv: true, highQual: true },
+ { name: 'Exxon', ticker: 'XOM', lowVol: false, highDiv: true, highQual: false },
+ { name: 'Johnson & Johnson', ticker: 'JNJ', lowVol: true, highDiv: true, highQual: true },
+ { name: 'Procter & Gamble', ticker: 'PG', lowVol: true, highDiv: true, highQual: true },
+ { name: 'Verizon', ticker: 'VZ', lowVol: true, highDiv: true, highQual: false }
+ ];
+
+ const stockGrid = document.getElementById('stock-grid');
+ const selectedStocks = document.getElementById('selected-stocks');
+ const backtestBtn = document.getElementById('backtest-btn');
+ const resultsDiv = document.getElementById('results');
+ const portfolio = new Set();
+
+ function renderStocks() {
+ stockGrid.innerHTML = '';
+ const lowVol = document.getElementById('low-volatility').checked;
+ const highDiv = document.getElementById('high-dividend').checked;
+ const highQual = document.getElementById('high-quality').checked;
+
+ stocks.filter(stock => {
+ return (!lowVol || stock.lowVol) &&
+ (!highDiv || stock.highDiv) &&
+ (!highQual || stock.highQual);
+ }).forEach(stock => {
+ const card = document.createElement('div');
+ card.className = 'stock-card';
+ card.innerHTML = `
+
${stock.name}
+ `;
+ card.addEventListener('click', () => toggleStock(stock));
+ stockGrid.appendChild(card);
+ });
+ }
+
+ function toggleStock(stock) {
+ if (portfolio.has(stock)) {
+ portfolio.delete(stock);
+ } else {
+ portfolio.add(stock);
+ }
+ renderSelectedStocks();
+ }
+
+ function renderSelectedStocks() {
+ selectedStocks.innerHTML = '';
+ portfolio.forEach(stock => {
+ const chip = document.createElement('div');
+ chip.className = 'stock-chip';
+ chip.textContent = `${stock.name} (${stock.ticker})`;
+ selectedStocks.appendChild(chip);
+ });
+ }
+
+ function backtestPortfolio() {
+ if (portfolio.size === 0) {
+ resultsDiv.textContent = 'Please select at least one stock to backtest.';
+ return;
+ }
+
+ // Simulate backtest results
+ const portfolioArray = Array.from(portfolio);
+ const returns = portfolioArray.map(() => (Math.random() * 30).toFixed(2));
+
+ resultsDiv.innerHTML = `
+
Backtest Results
+ ${portfolioArray.map((stock, i) => `
+
${stock.name} (${stock.ticker}): ${returns[i]}%+ `).join('')}
+
+
Portfolio Average Return: ${(returns.reduce((a,b) => +a + +b, 0) / returns.length).toFixed(2)}%
+ `;
+ }
+
+ document.querySelectorAll('.filters input').forEach(input => {
+ input.addEventListener('change', renderStocks);
+ });
+
+ backtestBtn.addEventListener('click', backtestPortfolio);
+
+ // Initial render
+ renderStocks();