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.