diff options
author | root <root@mfoi.dev> | 2025-06-18 22:25:36 +0000 |
---|---|---|
committer | root <root@mfoi.dev> | 2025-06-18 22:25:36 +0000 |
commit | 710c4c578b1d90853495489c36b51862050ddddc (patch) | |
tree | 2e8a5c170b4e6159daebba26309578b7dde66dba /screener.js | |
parent | 8ea29da7256b8bd159dc768cbcc69fdba8a107e6 (diff) |
use names from sector map & fix formatting on decimals
Diffstat (limited to 'screener.js')
-rw-r--r-- | screener.js | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/screener.js b/screener.js index 68f1138..76d3d54 100644 --- a/screener.js +++ b/screener.js @@ -83,7 +83,7 @@ const getSectorMap = () => { if (index === 0) return; // skip the header line // split the line by comma and get the name, ticker, sector, and subSector const [name, ticker, sector, subSector] = line.split('\t'); - sectorMapObj[ticker.trim()] = [sector.trim(), subSector.trim()]; + sectorMapObj[ticker.trim()] = [sector.trim(), subSector.trim(), name.trim()]; }); return sectorMapObj; } @@ -146,8 +146,10 @@ const formatDataFromHistories = (histories) => { histories.forEach(history => { // Tickern, name weight, sector from html pull - const { symbol, name, weight } = history; + const { symbol, webName, weight } = history; const sector = sectorMap[symbol] ? sectorMap[symbol][0] : 'Unknown'; + const subSector = sectorMap[symbol] ? sectorMap[symbol][1] : 'Unknown'; + const name = sectorMap[symbol] ? sectorMap[symbol][2] : webName || 'Unknown'; // Get RSI, MACD from helper const timestamps = history.history.chart.result[0].timestamp; @@ -177,10 +179,10 @@ const formatDataFromHistories = (histories) => { Ticker: symbol, Name: name, '% Weight': weight, - 'Sector': sectorMap[symbol] ? sectorMap[symbol][0] : 'Unknown', - 'Subsector': sectorMap[symbol] ? sectorMap[symbol][1] : 'Unknown', - 'RSI (14)': rsi, - 'MACD (Histogram Value)': macd, + 'Sector': sector, + 'Subsector': subSector, + 'RSI (14)': rsi.toFixed(3), + 'MACD (Histogram Value)': macd.toFixed(3), '1W': oneWeekChange.toFixed(3) + '%', '1M': oneMonthChange.toFixed(3) + '%', '3M': threeMonthChange.toFixed(3) + '%', @@ -202,34 +204,6 @@ const formatDataFromHistories = (histories) => { }; // testGetHistories(); -const main = async () => { - try { - // gt the test histories from the file - // const histories = fs.readFileSync('sp500_histories.json', 'utf8'); - // const parsedHistories = JSON.parse(histories); - // console.log(`Loaded ${parsedHistories.length} histories from sp500_histories.json`); - - // get tickers from file - const tickers = getTickersFromFile(); - if (tickers.length === 0) { - console.error('No tickers found. Please ensure sp500_tickers.json exists and is populated.'); - return; - } - console.log(`Found ${tickers.length} tickers in sp500_tickers.json`); - // get histories for each symbol - const parsedHistories = await getHistoriesForEachTicker(tickers); - console.log(`Fetched histories for ${parsedHistories.length} symbols.`); - - - // format the data from the histories - const formattedData = formatDataFromHistories(parsedHistories); - console.log('Formatted data:', formattedData.slice(0, 5)); // Print first 5 entries for brevity - - } catch (error) { - console.error('Error in main function:', error); - } -} - const calculateMACD = (prices, shortPeriod = 12, longPeriod = 26, signalPeriod = 9) => { // Helper function to calculate the Exponential Moving Average (EMA) const exponentialMovingAverage = (data, period) => { @@ -354,7 +328,33 @@ const testGetSector = async () => { }); } -// testGetSector(); +const main = async () => { + try { + // gt the test histories from the file + // const histories = fs.readFileSync('sp500_histories.json', 'utf8'); + // const parsedHistories = JSON.parse(histories); + // console.log(`Loaded ${parsedHistories.length} histories from sp500_histories.json`); + + // get tickers from file + const tickers = getTickersFromFile(); + if (tickers.length === 0) { + console.error('No tickers found. Please ensure sp500_tickers.json exists and is populated.'); + return; + } + console.log(`Found ${tickers.length} tickers in sp500_tickers.json`); + // get histories for each symbol + const parsedHistories = await getHistoriesForEachTicker(tickers); + console.log(`Fetched histories for ${parsedHistories.length} symbols.`); + + + // format the data from the histories + const formattedData = formatDataFromHistories(parsedHistories); + console.log('Formatted data:', formattedData.slice(0, 5)); // Print first 5 entries for brevity + + } catch (error) { + console.error('Error in main function:', error); + } +} main(); |