xirr_newton_calculator 0.0.1 → 0.0.2

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.
@@ -30,21 +30,23 @@ class XirrNewtonCalculator
30
30
 
31
31
  private
32
32
 
33
+ # Argument X_n
34
+ # Returns X_n+1
33
35
  def next_value(x)
34
36
  x - @f_xn.to_f/dfdx(x)
35
37
  end
36
38
 
37
39
  def dfdx(x)
38
40
  @flows.inject(0) do |result, flow|
39
- diff_date = (flow.date - @flows[0].date)/365
40
- result += flow.value * diff_date * x.to_f ** (diff_date -1)
41
+ diff_date = (Date.parse(flow.date.to_s) - Date.parse(@flows[0].date.to_s))/365
42
+ result += flow.amount* diff_date * x.to_f ** (diff_date -1)
41
43
  end
42
44
  end
43
45
 
44
46
  def f(x)
45
47
  @f_xn = @flows.inject(0) do |result, flow|
46
- diff_date = (flow.date - @flows[0].date)/365
47
- result += flow.value * x.to_f ** diff_date
48
+ diff_date = (Date.parse(flow.date.to_s) - Date.parse(@flows[0].date.to_s))/365
49
+ result += flow.amount * x.to_f ** diff_date
48
50
  end
49
51
  end
50
52
 
@@ -1,5 +1,5 @@
1
1
  require_relative '../lib/xirr_newton_calculator'
2
- Transaction = Struct.new(:value, :date)
2
+ Transaction = Struct.new(:amount, :date)
3
3
 
4
4
  describe "XirrNewtonCalculator" do
5
5
  before :each do
metadata CHANGED
@@ -1,7 +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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: