diff options
Diffstat (limited to 'screener.js')
-rw-r--r-- | screener.js | 7 |
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 |