Interest deposited before it is calculated

59 Views Asked by At

I have an array of periods, with the number indicating a balance at the end of the corresponding period. For example,

  balances: [0, 0,-10, 0, 0]

indicates that at period index 2, the balance is -10.

When the balance is negative, there is an interest charge in the following period. In the above example, if the interest is 10%, then there would be a charge of 1 after index 2.

   balances: [0, 0, -10,  0, 0]
   interest: [0, 0,   0,  1, 0]

What I want to do is split that interest with the previous periods to obtain something like

  interest: [0.25, 0.25, 0.25, 0.25, 0]

But this is not exact because when reaching index 2, there is 0.75 accumulated. Therefore, the interest is not calculated over -10, but -9.25 instead. So the interest will be 0.925 instead of 1, and the last interest value should be calculated as

      0.925 - 0.75 = 0.175
=>
      interest: [0.25, 0.25, 0.25, 0.175, 0]

So Is there some formula that would determine equal interest payments for all four indexes based on the interest and the balance at a specific period?

There may be interest accumulated as well for positive balances (e.g. interest on the .50 accumulated in the 2 first indexes) but the solution does not have to consider that.

1

There are 1 best solutions below

0
On

Posting the question had me think some more. So I risk an answer (math are so far in the past..)

Let x be one of the 4 equal payments. Let y be the number (10) on which the interest z (0.1) is calculated.

The actual total interest may be calculated as

  z(y - 3x)

Therefore

  4x = z(y - 3x)

  4x = zy - 3zx

  4x + 3zx = zy

  x(4 + 3z) = zy

  x = zy / (4 + 3z)

Using the numbers above, we can verify:

  x =  (0.1 * 10) / (4 + (3 * 0.1))

  x = 1 / 4.3 = 0.23

Interest is therefore calculated as

   0.1 * (10 - 0.69) = 0.1 * 9.31 = 0.931

We can dived by 4 to obtain the equal payments:

  0.931 / 4 = 0.23

The formula can therefore be expressed as follow, using "n" as the number of payments (4 here):

  x = zy / (n + z(n-1))

It seems to work with this example.