Last active
June 28, 2022 19:04
-
-
Save rrfaria/ab418efb984c1c56e0711e8e908ad54e to your computer and use it in GitHub Desktop.
Carcular porcentagem de alocação da carteira de ações do primo rico
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
const itens = document.querySelectorAll('.tabela-carteira-kinvo tr') | |
const acoes = [] | |
itens.forEach(item => { | |
const first = item.querySelectorAll('td:first-child') | |
const last = item.querySelectorAll('td:last-child') | |
var list = {} | |
if (first.length){ | |
list.asset = first[0].innerText | |
const lastPrice = parseFloat(last[0].innerText.replace(/[R$.]/gm, '').replace(',', '.')) | |
list.price = lastPrice | |
acoes.push(list) | |
} | |
}); | |
const total = parseFloat(acoes.reduce((a, b) => a + b.price, 0).toFixed(2)) | |
acoes.map( item => { | |
item.percent = parseFloat((item.price * 100 / total).toFixed(2)) | |
}) | |
itens.forEach((item, index)=> { | |
if(index === 0) { | |
item.appendChild(document.createElement('th')).textContent="Porcentagem" | |
} | |
if(index > 0 ) { | |
item.appendChild(document.createElement('td')).textContent=acoes[index-1].percent + "%" | |
} | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Só copiar e colar no console(botão direito inspecionar >> na aba console) da pagina e ele vai adicionar uma coluna extra na tabela
com as porcentagens...
Os cálculos só levam em consideração as ações e não somam ações no EUA e nem Renda fixa nem fii
https://www.oprimorico.com.br/webserie-rumo-ao-bilhao/