marksweston / finance

A library for financial calculations in Ruby
https://rubygems.org/gems/finance
Other
221 stars 91 forks source link

xirr bug? #31

Open josh-m-sharpe opened 10 years ago

josh-m-sharpe commented 10 years ago

Good Doc's xirr() thinks the result should be: 0.1877607042

The result should certainly be positive.

DATA:
5/3/2010   --   -3984.732
8/12/2010  --   -1877.98
6/2/2014   --    11684.915242
2.0.0-p353 :044 > trans = []
 => []
2.0.0-p353 :045 > trans << Finance::Transaction.new(-3984.732, date: Date.civil(2010, 5, 3).to_time)
 => [Transaction(-3984.732)]
2.0.0-p353 :046 > trans << Finance::Transaction.new(-1877.98, date: Date.civil(2010, 8, 12).to_time)
 => [Transaction(-3984.732), Transaction(-1877.98)]
2.0.0-p353 :047 > trans << Finance::Transaction.new(11684.915242, date: Date.civil(2014, 6, 2).to_time)
 => [Transaction(-3984.732), Transaction(-1877.98), Transaction(11684.915242)]
2.0.0-p353 :048 > trans.xirr.apr.to_f
 => -2.212298586260735

untitled_spreadsheet_-_google_sheets_and_1__tmux

tubedude commented 10 years ago

@crankharder why don't you give a try on my branch: https://github.com/tubedude/finance The error appears when you use 1.0 as guess (which is the standard in this release). But you should get to the correct answer by using a guess of 0.1:

trans.xirr(1).apr.to_f # => -2.212298586260735
trans.xirr(0.1).apr.to_f  # => 0.1882953622624719
josh-m-sharpe commented 10 years ago

@tubedude confirmed that your branch fixes the issue.

My other test cases didn't change either.

I thought it was odd that the 'transactions' param wasn't being used.

weshatheleopard commented 9 years ago

See Issue #38. It's a bug in the search value function. I provided the fix (#39).

tubedude commented 9 years ago

Good catch!