xirr 0.7.0 → 0.7.1
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/.ruby-version +1 -1
- data/CHANGE_LOG.md +6 -0
- data/README.md +11 -1
- data/lib/xirr/base.rb +0 -1
- data/lib/xirr/cashflow.rb +4 -2
- data/lib/xirr/version.rb +1 -1
- data/test/test_cashflow.rb +68 -1
- data/xirr.gemspec +3 -3
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1281b23c8069cbd5bf16cecf50ae129ea2d4bab31c4c5e89906d970f6e15b7d
|
4
|
+
data.tar.gz: 2431eed14a1de0deb4694621eb8136b10b53c6ce44d888682101e9ca04e46aca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6e38c8051ab43168cfafb1442fc897a96e9e25c62b55eb95320cc8f22fca57421ac360626ade4764115c17a4c7aa0fca84568f8d03238d78bc5bb3a123039cf
|
7
|
+
data.tar.gz: 4b450e70ef5d58150e0b9cf416f9246e67b8fa015449f6697042dafe49b49e9114065bc6f711dafa41c5e2bcbff7882ee87d2a77ae55046c89c55aa7d81f6b90
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.3
|
1
|
+
3.3.1
|
data/CHANGE_LOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
+
[](https://travis-ci.org/tubedude/xirr)[](https://coveralls.io/r/tubedude/xirr?branch=master)[](https://codeclimate.com/github/tubedude/xirr)
|
2
|
+
|
3
|
+
## NOTE
|
4
|
+
|
5
|
+
This gem is not very well maintained. You can check out a new and properlly maintained library for fast XIRR calculation:
|
6
|
+
https://github.com/fintual-oss/fast-xirr
|
7
|
+
|
8
|
+
I haven't tried it yet, but I liked two things:
|
9
|
+
- All calculations are underlying C ( = Fast )
|
10
|
+
- Bad results return NaN ( = you can decide how to deal with it )
|
11
|
+
|
1
12
|
# Xirr
|
2
|
-
[](https://travis-ci.org/tubedude/xirr)[](https://coveralls.io/r/tubedude/xirr?branch=master)[](https://codeclimate.com/github/tubedude/xirr)[](https://ebertapp.io/github/tubedude/xirr)
|
3
13
|
|
4
14
|
This is a gem to calculate XIRR on Bisection Method or Newton Method.
|
5
15
|
|
data/lib/xirr/base.rb
CHANGED
data/lib/xirr/cashflow.rb
CHANGED
@@ -49,8 +49,10 @@ module Xirr
|
|
49
49
|
# @return [Float]
|
50
50
|
def irr_guess
|
51
51
|
return @irr_guess = 0.0 if periods_of_investment.zero?
|
52
|
-
@irr_guess =
|
53
|
-
|
52
|
+
return @irr_guess = 0.0 if multiple <= 0
|
53
|
+
|
54
|
+
@irr_guess = valid? ? ((multiple**(1.0 / periods_of_investment)) - 1).round(3) : 0.0
|
55
|
+
@irr_guess.infinite? ? 0.0 : @irr_guess
|
54
56
|
end
|
55
57
|
|
56
58
|
# @param guess [Float]
|
data/lib/xirr/version.rb
CHANGED
data/test/test_cashflow.rb
CHANGED
@@ -84,7 +84,7 @@ describe 'Cashflows' do
|
|
84
84
|
assert_equal '22.352207 '.to_f, @cf.xirr(method: :bisection)
|
85
85
|
end
|
86
86
|
|
87
|
-
it '
|
87
|
+
it 'it won\'t fall back if method provided' do
|
88
88
|
@cf.xirr method: :bisection
|
89
89
|
assert_equal false, @cf.fallback
|
90
90
|
end
|
@@ -344,4 +344,71 @@ describe 'Cashflows' do
|
|
344
344
|
end
|
345
345
|
end
|
346
346
|
end
|
347
|
+
|
348
|
+
describe 'irr_guess' do
|
349
|
+
it 'Basic Scenario with Simple Positive Cash Flows' do
|
350
|
+
@cf = Cashflow.new
|
351
|
+
@cf << Transaction.new(1000, date: '2000-01-01'.to_date)
|
352
|
+
@cf << Transaction.new(-1200, date: '2001-01-01'.to_date)
|
353
|
+
assert_equal '0.2'.to_f, @cf.irr_guess
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'Zero Periods of Investment' do
|
357
|
+
@cf = Cashflow.new
|
358
|
+
@cf << Transaction.new(1000, date: '2000-01-01'.to_date)
|
359
|
+
@cf << Transaction.new(-1000, date: '2000-01-01'.to_date)
|
360
|
+
assert_equal '0.0'.to_f, @cf.irr_guess
|
361
|
+
end
|
362
|
+
|
363
|
+
it 'Negative Multiple' do
|
364
|
+
@cf = Cashflow.new
|
365
|
+
@cf << Transaction.new(1000, date: '2000-01-01'.to_date)
|
366
|
+
@cf << Transaction.new(-2000, date: '2000-01-01'.to_date)
|
367
|
+
assert_equal '0.0'.to_f, @cf.irr_guess
|
368
|
+
end
|
369
|
+
|
370
|
+
it 'No Cash Flows' do
|
371
|
+
@cf = Cashflow.new
|
372
|
+
assert_equal '0.0'.to_f, @cf.irr_guess
|
373
|
+
end
|
374
|
+
|
375
|
+
it 'Multiple Positive Cash Flows and Large Investment Period' do
|
376
|
+
@cf = Cashflow.new
|
377
|
+
@cf << Transaction.new(1000, date: '2000-01-01'.to_date)
|
378
|
+
@cf << Transaction.new(-100, date: '2010-01-01'.to_date)
|
379
|
+
@cf << Transaction.new(-100, date: '2020-01-01'.to_date)
|
380
|
+
assert_equal '0.072'.to_f, @cf.irr_guess
|
381
|
+
end
|
382
|
+
|
383
|
+
it 'Very Small Periods of Investment' do
|
384
|
+
@cf = Cashflow.new
|
385
|
+
@cf << Transaction.new(1000, date: '2000-01-01'.to_date)
|
386
|
+
@cf << Transaction.new(-500, date: '2000-01-02'.to_date)
|
387
|
+
assert_equal '0.0'.to_f, @cf.irr_guess
|
388
|
+
end
|
389
|
+
|
390
|
+
it 'Complex Cash Flows' do
|
391
|
+
@cf = Cashflow.new
|
392
|
+
@cf << Transaction.new(1000, date: '2000-01-01'.to_date)
|
393
|
+
@cf << Transaction.new(-500, date: '2001-01-01'.to_date)
|
394
|
+
@cf << Transaction.new(-300, date: '2002-01-01'.to_date)
|
395
|
+
@cf << Transaction.new(-200, date: '2003-01-01'.to_date)
|
396
|
+
assert_equal '0.195'.to_f, @cf.irr_guess
|
397
|
+
end
|
398
|
+
|
399
|
+
it 'Only Negative Cash Flows' do
|
400
|
+
@cf = Cashflow.new
|
401
|
+
@cf << Transaction.new(-1000, date: '2000-01-01'.to_date)
|
402
|
+
@cf << Transaction.new(-500, date: '2001-01-01'.to_date)
|
403
|
+
assert_equal '0.0'.to_f, @cf.irr_guess
|
404
|
+
end
|
405
|
+
|
406
|
+
it 'Positive and Negative Cash Flows Spread Over Different Periods' do
|
407
|
+
@cf = Cashflow.new
|
408
|
+
@cf << Transaction.new(500, date: '2000-01-01'.to_date)
|
409
|
+
@cf << Transaction.new(-100, date: '2005-01-01'.to_date)
|
410
|
+
@cf << Transaction.new(-400, date: '2010-01-01'.to_date)
|
411
|
+
assert_equal '0.033'.to_f, @cf.irr_guess
|
412
|
+
end
|
413
|
+
end
|
347
414
|
end
|
data/xirr.gemspec
CHANGED
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.required_ruby_version = '>=
|
21
|
+
spec.required_ruby_version = '>=3.1'
|
22
22
|
|
23
|
-
spec.add_dependency 'activesupport', '>=
|
23
|
+
spec.add_dependency 'activesupport', '>= 6.1', '< 8'
|
24
24
|
|
25
|
-
spec.add_development_dependency 'activesupport', '>=
|
25
|
+
spec.add_development_dependency 'activesupport', '>= 6.1', '< 8'
|
26
26
|
spec.add_development_dependency 'minitest', '~> 5.14'
|
27
27
|
spec.add_development_dependency 'coveralls', '~> 0.8'
|
28
28
|
spec.add_development_dependency 'bundler', '>= 2.2'
|
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.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tubedude
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,40 +16,40 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.1'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '8'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '6.1'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '8'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activesupport
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
39
|
+
version: '6.1'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
42
|
+
version: '8'
|
43
43
|
type: :development
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
49
|
+
version: '6.1'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
52
|
+
version: '8'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: minitest
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -148,14 +148,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
148
148
|
requirements:
|
149
149
|
- - ">="
|
150
150
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
151
|
+
version: '3.1'
|
152
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
153
|
requirements:
|
154
154
|
- - ">="
|
155
155
|
- !ruby/object:Gem::Version
|
156
156
|
version: '0'
|
157
157
|
requirements: []
|
158
|
-
rubygems_version: 3.5.
|
158
|
+
rubygems_version: 3.5.23
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: Calculates XIRR (Bisection and Newton method) of a cashflow
|