This gem is not very well maintained. You can check out a new and properlly maintained library for fast XIRR calculation: https://github.com/fintual-oss/fast-xirr
I haven't tried it yet, but I liked two things:
- All calculations are underlying C ( = Fast )
- Bad results return NaN ( = you can decide how to deal with it )
This is a gem to calculate XIRR on Bisection Method or Newton Method.
Add this line to your application's Gemfile:
gem 'xirr'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install xirr
include Xirr
cf = Xirr::Cashflow.new
cf << Xirr::Transaction.new(-1000, date: '2014-01-01'.to_date)
cf << Xirr::Transaction.new(-2000, date: '2014-03-01'.to_date)
cf << Xirr::Transaction.new( 4500, date: '2015-12-01'.to_date)
cf.xirr
# 0.25159694345042327 # [BigDecimal]
flow = []
flow << Xirr::Transaction.new(-1000, date: '2014-01-01'.to_date)
flow << Xirr::Transaction.new(-2000, date: '2014-03-01'.to_date)
flow << Xirr::Transaction.new( 4500, date: '2015-12-01'.to_date)
cf = Xirr::Cashflow.new(flow: flow)
cf.xirr
# intializer/xirr.rb
Xirr.configure do |config|
config.eps = '1.0e-12'
config.days_in_year = 365.25
end
http://rubydoc.info/github/tubedude/xirr/master/frames
Ruby:
- 2.2.1
- 2.3
- 2.4
- 2.7
ActiveSupport:
- 4.2
- 5
- 6
- 7
http://puneinvestor.wordpress.com/2013/10/01/calculate-xirr-in-ruby-bisection-method/ https://github.com/wkranec/finance
- Fork it ( https://github.com/tubedude/xirr/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Run specs (
rake default
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request