Code Monkey home page Code Monkey logo

Comments (11)

yccheok avatar yccheok commented on August 16, 2024

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.

from jstock.

yccheok avatar yccheok commented on August 16, 2024

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

from jstock.

tarioch avatar tarioch commented on August 16, 2024

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.

from jstock.

yccheok avatar yccheok commented on August 16, 2024

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

img_20140311_215626

from jstock.

tarioch avatar tarioch commented on August 16, 2024

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).

from jstock.

yccheok avatar yccheok commented on August 16, 2024

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.

from jstock.

yccheok avatar yccheok commented on August 16, 2024

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.

from jstock.

tarioch avatar tarioch commented on August 16, 2024

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/

from jstock.

yccheok avatar yccheok commented on August 16, 2024

Work in progress.

https://github.com/yccheok/xirr

Still need bisect algorithm and more unit test cases.

Contribution is very much welcomed.

from jstock.

yccheok avatar yccheok commented on August 16, 2024

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.

from jstock.

tarioch avatar tarioch commented on August 16, 2024

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

from jstock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.