html formatter

This commit is contained in:
Seth Trowbridge 2026-01-17 14:35:53 -05:00
parent 207c0067b3
commit bd31897f79

View File

@ -119,6 +119,61 @@ async function throttle<T>(
await Promise.all(queue);
}
function buildHtmlTable(
results: { ticker: string; model: ReturnType<typeof linearRegression> }[],
): string {
const rows = results.map(({ ticker, model }) => {
const link = `<a href="https://www.tradingview.com/symbols/NASDAQ-${ticker}/?timeframe=6M" target="_blank">${ticker}</a>`;
return `
<tr>
<td>${link}</td>
<td class="extra">${model.slope.toFixed(6)}</td>
<td class="extra">${model.intercept.toFixed(6)}</td>
<td class="extra">${model.r2.toFixed(4)}</td>
<td>${(model.growth * 100).toFixed(2)}%</td>
</tr>
`;
}).join("");
return `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>S&P 500 Regression Results</title>
<style>
body { font-family: Arial, sans-serif; padding: 20px; }
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid #ccc; padding: 8px; text-align: left; }
th { background: #f4f4f4; }
tr:nth-child(even) { background: #fafafa; }
.extra{display:none;}
</style>
</head>
<body>
<h1>S&P 500 Regression Results</h1>
<table>
<thead>
<tr>
<th style="width:75px;">Ticker</th>
<th class="extra">Slope</th>
<th class="extra">Intercept</th>
<th class="extra">R²</th>
<th>Growth (30d)</th>
</tr>
</thead>
<tbody>
${rows}
</tbody>
</table>
</body>
</html>
`;
}
// ------------------------------------------------------------
// Main Dump
// ------------------------------------------------------------
@ -139,7 +194,7 @@ async function Dump() {
const tickers = await fetchSP500Tickers();
console.log(`${tickers.length} S&P 500 stocks found...`);
console.log(
`Finding stocks with slope better than the S&P Index slope (${spx.slope.toFixed(6)})...`,
`Finding stocks with growth better than the S&P Index growth (${spx.growth.toFixed(4)})...`,
);
const limit = 5;
@ -159,16 +214,11 @@ async function Dump() {
// Sort by growth descending
results.sort((a, b) => b.model.growth - a.model.growth);
// Serialize CSV
const rows = ["ticker,slope,intercept,r2,growth"];
for (const { ticker, model } of results) {
rows.push(
`${ticker},${model.growth.toFixed(2)}`
);
}
// Build HTML
const html = buildHtmlTable(results);
await Deno.writeTextFile("sp500_regression.csv", rows.join("\n"));
console.log("Dumped output to sp500_regression.csv");
await Deno.writeTextFile("sp500_regression.html", html);
console.log("Dumped output to sp500_regression.html");
}
Dump();