Skip to content

Instantly share code, notes, and snippets.

@vitor-mariano
Last active December 30, 2016 02:34
Show Gist options
  • Save vitor-mariano/aab2b789737001952e3deb443ac37c4e to your computer and use it in GitHub Desktop.
Save vitor-mariano/aab2b789737001952e3deb443ac37c4e to your computer and use it in GitHub Desktop.
Simulador de rentabilidade no tesouro direto
import R from 'ramda'
const compoundInterest = (a, f, t) => a * (1 + f) ** t
const compoundInterestSerie = (a, f, t) => R.pipe(
R.inc,
R.range(0),
R.map((i) => compoundInterest(a, f, i)),
R.sum
)(t)
const totalInvested = R.multiply
const incomeTax = R.cond([
[R.lte(R.__, 6), R.always(0.225)],
[R.lte(R.__, 12), R.always(0.200)],
[R.lte(R.__, 24), R.always(0.175)],
[R.T, R.always(0.150)]
])
const simulateFixed = (a, f, t) =>
a + (compoundInterest(a, f, t) - a) * (1 - incomeTax(t))
const simulateIncremental = (a, f, t) =>
totalInvested(a, t) + (compoundInterestSerie(a, f, t) - totalInvested(a, t)) * (1 - incomeTax(t))
simulateFixed(5000, 0.00925, 60)
simulateIncremental(1000, 0.0095, 60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment