Compund interest calculator - Decide for me or is there a better formula

I need a formula for determining a debt repayment plan, in which I know: the number of payments, the amount for the payment and the principal amount, and I need to find out which one will represent the interest rate. I redistribute the existing code, and the current method uses the following (compound = 12; interest rate starts with .1):

while (counter < 100) { intermediatePayment = (interestRate*(principal/compounded))/(1 - (1/Math.Pow(interestRate/compounded + 1,(compounded*numberOfYears)))); interestIncrement = Math.Abs(interestRate - previousRate)/2; previousRate = interestRate; if(intermediatePayment == payment) break; if (intermediatePayment > payment) interestRate -= interestIncrement; else interestRate += interestIncrement; counter++; } 

Now I understand what this formula does, but I can never come to it myself. What is actually the equation that is supposed to be used to determine the monthly payment if interest rates, principal amounts and the number of payments are known. It uses brute force and a cycle (not more than 100 times) until the settlement payment becomes equal to the desired payment. It usually comes to an answer after 40-50 cycles and can be optimized by reducing significant numbers.

It seems to me that if we just decided for interestRate, there would be no cycles. Try as I could, I can’t get the equation to solve for me, so my main question.

Now, if you understand the problem well and know the financial formulas and exacerbate interest, you can provide me with an even better solution that would be awesome. I myself did a lot of research and found tools, but not a crude equation, or more often than not I find different formulas to identify questions of interest, but I'm not aware of how to reconfigure them for my needs.

Basically, I spent too much time on this, and my boss thinks, because the cycle is working, I need to leave it or ask for help. Fair enough, so do I. :)

Here's a more traditional formula layout if it helps anyone: http://i.imgur.com/BCdsV.png

And for test data: if

  • P = 45500
  • c = 12
  • y = 3
  • t = 1400

then

  • i = .0676

thanks for the help

+4
source share
2 answers

If you try to solve the formula with which you are associated, for the interest rate, you will find that you get a polynomial of degree cy + 1, that is, the total number of payments plus one. It is difficult / impossible to find closed-form solutions for polynomials of high degree; therefore, approximation may be best.

The algorithm you indicated has some good properties: it’s pretty clear what it does and gives the right answer in a reasonable amount of time. Therefore, my attitude would be "if it is not broken, do not try to fix it."

If it turned out that for some reason this algorithm is too slow, that is, algorithms that converge faster to the correct answer; you could find out which polynomial you need to find the roots, work out its derivative using a simple calculus, and then use the Newton method to more quickly converge to the roots. But for this simple example, where the answer must be accurate to four decimal places, one way or another, this seems redundant.

+7
source

This formula cannot be explicitly solved for I , so you can stop trying. On the other hand, the loop goes beyond common sense exactly. You can, of course, stop when you are within half a cent of the payment amount, or when the increment in grade I drops below 0.0001, since there was some kind of rounding during the initial calculations.

0
source

Source: https://habr.com/ru/post/1306963/


All Articles