I have a simple working annuity loan calculator written in python, which gives correct results when compared to calculators online. That is, the monthly amount (what part is interest, what is the downpayment amount etc) and the effective interest rate (EIR). It uses two numpy-functions, ppmt and ipmt
loanAmount = 100000
monthlyIntRate = 2.5 / 12
effectiveIntRate = 100 * ((1 + monthlyIntRate/100.)**12 - 1)
However, when I add a monthly fee to the payments, my EIR changes, but does no longer equal the answers given by online loan calculators.
monthlyFee = -5
monthlyIntToBePaid = np.ipmt(rate, per, nPer, loanAmount)
monthDownPay = np.ppmt(rate, per, nPer, loanAmount)
amountDue = monthlyInt + monthDownPay + monthlyFee
Everything else, is still in perfect agreement. I think my formula is a somewhat ok approximation, but I would like to know a better way to do this!
effectiveIntRate = 100 * ((1+ monthlyIntRate/100.)**12 - 1)
effectiveIntRate += 100 * monthlyFee*12*2./loanAmount # <-- this line!
Try this (uses IRR to find the rate after fee):
nPer=12
rate=monthlyIntRate/100.
Monthpay=np.pmt(rate, nPer, loanAmount, fv=0)
amountDue = Monthpay + monthlyFee
effectiveIntRate = 100 * ((1+ monthlyIntRate/100.)**12 - 1)
#effectiveIntRate += 100 * monthlyFee*12*2./loanAmount # <-- this line!
monthpays = [-amountDue] * nPer
monthpaysf=[-loanAmount] + monthpays
efratem=np.irr(monthpaysf)
effectiveIntRateF = 100 * ((1 + efratem)**12 - 1)
print(efratem*100,effectiveIntRateF)
(0.21749271256861213, 2.6413600327578557)