Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add annual return/xirr to portfolio #7

Open
tarioch opened this issue Feb 16, 2014 · 11 comments
Open

Add annual return/xirr to portfolio #7

tarioch opened this issue Feb 16, 2014 · 11 comments
Assignees

Comments

@tarioch
Copy link

tarioch commented Feb 16, 2014

I would really love if the portfolio view would show the annual return as this would help compare between different investments that have been taken for different durations.

@yccheok
Copy link
Owner

yccheok commented Feb 18, 2014

Hi tarioch,

Yes. This is in fact one of my top wished feature. I would like to know, what is my return of investment in yearly basic. i.e., am I getting 20% return every year?

To calculate return,

net worth end of the year - net worth beginning of the year

To calculate net worth, we need to take consideration into

  • Stock holding value
  • Profit generated from stock sales
  • Received dividend

Thing doesn't straight forward. We need some proper planning before kick start on this feature.

@yccheok
Copy link
Owner

yccheok commented Feb 18, 2014

Here's the trello card : https://trello.com/c/E0pvlWqT

@tarioch
Copy link
Author

tarioch commented Feb 18, 2014

I found a java implementation for xirr, might come in handy: https://github.com/ept/jxirr

Correct me if I'm wrong but what works quite well is every transaction is listed with the value, e.g.

-1000 buy stock
+200 dividend
+500 sell stock
-1000 buy stock
+2000 current stock value

(internal transactions such as splits, direct reinvestment and so on can be ignored)

now using the dates of the transactions, using xirr on this works quite well for me in a spreadsheet.

@yccheok
Copy link
Owner

yccheok commented Mar 11, 2014

In fact, this is one of my top wishlist features. My ideal case is drawn in the following picture.

img_20140311_215626

@tarioch
Copy link
Author

tarioch commented Mar 14, 2014

Here are some more thoughts and a possible way to do it.

xirr takes into account the actual dates of value relevant actions and computes an interest rate, basically it tells me if, instead of investing in a stock, I would have put the same money transactions into an account, what would have been the interest rate of the account.

Could your chart be done like this:

Dividend gain rate
xirr with
-buy transaction: cash value
-sell transaction: purchase value (not cash value)
-not directly reinvested dividend: cash value
-purchase value at end (not market value)

That way only dividend profits should be taken into account

Sales gain rate
xirr with
-buy transaction: cash value
-sell transaction: cash value
-not directly reinvested dividend: ignore
-purchase value at end (not market value)

That way only sales gains should be taken into account

Paper gain rate
xirr with
-buy transaction: cash value
-sell transaction: purchase value (not cash value)
-not directly reinvested dividend: ignore
-market value at end

That way only paper profit should be taken into account

I would also find it great if besides the yearly values, an overall annualized value would be available (given the algorithm above, the only change would be to take all transactions instead of only the ones from one year).

@yccheok yccheok self-assigned this Jul 2, 2014
@yccheok
Copy link
Owner

yccheok commented Jul 6, 2014

Hi @tarioch,

Now, I just want to kick start this very exciting feature :)

I came across some obstacle while implementing it (I don't have any format financial or quantitative background)

http://quant.stackexchange.com/questions/12936/calculate-rate-of-return-of-a-stock-if-there-is-a-buy-transaction-occurs-during

Would you like to participate in such discussion?

Thanks.

@yccheok
Copy link
Owner

yccheok commented Jul 8, 2014

Hi @tarioch ,

After spending a few hours studying starting from http://www.mathsisfun.com/money/internal-rate-return.html, I can get a rough understanding on NPV, IRR & XIRR.

Code implementation shouldn't be much trouble, after looking at your pointer on those implementation (Java at GitHub, Stackoverflow....) But, I will surely spend time looking at StackOverflow discussion, as there seems to be edge case where Newton method doesn't work. We need to fall back to BisectionMethod in those edge case. jxirr might not handle those cases (I just did a rough search on keyword "bisection"). But, it is still too early to judge till I run their unit test.

What is more important is, I need to ensure my understanding on this subject is more or less accurate. I got some doubt in my mind still. Do you mind to take a look? http://quant.stackexchange.com/questions/12974/is-there-any-relationship-between-investment-return-of-a-stock-for-individual-y

Thank you.

@tarioch
Copy link
Author

tarioch commented Jul 8, 2014

The reply you got looks good.

Wikipedia also has a nice article about the bisect algorithm
http://en.wikipedia.org/wiki/Bisection_method

And here's an example implementation for xirr
http://puneinvestor.wordpress.com/2013/10/01/calculate-xirr-in-ruby-bisection-method/

@yccheok
Copy link
Owner

yccheok commented Jul 10, 2014

Work in progress.

https://github.com/yccheok/xirr

Still need bisect algorithm and more unit test cases.

Contribution is very much welcomed.

@yccheok
Copy link
Owner

yccheok commented Jul 13, 2014

Hi @tarioch,

While implementing, I came across a roadblock, while trying to break down yearly XIRR into different segments.

Would you mind to take a look http://quant.stackexchange.com/questions/14013/break-down-xirr-to-different-segments

Also, I tried to understand your previous thread

Dividend gain rate
xirr with
-buy transaction: cash value
-sell transaction: purchase value (not cash value)
-not directly reinvested dividend: cash value
-purchase value at end (not market value)

I don't understand what do you mean by
-sell transaction: purchase value (not cash value)
-purchase value at end (not market value)

I would be very much appreciated, if you could provide an example.

Thank you.

@tarioch
Copy link
Author

tarioch commented Jul 13, 2014

My thought is to ignore all the other profits. So when looking at dividend profits you're not interested in sales or paper profits. Therefore I cancel them out by using the original purchase price when selling them.

e.g.

buy 1000 for 1$ get dividend of 100$ and sell for 2$

Dividend profit would be:

-1000
+100
+1000

vs total profits

-1000
+100
+2000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants