Problema
Cómo calcular Tipo de interés efectivo anual (TEA) y Tasa Anual Equivalente (TAE) con tasas (en R) ?
Me interesa saber cuánto estoy pagando realmente de intereses si se tienen en cuenta las comisiones y supongo que EAR es el camino a seguir, pero corregidme si me equivoco.
Intenté implementar la TAE a continuación como en la descripción de investopedia, pero la TAE es menor que el interés nominal, por lo que seguramente no es correcta (debería ser alrededor del 3,5%)
Lo que he probado
A continuación un MVE que también explica el problema con más detalle:
rm(list=ls())
library(reprex)
# define costs, fees and interests
price <- 24800
monthly_payment <- 280
deposit <- 4000
loan_term <- 5*12 #in months
initial_fee <- 300
monthly_fee <- 12
nominal_interest <- 2/100
monthly_interest <- nominal_interest/12
# initiate fixed costs, interest fees and total costs for the loop
handling_charges <- initial_fee
interest_fees <- 0
total_costs <- handling_charges
# substracting initial payment from the what is left variable
left <- price - deposit
#calculating how much of dept is left after loan period and how much interest has accumulated
for (i in 1:loan_term) {
left_last_month <- left
left <- left*(1+monthly_interest)
interest_fees_mo <- (left-left_last_month)
interest_fees <- interest_fees + interest_fees_mo
handling_charges <- handling_charges + monthly_fee
total_costs <- total_costs+ interest_fees_mo + monthly_fee
left <- left+monthly_fee-monthly_payment
}
#https://www.investopedia.com/terms/a/apr.asp
#https://www.investopedia.com/terms/e/effectiveinterest.asp
apr_100 <-
((
(total_costs/price)
/(loan_term*30.4375) # number of days in the loan term
)
*365.25) # number of days in a year
apr <- apr_100*100
# ear ???
share_of_loan_100 <- (total_costs/price)*100
share_of_loan_100
#> [1] 9.632864
left # after loan period ends
#> [1] 6088.95
interest_fees
#> [1] 1368.95
handling_charges
#> [1] 1020
total_costs
#> [1] 2388.95
apr # wrong
#> [1] 1.926573
# ear # ????
Creado el 2022-01-20 por el paquete reprex (v2.0.1)
Definiciones de investopedia:
APR
EAR, no se tienen en cuenta las tasas
EDIT1:
Basado en base64 de la Comisión, he aquí un nuevo intento. Hay dos lugares que traté de arreglar y no estoy obteniendo las mismas respuestas exactas que la calculadora de finanzas, pero se está acercando.
- ¿Parece que la búsqueda binaria APR hace lo que se supone que debe hacer? (Las variables cruciales son
D=monthly_payment-monthly_fee
ytarget=paid_excluding_fees
). La TAE se calcula con el fórmula dada por la Unión Europea -
¿Cómo debo tener en cuenta la tasa inicial en mis cálculos? (especialmente en lo que respecta a la
principal
yleft
variables)rm(list=ls()) library(reprex) library(gtools)
define costs, fees and interests
price <- 24800 monthly_payment <- 280 monthly_fee <- 12 deposit <- 4000 loan_term <- 5*12 #in months initial_fee <- 300 nominal_interest <- 2/100 monthly_interest <- nominal_interest/12
initiate fixed costs, interest fees and total costs for the loop
handling_charges <- initial_fee interest_fees <- 0 total_costs <- handling_charges
#########################################################################
substracting initial payment and initial fees to get principal
principal <- price - deposit - initial_fee # left <- principal #
left <- principal + initial_fee
#########################################################################
calculating how much of dept is left after loan period and how much interest has accumulated
for (i in 1:loan_term) { left_last_month <- left left <- left*(1+monthly_interest) interest_fees_mo <- (left-left_last_month) interest_fees <- interest_fees + interest_fees_mo handling_charges <- handling_charges + monthly_fee total_costs <- total_costs+ interest_fees_mo + monthly_fee left <- left+monthly_fee-monthly_payment }
left <- left - initial_fee
paid_excluding_fees <- principal-left
function to calculate apr (multiplied by 100)
https://en.wikipedia.org/w/index.php?title=Annual_percentage_rate#European_Union
apr_100 <- function(APR=APR, D=monthly_payment-monthly_fee,MONTHS=loan_term){ sum(sapply(1:MONTHS, function(MONTHS) D(1+APR/(100100))^-(MONTHS/12))) }
running a binary search to find apr given that we know how much we have paid
binsearch <- binsearch(apr_100, range = c(0,100*100),target=paid_excluding_fees)
dividing the result by 100 and getting the mean
binsearch$where <- binsearch$where/100 binsearch
> $call
> binsearch(fun = apr_100, range = c(0, 100 * 100), target = paid_excluding_fees)
>
> $numiter
> [1] 15
>
> $flag
> [1] "Between Elements"
>
> $where
> [1] 3.52 3.53
>
> $value
> [1] 14744.85 14741.34
apr <- mean(binsearch$where) apr
> [1] 3.525
calcualting APY
https://www.investopedia.com/terms/a/apy.asp
apy <- ((1+(apr/100)/12)^12-1)*100 #
share_of_loan_100 <- (total_costs/price)*100 share_of_loan_100
> [1] 9.505752
left # after loan period ends
> [1] 5757.427
interest_fees
> [1] 1337.427
handling_charges
> [1] 1020
total_costs
> [1] 2357.427
apr
> [1] 3.525
apy
> [1] 3.582512
Creado el 2022-01-25 por el paquete reprex (v2.0.1)