# Compounding Formula (and its reverse)

I've written a program in which I'm using a compounding calculator to determine an output. But without a formula I'm having trouble reversing the calculation.

Given a compounding problem whose variables are:

i: initial amount (eg: 2000),
d: divisor (each round, eg: 3),
r: return amount (eg: 0.15),
f: final amount (the return of all divisions)


Note: Unlike interest formulas, we don't know the number of "rounds" or times it will be compounded because that's determined by how much the return rate is gives us back each round.

It's simple enough given i, r, and d to calculate f with this code:

for i >= d {
f += i/d
i = i*r
}


Example might be:

i = 2134
d = 4
r = 0.15

f = 627
some ancillary outputs:
- the amount returned from r: 376 (17.62% of input)
- i remainder from final division: 2


I don't know how to express this in a mathematic formula, so the iterative approach is all I can do. And because of that, given r, d, and f, I cannot figure out how to calculate i which is important to the problem at hand.

• I don't understand what a round is. If the initial amount is $1000$ the rate is $10\%\ (.10)$ and there are $2$ rounds, what is the final amount? – saulspatz May 17 at 0:22
• $i \approx fd(1-r)+1$ may be quite close especially since you seem to be rounding. So with $f=627,d=4,r=0.15$ you might estimate $i \approx 2132.8$ which is not far from $2134$ – Henry May 17 at 0:33
• @saulspatz The rounds continue until the finalizing condition (you can no longer divide i/d. So there's no ability to say "there's two rounds" as the number of rounds is a function of how much gets returned in each round. – aarondl May 17 at 1:10
• @Henry I'm using a floor() to get my answers in my code, I didn't show that (sorry). That's actually very close and may be a good enough estimate for my purposes. I'll experiment with it! – aarondl May 17 at 1:12
• @Henry Thanks for your reply. I've poked at it a bit and it seems fit enough. I pad the output numbers just a little and it works. Thanks! – aarondl May 18 at 1:04