Yearly contribution to reach given stock (compound interest) I'm working on a calculator to compute the final stock given a yearly contribution (either a fixed contribution or with a linear growth). The user provides the contribution for the first year, if he wants to increase this contribution yearly (the growth value is fixed, the user only chooses if he wants it or not), the interest rate and the number of years (compounding frequency is always yearly).
Calculate the final stock given those imputs isn't difficult, I simply use the Compound Interest formula for each year from $zero$ to $t$ and accumulate the results:
$$F = Py(1+i)^t$$
Where:
$F =$ Final value
$Py =$ Contribution on year $y$ (same each year or increased by a percentage)
$i =$ Interest rate
$t =$ Remaining years
But I don't have a clue about how to calculate (or at least approximate) the other way around. I.e. calculate the needed yearly contribution to reach a desired final stock, given the interest rate and the number of years, either with fixed contributions or increasing ones.
 A: Let g be the (constant) growth rate and  $G=1+g$ the growth factor. And let r be the interest rate and $q=1+r$. Then the future value of the growing contributions  is
$F_n=C\cdot  q^{n-1}+ C\cdot q^{n-2}\cdot G+\ldots + C\cdot q\cdot G^{n-2}+C\cdot  G^{n-1}$
$C\cdot  q^{n-1}:$ The first contribution has to be compounded n-1 times and no growth.
$C\cdot  G^{n-1}:$ The n-th contribution has grown n-1 times and no compounding.
$F_n=C\cdot \left[  q^{n-1}+  q^{n-2}\cdot G+\ldots + q\cdot G^{n-2}+  G^{n-1} \right]$
$q\cdot F_n=C\cdot \left[  q^{n}+  q^{n-1}\cdot G+\ldots + q^2\cdot G^{n-2}+ q \cdot G^{n-1} \right] \quad \quad \quad (1)$
$G\cdot F_n=C\cdot \left[ \ \ \quad  q^{n-1}\cdot G+  q^{n-2}\cdot G^2+\ldots + q\cdot G^{n-1}+  G^{n} \right] \quad (2)$
Substracting (2) from (1)
$(q-G)\cdot F_n=C\cdot (q^n-G^n)$
$\boxed{F_n=C\cdot\frac{q^n-G^n}{q-G}}$
A: Your formula is $\sum_{t=0}^n P_y(1+ i)^t$.  That is the same as the "geometric sum" $\sum_{t= 0}^n ar^t$ for which a formula is known:  $\frac{a(1- r^{n+1}}{1- r}$.    Here $a= P_y$ and r= 1+ I so that becomes
$F=\frac{P_y(1- (1+ i)^n)}{i}$.  So $P_y= \frac{Pi}{1- (1+i)^{n+1}}$
A: There is an exact formula for this (or rather, two formulas, one with the "growth value" and one without) which you might be able to deduce from the answer already posted. But here is another way of looking at the problem:
Consider the case where the user opts for a "growth value", since
you can easily deduce the "no growth value" solution by setting the
growth value to zero.
Now observe that the contribution in each successive
year is proportional to the initial amount.
That is, suppose two users try your program, and one enters $P_0 = 100$
and the other enters $P_0 = 200$.
It is easy to see (and not hard to prove) that in each successive year,
the second user's contribution will be exactly twice as much as the
first user's contribution.
(The exact formula is of the form $P_t = P_0 k^t$, where $k$ is a factor determined by the "growth value".)
Furthermore, as you already know, the final value of each year's contribution
is proportional to that year's contribution.
That is $F_y$ (final value for year $y$) is proportional to $P_y$.
But if $F_y$ is proportional to $P_y$, and $P_y$ is proportional to $P_0$,
then $F_y$ is proportional to $P_0$.
Moreover, since this is true for each of the $F_y$ individually, it is also
true for their sum.
So the final total, at the end, will be exactly proportional to $P_0$.
So one way to solve your problem without working out the complete
closed-form equation for the total at the end,
is simply to try the input $P_0 = 1$ and see what total you get at the end.
Then scale this up as needed to achieve the desired total.
For example, suppose that when you set $P_0 = 1$, the sum of all your
$F_y$, that is, your final stock, is $10$. 
Then what $P_0$ will produce a final stock of $20$? 
What if you want a final stock of $100$, then what should be $P_0$?
The same trick works if you find that the final stock is $15.31456$ when
$P_0 = 1$, and you want to find $P_0$ that will make the final stock be $5000$.
The only difference is that the answer would not be so easy to guess by
mental arithmetic as it was for my first couple of examples.
