How to calculate the monthly loan fee?
Given:
- a: loan amount.
- b: lending period (number of months).
- c: interest rate pa (interest is calculated and added every month, 1/12 percent is added. So if interest is 12%, 1% is added every month).
- d: amount of money due after the end of the period.
This problem is slightly different from the usual one, because the goal is not to repay the loan after the lonely period has ended, but should still provide the amount. I could find an algorithm to solve this problem if I wanted to pay the full amount, but this will be the reason that this work will not work when the goal is to end because of a certain amount, and not because anything.
I managed to solve this problem, starting with an assumption, and continue to improve this conjecture until it gets close enough. I thought, however, if there is a better way to just figure it out, and not just guess.
Edit: this is how I do it now.
def find_payment(start, end, months, interest): difference = start guess = int(start / months * interest) while True: total = start for month in range(1, months + 1): ascribe = total * interest / 12 total = total + ascribe - guess difference = total - end
evolution is just a function that shows how a loan will look like payment for payment and interest for interest, summing up the total amount of interest paid, etc.
For example, if I wanted to know the monthly payments for a loan starting at $ 100 thousand and ending at $ 50 thousand with a percentage of 8% and a duration of 70 months, calling
>>> find_payment(100000, 50000, 70, 0.08) payment is 1363
In the above case, I would finish for 49935, and I went through the loop 5 times. The number of times it takes to go through a cycle depends on how close I'm used to getting to the amount, and it changes a bit.
python math algorithm finance
googletorp
source share