aboutsummaryrefslogtreecommitdiff
path: root/screener.js
diff options
context:
space:
mode:
authorroot <root@mfoi.dev>2025-06-18 20:58:18 -0400
committerroot <root@mfoi.dev>2025-06-18 20:58:18 -0400
commitf89bbb755ed3cf0837fb07f1a38866744251f226 (patch)
tree7af3bf162871a845b2101793888d765da0c8d0fb /screener.js
parent710c4c578b1d90853495489c36b51862050ddddc (diff)
create uploading pipeline to google sheets in upload.js
Diffstat (limited to 'screener.js')
-rw-r--r--screener.js7
1 files changed, 3 insertions, 4 deletions
diff --git a/screener.js b/screener.js
index 76d3d54..9fb0762 100644
--- a/screener.js
+++ b/screener.js
@@ -5,7 +5,6 @@ fs = require('node:fs');
// this gets the HTML page of the SP500 list from slickcharts.com
const getSPHTML = async () => {
-
const response = await fetch('https://www.slickcharts.com/sp500');
if (!response.ok) {
throw new Error('Network response was not ok');
@@ -163,13 +162,13 @@ const formatDataFromHistories = (histories) => {
const currentPrice = prices[prices.length - 1];
// Directly calculate the percentage changes for 1W, 1M, 3M, and 6M\
- const oneWeekAgoPrice = prices[prices.length - 6]; // 7 days ago
+ const oneWeekAgoPrice = prices[prices.length - 6]; // 5 days of trading
const oneWeekChange = ((currentPrice - oneWeekAgoPrice) / oneWeekAgoPrice) * 100;
- const oneMonthAgoPrice = prices[prices.length - 21]; // 21 days ago (trading days in a month)
+ const oneMonthAgoPrice = prices[prices.length - 21]; // 20 days of trading (4 weeks)
const oneMonthChange = ((currentPrice - oneMonthAgoPrice) / oneMonthAgoPrice) * 100;
- const threeMonthsAgoPrice = prices[prices.length - 63]; // 63 days ago (trading days in 3 months)
+ const threeMonthsAgoPrice = prices[parseInt(prices.length / 2) - 1]; // 3 months is half the length of the prices array
const threeMonthChange = ((currentPrice - threeMonthsAgoPrice) / threeMonthsAgoPrice) * 100;
const sixMonthsAgoPrice = prices[0]; // last 6 months is the first price in the array