xirr 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGE_LOG.md +5 -0
- data/lib/xirr/bisection.rb +4 -3
- data/lib/xirr/version.rb +1 -1
- data/test/test_cashflow.rb +10 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcb7b25e26618e39ecb5c1e8b38ad211be4edc73
|
4
|
+
data.tar.gz: 0c845e053436159125d5b8bedf2dd08e8243cdbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec7a9821be4721669be0d656864b1d7db88f5d0fc1ec4306b0f190d5b2d2143f0b98ebe338589f3de60af6f07f9077a9a19b9022ee3d64f0aeec81f94b1885b7
|
7
|
+
data.tar.gz: dcf0c3570dbc34e6595cfd3f0e1976ec4f2bd876e1a9ad11dfebdc52b75494199a55f3b4dabb12185b07d36abe79c1a987453a2ebe3889fd4bc756bc00bc2253
|
data/CHANGE_LOG.md
CHANGED
data/lib/xirr/bisection.rb
CHANGED
@@ -13,6 +13,7 @@ module Xirr
|
|
13
13
|
# Initial values
|
14
14
|
left = [BigDecimal.new(-0.99, Xirr::PRECISION), cf.irr_guess].min
|
15
15
|
right = [BigDecimal.new(9.99, Xirr::PRECISION), cf.irr_guess + 1].max
|
16
|
+
@original_right = right
|
16
17
|
midpoint ||= cf.irr_guess
|
17
18
|
runs = 0
|
18
19
|
|
@@ -29,7 +30,7 @@ module Xirr
|
|
29
30
|
end
|
30
31
|
|
31
32
|
# If enabled, will retry XIRR with NewtonMethod
|
32
|
-
if Xirr::FALLBACK && right_limit_reached?(
|
33
|
+
if Xirr::FALLBACK && right_limit_reached?(midpoint)
|
33
34
|
return NewtonMethod.new(cf).xirr
|
34
35
|
end
|
35
36
|
|
@@ -43,8 +44,8 @@ module Xirr
|
|
43
44
|
# @param midpoint [BigDecimal]
|
44
45
|
# @return [Boolean]
|
45
46
|
# Checks if result is the right limit.
|
46
|
-
def right_limit_reached?(
|
47
|
-
(
|
47
|
+
def right_limit_reached?(midpoint)
|
48
|
+
(@original_right - midpoint).abs < Xirr::EPS
|
48
49
|
end
|
49
50
|
|
50
51
|
# @param left [BigDecimal]
|
data/lib/xirr/version.rb
CHANGED
data/test/test_cashflow.rb
CHANGED
@@ -23,7 +23,7 @@ describe 'Cashflows' do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'has an Internal Rate of Return on Bisection Method using a Guess' do
|
26
|
-
|
26
|
+
assert_in_delta 0.225683, @cf.xirr(0.15).to_f, 0.000002
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'has an Internal Rate of Return on Newton Method' do
|
@@ -44,12 +44,16 @@ describe 'Cashflows' do
|
|
44
44
|
@cf << Transaction.new(6000, date: '1995-01-01'.to_date)
|
45
45
|
end
|
46
46
|
|
47
|
+
it 'has a sum of its transactions' do
|
48
|
+
assert_equal '5600'.to_f, @cf.sum
|
49
|
+
end
|
50
|
+
|
47
51
|
it 'has an Internal Rate of Return on Bisection Method' do
|
48
52
|
assert_equal '0.225683'.to_f, @cf.xirr
|
49
53
|
end
|
50
54
|
|
51
55
|
it 'has an Internal Rate of Return on Bisection Method using a Guess' do
|
52
|
-
|
56
|
+
assert_in_delta 0.225683, @cf.xirr(0.15).to_f, 0.000002
|
53
57
|
end
|
54
58
|
|
55
59
|
it 'has an Internal Rate of Return on Newton Method' do
|
@@ -73,6 +77,10 @@ describe 'Cashflows' do
|
|
73
77
|
assert_equal '22.352206 '.to_f, @cf.xirr
|
74
78
|
end
|
75
79
|
|
80
|
+
it 'has a sum of its transactions' do
|
81
|
+
assert_equal '-2000000'.to_f, @cf.sum
|
82
|
+
end
|
83
|
+
|
76
84
|
it 'has an Internal Rate of Return on Newton Method' do
|
77
85
|
assert_equal '22.352206 '.to_f, @cf.xirr(nil, :newton_method)
|
78
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xirr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tubedude
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|