From bd31897f790c322df1f57f1273657177921dd74a Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 17 Jan 2026 14:35:53 -0500 Subject: [PATCH] html formatter --- scraper.ts | 70 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/scraper.ts b/scraper.ts index a56add3..8867fed 100644 --- a/scraper.ts +++ b/scraper.ts @@ -119,6 +119,61 @@ async function throttle( await Promise.all(queue); } + +function buildHtmlTable( + results: { ticker: string; model: ReturnType }[], +): string { + const rows = results.map(({ ticker, model }) => { + const link = `${ticker}`; + return ` + + ${link} + ${model.slope.toFixed(6)} + ${model.intercept.toFixed(6)} + ${model.r2.toFixed(4)} + ${(model.growth * 100).toFixed(2)}% + + `; + }).join(""); + + return ` + + + + + S&P 500 Regression Results + + + +

S&P 500 Regression Results

+ + + + + + + + + + + + ${rows} + +
TickerSlopeInterceptGrowth (30d)
+ + +`; +} + + + // ------------------------------------------------------------ // 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();