Skip to content

Commit

Permalink
Correção no cálculo de taxa de rendimento (#64)
Browse files Browse the repository at this point in the history
* feat: add period selection

* fix: interest income calculation ('poupança')
  • Loading branch information
CleberL authored Sep 5, 2023
1 parent e4ec07f commit bcbe66a
Show file tree
Hide file tree
Showing 15 changed files with 239 additions and 66 deletions.
15 changes: 14 additions & 1 deletion components/InvestmentInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
<v-card-text>
<v-form @submit.prevent="submit">
<AmountInput />
<DurationInput />
<div class="duration-container">
<DurationInput />
<DurationTypeInput />
</div>
<IndexDiInput />
<IndexSelicInput />
<IndexCdbInput />
Expand All @@ -15,6 +18,7 @@
</template>
<script>
import AmountInput from './investment/AmountInput.vue'
import DurationTypeInput from './investment/DurationTypeInput.vue'
import DurationInput from './investment/DurationInput.vue'
import IndexDiInput from './investment/IndexDiInput.vue'
import IndexSelicInput from './investment/IndexSelicInput.vue'
Expand All @@ -23,6 +27,7 @@ import IndexLcxInput from './investment/IndexLcxInput.vue'
export default {
components: {
AmountInput,
DurationTypeInput,
DurationInput,
IndexDiInput,
IndexSelicInput,
Expand All @@ -31,3 +36,11 @@ export default {
}
}
</script>

<style scoped>
.duration-container {
display: flex;
flex-direction: row;
align-items: center;
}
</style>
22 changes: 18 additions & 4 deletions components/InvestmentSimulation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ import InvestmentResult from './InvestmentResult.vue'
import { getCDBResult } from '~/src/cdb'
import { getLcxResult } from '~/src/lcx'
import { getPoupancaResult } from '~/src/poupanca'
import { DurationType } from '~/store/investment'
export default {
components: { InvestmentResult },
data() {
return {
investment: this.$store.state.investment
investment: this.$store.state.investment,
periodMultiplier: {
[DurationType.Days]: 1,
[DurationType.Months]: 365 / 12,
[DurationType.Years]: 365
}
}
},
computed: {
Expand All @@ -45,22 +51,30 @@ export default {
this.investment.amount,
this.investment.di,
this.investment.cdb,
this.investment.duration
this.getDurationInDays()
)
},
resultLcx() {
return getLcxResult(
this.investment.amount,
this.investment.di,
this.investment.lcx,
this.investment.duration
this.getDurationInDays()
)
},
resultPoupanca() {
return getPoupancaResult(
this.investment.amount,
this.investment.poupanca,
this.investment.duration
this.getDurationInDays()
)
}
},
methods: {
getDurationInDays() {
return Math.floor(
this.investment.duration *
this.periodMultiplier[this.investment.durationType]
)
}
}
Expand Down
1 change: 0 additions & 1 deletion components/investment/DurationInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
type="number"
label="Vencimento"
prepend-icon="mdi-calendar"
suffix="meses"
min="1"
:rules="[rules.required, rules.positive]"
/>
Expand Down
27 changes: 27 additions & 0 deletions components/investment/DurationTypeInput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<v-select
v-model="durationType"
label="Tipo de período"
:items="durationTypeOptions"
density="compact"
></v-select>
</template>
<script>
export default {
computed: {
durationTypeOptions: {
get() {
return this.$store.state.investment.durationTypeOptions
}
},
durationType: {
get() {
return this.$store.state.investment.durationType
},
set(value) {
this.$store.commit('investment/setDurationType', value)
}
}
}
}
</script>
68 changes: 34 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
"lint-staged": "^13.0.3",
"postcss-html": "^1.3.0",
"prettier": "^2.5.1",
"stylelint": "^14.1.0",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-recommended-vue": "^1.1.0",
"stylelint-config-standard": "^28.0.0",
"stylelint": "^14.16.1",
"stylelint-config-prettier": "^9.0.5",
"stylelint-config-recommended-vue": "^1.4.0",
"stylelint-config-standard": "^29.0.0",
"ts-jest": "^27.1.1",
"vue-jest": "^3.0.4"
}
Expand Down
2 changes: 1 addition & 1 deletion src/cdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ export function getCDBResult(amount, di, yearlyIndex, periods) {

function getIndexCDB(yearlyInterest, di) {
const index = yearlyInterest / 100
return Math.pow((index * di) / 100 + 1, 1 / 12)
return Math.pow((index * di) / 100 + 1, 1 / 365)
}
12 changes: 6 additions & 6 deletions src/finance.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export function compoundInterest(amount, index, periods) {
return amount * Math.pow(index, periods) - amount
export function compoundInterest(amount, index, days) {
return amount * Math.pow(index, days) - amount
}

export function getIndexIR(periods) {
if (periods <= 6) {
export function getIndexIR(days) {
if (days <= 180) {
return 22.5
} else if (periods <= 12) {
} else if (days <= 360) {
return 20
} else if (periods <= 24) {
} else if (days <= 720) {
return 17.5
} else {
return 15
Expand Down
2 changes: 1 addition & 1 deletion src/lcx.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export function getLcxResult(amount, di, yearlyIndex, periods) {

function getIndexLcx(yearlyInterest, di) {
const index = yearlyInterest / 100
return Math.pow((index * di) / 100 + 1, 1 / 12)
return Math.pow((index * di) / 100 + 1, 1 / 365)
}
14 changes: 9 additions & 5 deletions src/poupanca.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ export function getPoupancaResult(amount, index, periods) {
const interestAmount = finance.compoundInterest(
amount,
getIndexPoupanca(index),
periods
calculateFullMonthsDays(periods)
)
const taxAmount = 0
const taxPercentage = 0
return { interestAmount, taxAmount, taxPercentage }

return { interestAmount }
}

export function calculateFullMonthsDays(days) {
const daysInMonth = 30
return days < daysInMonth ? 0 : Math.floor(days / daysInMonth) * daysInMonth
}

function getIndexPoupanca(index) {
return index / 100 + 1
return Math.pow(index / 100 + 1, 1 / 30)
}
Loading

0 comments on commit bcbe66a

Please sign in to comment.