Say I invested \$100 every month into the S&P 500 since January 2004. If I sold out on 2019-01-11 (not considering fees or dividends), I will have invested \$18,100 and my investment would be worth \$32,331.15.

How do I calculate my average yearly return (interest rate) on this investment?

What I've tried so far

My starting equation is $$ totalValue = monthlyAmount \cdot interest^{numYears} + monthlyAmount \cdot interest^{numYears - 1/12} + \dots + monthlyAmount \cdot interest^{1/12} $$

I can then extract $monthlyAmount$ to simplify the expression:

$$ totalValue = monthlyAmount \cdot (interest^{numYears} + interest^{numYears - 1/12} + \dots + interest^{1/12}) $$

The part in the parentheses, if I'm not mistaken, seems to be the sum of a geometric sequence - where both the first term and the common ratio is $interest^{1/12}$. If so, then I can use the formula for calculating the sum of the first $n$ terms of a geometric sequence:

$$ totalValue = monthlyAmount \cdot \frac{interest^{1/12} \cdot (1-interest^{1/12})}{1-interest^{numYears}} $$

Alright, given the values in the introduction, I have an equation with a single unknown - the $interest$:

$$ 32331.15 = 100 \cdot \frac{interest^{1/12} \cdot (1-interest^{1/12})}{1-interest^{15}} $$

I gave this to WolframAlpha, and it gave me a solution of 1.074 (i.e. 7.4%). That's nice, but how do I arrive at the solution?

I'm writing a program that calculates this in the general case, so I'm ideally looking for some sort of algorithm that can be written in code.

Source of financial information: https://finance.yahoo.com/quote/%5EGSPC/history?p=%5EGSPC

  • $\begingroup$ Hint: write it out as a sum involving the rate and note that you have a geometric series. $\endgroup$ – lulu Jan 22 '19 at 23:04
  • $\begingroup$ @lulu No, because the stock price changes. $\endgroup$ – Acccumulation Jan 22 '19 at 23:07
  • $\begingroup$ @Acccumulation Why does that matter? You are looking for a single rate $r$ which would match the return over the period. $\endgroup$ – lulu Jan 22 '19 at 23:09
  • $\begingroup$ I'ver misread the problem a couple of times now, so let me state how I am currently reading it. I believe the OP is looking for the rate, $r$, such that a monthly investment of $100$ over $181$ periods would result in a total value of $32,331.15$ Thus, the first $100$ will have become $100\times (1+\frac r{12})^{181}$, the second will have grown to $100\times (1+\frac r{12})^{180}$ and so on. Is this what was intended? $\endgroup$ – lulu Jan 22 '19 at 23:14
  • $\begingroup$ @lulu yes, that's what I meant. See my update for more information $\endgroup$ – Zoltán Jan 22 '19 at 23:15

Trusting that the schedule of payments I outlined in the comments are correct, the problem comes down to the following: $$100\times \sum_{i=1}^{181}\left(1+\frac r{12}\right)^i=32,311.15$$

Now, it's possible to evaluate that sum as a rational function, but as that leads to a polynomial of degree $182$ in $r$ you'll be stuck with numerical methods anyway. Instead, I'd leave the function as it stands and work numerically. A simple binary search converges rapidly and we get $$r\approx 7.056\%$$

| cite | improve this answer | |

Considering the general case, you want to solve for $x$ the equation $$k=\frac TM=\sum_{i=1}^n(1+x)^i=\frac{(x+1) \left((x+1)^n-1\right)}{x}$$ where $T$ is the total value, $M$ the monthly amount, $n$ the number of months and $x$ the monthly interest.

As lulu explained, you need some numerical method (Newton method would be the easiest).

You can have good estimates of the solution considering that $x \ll 1$. So, let us expand the summation as a Taylor series (or use the binomial theorem) and get $$k=n+\frac{n (n+1)}{2} x+\frac{(n-1)n(n+1)}{6} n x^2+O\left(x^3\right)$$

Neglecting the higher order terms, you just face a quadratic equation in $x$ anf then $$x_0=\frac{\sqrt{24(n-1)n(n+1)k-3n^2(5 n^2-6 n-11) }-3n(n+1) } {2(n-1)n(n+1) }$$

For your example, this would give as an estimate $x=0.00626955$ corresponding to $7.52$%. Newton iterates would be

$$\left( \begin{array}{cc} n & x_n \\ 0 & 0.0062695483 \\ 1 & 0.0058852014 \\ 2 & 0.0058753116 \\ 3 & 0.0058753053 \end{array} \right)$$ and then the answer $7.050366$%.

We could have a better estimate (still at the price of a quadratic equation in $x$) using, instead of Taylor series, a simple Padé approximant. This would give $$k=\frac{n+\frac{1}{10} \left(n^2+13 n\right) x+\frac{1}{60} \left(n^3+3 n^2+20 n\right) x^2 } {1-\frac{2}{5} (n-2) x+\frac{1}{20} \left(n^2-3 n+2\right) x^2 }$$ Applied to the example, this would give as an estimate $x=0.00587785$ corresponding to $7.053$%.


We can even avoid solving quadratic equations building at $x=0$ the $[1,p]$ Padé approximant of $$\frac{(x+1) \left((x+1)^n-1\right)}{x}-k=\frac{(k-n)+a_{(p)} x}{1+\sum_{j=1}^p b_j x^j}\implies x_{(p)}=\frac{n-k}{a_{(p)} }$$

For the simplest , the required coefficient is given by $$a_{(1)}=\frac{1}{6} n (n+5)+\frac{1}{3} k (n-1)$$ $$a_{(2)}=\frac{3 n^2 (n+3)+2 (n-1) n (n+4)k+ (n-2) (n-1)k^2 } {2 n (n+5)+4 (n-1)k }$$ The formula becomes really long for $p \geq 3$ but they will be very easy to code.

Applied to the example, this would give $$x_{(1)}\approx 0.00568499\implies 6.82198\text{ %}$$ $$x_{(2)}\approx 0.00585822\implies 7.02987\text{ %}$$ $$x_{(3)}\approx 0.00587585\implies 7.05102\text{ %}$$ $$x_{(4)}\approx 0.00587561\implies 7.05073\text{ %}$$ $$x_{(5)}\approx 0.00587532\implies 7.05039\text{ %}$$

| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.