Using XIRR for Stock Returns with Midyear Purchases
Summary
The document asks how to calculate a stock’s annual return when shares are bought at different times during the year. A simple beginning-to-end portfolio return works when the position is unchanged, but a midyear purchase adds cash flow that should not be mistaken for investment gain.
The suggested approach is XIRR: find the annualized rate that equates dated investment cash flows with the ending value. The response describes this as solving for an interest rate and notes that spreadsheet tools commonly use a Newton-style numerical approximation. It points to a related explanation and a Java implementation, but provides no worked XIRR calculation or comparison with other return measures. The result therefore depends on the dates and amounts of cash flows, and it reflects a money-weighted return rather than a time-weighted measure of the stock’s performance.
Key ideas
- A midyear contribution changes the calculation of the investor’s annual return.
- XIRR uses dated cash flows and ending value to find an annualized rate.
- The method can be understood as solving for the rate that balances the cash flows.
- Spreadsheet implementations may use Newton-style numerical iteration.
- The document does not provide a worked example or compare XIRR with time-weighted returns.
Tags
Full text
# Calculate rate of return of a stock, if there is a buy transaction occurs during the middle of financial year # Calculate rate of return of a stock, if there is a buy transaction occurs during the middle of financial year 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? ## Answer by tario (score 1, accepted) https://quant.stackexchange.com/a/12937 That is what XIRR does or can you read this answer. Basically it tries to find an interest rate that works out to the same numbers. I think Excel and Google Docs use the Newton approximation http://www.mftransparency.org/calculating-interest-rates-using-newtons-method/ There's also a java implementation available on github called jxirr.
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.