I'm trying to understand how the performance of financial investments are measuring when the asset has multiple points of investment.
For example, say I invest $1000 in a stock. After 6 months, it's worth $1200. At this point, I invest an additional $2000, for a total value of $3200. If after an additional 6 months, the entire investment is worth $4000, how would I calculate the overall yield or effective interest rate? Normally, you'd do (final-initial)/initial, but in this example there are multiple initial values, but only one final. How would I reconcile this?
EDIT: Note, some values are supposed to be dollar amounts, but for some reason the site's markup is interpreting the dollar sign as the start of italics...
EDIT: Escaped dollar amounts (thanks KennyTM).
Figure: Cash Flows of -1000, -2000 and +4000 dollars
Excel has a function for this called IRR. To roll your own you just need to find the rate of return that produces the final value. You have investments i1, i2, ... that have been in the account for m1, m2, ... months. For a given return per month you should have i1*(1+r)^m1 + i2*(1+r)^m2 + ... Now just search for r that makes this equal to the final value. For some patterns of cash flow, there may be multiple values of r that satisfy the equation. You can use your favorite root finder, but bisection is quite robust.