Skip to content

Instantly share code, notes, and snippets.

@rrfaria
Last active June 28, 2022 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrfaria/ab418efb984c1c56e0711e8e908ad54e to your computer and use it in GitHub Desktop.
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
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 + "%"
}
})
@rrfaria
Copy link
Author

rrfaria commented Aug 12, 2021

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/
image

@rrfaria
Copy link
Author

rrfaria commented Jun 28, 2022

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment