xirr_newton_calculator 0.0.5 → 0.0.6
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 +15 -0
- data/lib/xirr_newton_calculator.rb +15 -15
- metadata +4 -8
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MzQ1ZjFmMGIzYjY0ODQ3MjA5MzYyYmYxOTc4MGIzNWI2YTBiMzZiMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YmVkYjVlZWZhMGIzMjBiYTFlMjdmNjg2NjFhNTVkZTNlZTE3MDYzYg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTBlYmRhMjY2MDk5MGYwM2EwZjlmMDgxMjk1YTY4ZTZlNmIzMWU2YTgxMjYy
|
10
|
+
MDcyYjNhYjYyN2M3M2YxM2E4YjBlOTVhYTE0ZGU4Y2RiYjM2MzQwNzlhMmIz
|
11
|
+
ZTAwYzU1NmJiNDA1ODkxNWM1YjQ1YTNmZjQ2NDMyNTNiMjBjMmU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OWI4OWMwZmRkMjZlNjZkZjQxNTUxMzBiMDg4NzUwMDYzYmIxNDZmZjFmMGU4
|
14
|
+
MDAzMTQ0NTkxZTc0NTQzYjk2NGVjNjdlZTVmMzRlNzU1NWJhN2E3NzRlZjQ4
|
15
|
+
Y2RjNDhkMWZmMDgzZGYyZDk5MzNlNzhlMDVkN2RlODg3NDUwYmI=
|
@@ -20,10 +20,10 @@ class XirrNewtonCalculator
|
|
20
20
|
@max_iteration = max_iteration
|
21
21
|
end
|
22
22
|
|
23
|
-
def calculate
|
23
|
+
def calculate(eps = EPS)
|
24
24
|
f(@x_n)
|
25
25
|
@max_iteration.times do
|
26
|
-
break if @f_xn.abs <
|
26
|
+
break if @f_xn.abs < eps
|
27
27
|
@x_n = next_value(@x_n)
|
28
28
|
end
|
29
29
|
@x_n
|
@@ -31,21 +31,21 @@ class XirrNewtonCalculator
|
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
# Argument X_n
|
35
|
+
# Returns X_n+1
|
36
|
+
def next_value(x)
|
37
|
+
x - f(x) / dfdx(x)
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
def dfdx(x)
|
41
|
+
@flows[1..-1].inject(0) do |result, flow|
|
42
|
+
result += flow[:amount] * (-flow[:diff_date]) / ((1.0 + x) ** (flow[:diff_date] + 1.0))
|
43
|
+
end
|
43
44
|
end
|
44
|
-
end
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
def f(x)
|
47
|
+
@f_xn = @flows.inject(0) do |result, flow|
|
48
|
+
result += flow[:amount] / ((1.0 + x) ** flow[:diff_date])
|
49
|
+
end
|
49
50
|
end
|
50
|
-
end
|
51
51
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xirr_newton_calculator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- JP Colomer
|
@@ -14,7 +13,6 @@ dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -39,26 +36,25 @@ files:
|
|
39
36
|
homepage:
|
40
37
|
licenses:
|
41
38
|
- MIT
|
39
|
+
metadata: {}
|
42
40
|
post_install_message:
|
43
41
|
rdoc_options: []
|
44
42
|
require_paths:
|
45
43
|
- lib
|
46
44
|
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
45
|
requirements:
|
49
46
|
- - ! '>='
|
50
47
|
- !ruby/object:Gem::Version
|
51
48
|
version: '1.9'
|
52
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
50
|
requirements:
|
55
51
|
- - ! '>='
|
56
52
|
- !ruby/object:Gem::Version
|
57
53
|
version: '0'
|
58
54
|
requirements: []
|
59
55
|
rubyforge_project:
|
60
|
-
rubygems_version: 1.
|
56
|
+
rubygems_version: 2.1.5
|
61
57
|
signing_key:
|
62
|
-
specification_version:
|
58
|
+
specification_version: 4
|
63
59
|
summary: a library to calculate xirr on Ruby.
|
64
60
|
test_files: []
|