# Paying off an installment

How do I determine the weekly installment I have to pay, if my loan is, let's say, loan=5000, with interest rate of 2% every week, and I have to settle it in 52 weeks. This is my code so far.

amt = 5000;
interestrate = 2;
nlast = 52;
inst = (* I do not know how to obtain this *);

Do[
interest = amt*interestrate;
amt = (amt + (interest/100.0)) - inst;
Print["this is the ", n, " week."];
Print[" I pay the installment ", inst, " per week, the remaining amount I have to pay is ", amt];
Print[" "];
If[amt < 0, inst = inst + 1],
{n, 1, nlast, 1}
];

-
I like, how the tag on a thread about paying off debt is "infinite-loop" :) – LLlAMnYP Mar 1 at 19:51
FWIW you do not have an infinite loop. With inst unspecified amt is a symbolic expression that grows larger and larger with each iteration. (And you are trying to print this big thing to the screen every time). Try runninfg with nlast=10 and you'll see.. – george2079 Mar 1 at 20:30
An "interest rate of 2% every week" could mean an annual effective interest rate of 180% p.a. depending on interpretation. (1 + 0.02)^52 - 1 = 1.8003. Do you mean an annual effective rate of 2%, or a nominal rate of 2% compounded weekly? (see link) – Chris Degnen Mar 2 at 12:01
yes, effective interest rate is 180% like u said. 2% weekly – Nabil Mar 7 at 3:40

Just to show how to fix the origional loop:

amt = 5000;
interestrate = .02;
nlast = 52;
Do[interest = amt*interestrate;
amt = Simplify[amt + interest - inst], {n, 1, nlast, 1}];
Solve[amt == 0, inst]


inst -> 155.545

Note the Simplify is important here, without it amt looks like this after just 4 weeks..

     5100. + 0.02 (5100. + 0.02 (5100. + 0.02 (5100. - inst) - 2 inst) +
0.02 (5100. - inst) - 3 inst) +  0.02 (5100. + 0.02 (5100. - inst) - 2 inst) + 0.02 (5100. - inst) -  4 inst


It is correct but will be horribly slow even if you don't try to print it.

-

Using Annuity:

pmt /.Solve[TimeValue[Annuity[pmt, 52, 1], .02, 0] == 5000, pmt]


155.545

Exercise left for the reader...

-

The general formula can be derived as follows.

First@RSolve[{prin[n] == (1 + int) prin[n - 1] - pay, prin[0] == loan}, prin[n], n];
First@Solve[(prin[n] /. %) == 0, pay]
(* {pay -> (int (1 + int)^n loan)/(-1 + (1 + int)^n)} *)


where pay is the payment per period, int is the interest per period, and loan is the original principal.

For the example given in the question,

pay /. % /. {n -> 52, loan -> 5000, int -> .02}
(* 155.545 *)


and the total amount needed to pay off the loan is 8088.36.

-

Using the example for an ordinary annuity from here:-

Calculating The Present And Future Value Of Annuities

The example demonstrates how a present value principal of 4329.48 is paid down by five repayments of 1000 each discounted to present value by the interest rate and period.

The calculation can be represented by the following summation:

where pis the principal, d is the periodic payment, r is the periodic interest rate and n is the number of periods.

By induction this can be converted to a standard formula.

Mathematica does the induction calculation automatically:

p = (d - d (1 + r)^-n)/r

∴ d = (p r)/(1 - (1 + r)^-n)


Substituting your figures with variations, since 2% is rather high for a weekly rate and more typical of an annual rate.

principal, p = 5000
number of periods, n = 52

for annual effective rate of interest = 2%
weekly rate, r = (1 + 0.02)^(1/52) - 1 = 0.000380892

d = (p r)/(1 - (1 + r)^-n) = 97.1275


So with a 2% annual effective rate of interest the weekly instalment is 97.13

for an annual nominal rate of 2% compounded weekly
weekly rate, r = 0.02/52 = 0.000384615

d = (p r)/(1 - (1 + r)^-n) = 97.1371


With a 2% nominal rate compounded weekly the weekly instalment is 97.14

Alternatively, with periodic (weekly) rate, r = 2% = 0.02

d = (p r)/(1 - (1 + r)^-n) = 155.545


With a weekly rate of 2% the annual effective rate is (1 + 0.02)^52 - 1 = 180% per annum and the weekly instalment is 155.55

-