Last active
December 30, 2016 02:34
-
-
Save vitor-mariano/aab2b789737001952e3deb443ac37c4e to your computer and use it in GitHub Desktop.
Simulador de rentabilidade no tesouro direto
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
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