-
-
Save eduardobsg/0b8a347237a2c11a225f929081d629f8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| cdb <- function(capital, data_aplicacao, data_resgate, di, pct_cdi){ | |
| library(dplyr) | |
| library(bizdays) | |
| dias_corridos <- as.numeric(difftime(data_resgate, data_aplicacao, units = "days")) | |
| # computar biz days entre datas | |
| bizdays::create.calendar("Brazil/ANBIMA", | |
| bizdays::holidaysANBIMA, | |
| weekdays=c("saturday", "sunday")) | |
| dias_uteis <- bizdays::bizdays(from = data_aplicacao, to = data_resgate, | |
| cal = "Brazil/ANBIMA") | |
| tx_di_dia <- (1 + di)^(1/252) - 1 | |
| rb_dia <- tx_di_dia * pct_cdi | |
| rb_periodo <- (1 + rb_dia) ^ (dias_uteis) - 1 | |
| taxa_ir <- dplyr::case_when( | |
| dias_corridos > 720 ~ 0.15, | |
| dias_corridos <= 720 & dias_corridos > 360 ~ 0.175, | |
| dias_corridos <= 360 & dias_corridos > 180 ~ 0.20, | |
| dias_corridos <= 180 ~ 0.225 | |
| ) | |
| valor_aplicacao_atualizado <- capital * (1 + rb_periodo) | |
| ir_rendimento <- (valor_aplicacao_atualizado - capital) * taxa_ir | |
| valor_liquido <- valor_aplicacao_atualizado - ir_rendimento | |
| valor_liquido | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment