Created
March 17, 2021 17:02
-
-
Save jaredrummler/8a0d536987de78df50456bbc81301228 to your computer and use it in GitHub Desktop.
Use percent change when viewing futures on Bloomberg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Bloomberg Futures | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Chage table content to use percents for futures | |
// @author Jared Rummler | |
// @match https://www.bloomberg.com/markets/stocks/futures | |
// @grant none | |
// ==/UserScript== | |
'use strict'; | |
const NET_CHANGE_INDEX = 4; | |
const TOTAL_POINTS_INDEX = 3; | |
(function() { | |
function cell(row, index) { | |
return row.getElementsByClassName("data-table-row-cell")[index]; | |
} | |
function parseCellToFloat(cell) { | |
return parseFloat(cell.textContent.replace(',', '')); | |
} | |
// Get the tables containing market data for each region | |
const tables = document.getElementsByClassName("data-table"); | |
for (let i = 0, table; table = tables[i]; i++) { | |
const rows = table.getElementsByClassName("data-table-row"); | |
for (let j = 0, row; row = rows[j]; j++) { | |
const netChangeCell = cell(row, NET_CHANGE_INDEX); | |
const netChangeInPoints = parseCellToFloat(netChangeCell); | |
const openPoints = parseCellToFloat(cell(row, TOTAL_POINTS_INDEX)); | |
const percent = ((netChangeInPoints / openPoints) * 100); | |
netChangeCell.setAttribute("data-type", (percent > 0) ? "better" : "worse"); | |
netChangeCell.getElementsByClassName("data-table-row-cell__value")[0].textContent = percent.toFixed(2) + '%'; | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment