Currently, I'm implementing a feature of an open source project (https://github.com/yccheok/jstock/issues/7), which requires me to calculate the rate of return of a stock.
Let's take the following scenario.
User purchased 1000 units stock with unit price 1 dollar at 1st January 2013. He didn't perform any sell transaction & buy transaction in between. At 31st December 2013, the stock price reached 2 dollar.
The rate of return of the stock for year 2013 is 100%
(Value of investment at 31st December 2013 - Cost of investment at 1st January 2013) / (Cost of investment at 1st January 2013) * 100% (1000 * $2 - 1000 * $1) / (1000 * $1) * 100% = 100%
But, what if the user had purchased another 1000 units of same stock with unit price 1 dollar at 1st March 2013. What should be the rate of return of the stock for year 2013?