Skip to content

Commit

Permalink
## Version 0.2.5
Browse files Browse the repository at this point in the history
* Default XIRR does not raise an Exception if cashflow is invalid
  • Loading branch information
tubedude committed Aug 7, 2014
1 parent b6a343e commit 3a026e5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGE_LOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Version 0.2.5

* Default XIRR does not raise an Exception if cashflow is invalid


## Version 0.2.4

* Cashflow Invalid Messages are now public.
Expand Down
8 changes: 4 additions & 4 deletions lib/xirr/cashflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(*args)
self.flatten!
end

# Check if Cashflow is invalid and raises ArgumentError
# Check if Cashflow is invalid
# @return [Boolean]
def invalid?
positives.empty? || negatives.empty?
Expand Down Expand Up @@ -50,7 +50,7 @@ def irr_guess
# @param method [Symbol]
# @return [Float]
# Finds the XIRR according to the method provided. Default to Bisection
def xirr(guess = nil, method = Xirr.config.default_method)
def xirr_with_exception(guess = nil, method = Xirr.config.default_method)
if valid?
choose_(method).send :xirr, guess
else
Expand All @@ -62,11 +62,11 @@ def xirr(guess = nil, method = Xirr.config.default_method)
# @param guess [Float]
# @param method [Symbol]
# @return [Float]
def xirr_no_exception(guess = nil, method = Xirr.config.default_method)
def xirr(guess = nil, method = Xirr.config.default_method)
if invalid?
BigDecimal.new(0, Xirr::PRECISION)
else
xirr(guess, method)
xirr_with_exception(guess, method)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/xirr/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Xirr
# Version of the Gem
VERSION = "0.2.4"
VERSION = "0.2.5"
end
6 changes: 5 additions & 1 deletion test/test_cashflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
assert_raises(ArgumentError) { @cf.xirr(nil, :no_method) }
end

it 'has an Internal Rate of Return on Bisection Method' do
it 'has an Internal Rate of Return on default Method' do
assert_equal '0.225683'.to_f, @cf.xirr
end

it 'has an Internal Rate of Return on default Method' do
assert_equal '0.225683'.to_f, @cf.xirr(nil, :bisection)
end

it 'has an Internal Rate of Return on Bisection Method using a Guess' do
assert_equal '0.225683'.to_f, @cf.xirr(0.15)
end
Expand Down

0 comments on commit 3a026e5

Please sign in to comment.