xirr 0.5.4 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 19f0ca0058f57982916f0a8e2b96ceb6717a6dc4
4
- data.tar.gz: e2467167fa94e1f7132815933034502a0a999b9a
2
+ SHA256:
3
+ metadata.gz: 9a197c0e93de7a844fed9d1ecd9b60b7f9c2ddab3dccc47a1e775e885ab1a898
4
+ data.tar.gz: 6b85b7d8eae45afc6c80fc141f2b1899d225b22917225566ca1748cbac499bc2
5
5
  SHA512:
6
- metadata.gz: d6ab5e1fe60ef7859c938938b23ca06e01b148e2c1e5cb9cd8fb82f4d15e9ba30818abea6004440da26ad90016c31191bab62cde26c7e635d78ac64b3a3b0a0f
7
- data.tar.gz: 38da74ebbfe057d53139d13d25d73553db8edb1b6fbe5492dfac8816920ee0efab77ae2fb21a7edc5dfc7039cb5b77a6e7ec0a91f1b0c08d084db23affb700e8
6
+ metadata.gz: 4950571f7b684a33a4cd09831d91d5a8b712a71bdc4d103c1f8ceaea741682664581ee29a0505258b5951a2eec1bf1ff71d87bd96c2045dc872b15c4fb128290
7
+ data.tar.gz: 43d07f86b53b51d495d6642667f12cd41b41f24f850b77fef9c270a9998039d862ff1a479c675ca0f6047bdbff02f546ccd65c6d66e679b96ee3afb4c656014e
data/.gitignore CHANGED
Binary file
@@ -1 +1 @@
1
- ruby-2.2.1
1
+ 2.6.2
@@ -1,7 +1,10 @@
1
1
  language: ruby
2
2
  rvm:
3
- - '2.2.1'
4
- - '2.1.5'
5
- - '2.0.0'
3
+ - '2.2.2'
4
+ - '2.3.0'
5
+ - '2.4.0'
6
+ - '2.3.1'
7
+ - '2.4.1'
8
+ - '2.5.1'
6
9
  script:
7
10
  - bundle exec rake test_units
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # Xirr
2
- [![Build Status](https://travis-ci.org/tubedude/xirr.svg)](https://travis-ci.org/tubedude/xirr)[![Coverage Status](https://coveralls.io/repos/tubedude/xirr/badge.svg?branch=master)](https://coveralls.io/r/tubedude/xirr?branch=master)[![Code Climate](https://codeclimate.com/github/tubedude/xirr/badges/gpa.svg)](https://codeclimate.com/github/tubedude/xirr)[![Dependency Status](https://gemnasium.com/tubedude/xirr.svg)](https://gemnasium.com/tubedude/xirr)
3
-
2
+ [![Build Status](https://travis-ci.org/tubedude/xirr.svg)](https://travis-ci.org/tubedude/xirr)[![Coverage Status](https://coveralls.io/repos/tubedude/xirr/badge.svg?branch=master)](https://coveralls.io/r/tubedude/xirr?branch=master)[![Code Climate](https://codeclimate.com/github/tubedude/xirr/badges/gpa.svg)](https://codeclimate.com/github/tubedude/xirr)[![Ebert](https://ebertapp.io/github/tubedude/xirr.svg)](https://ebertapp.io/github/tubedude/xirr)
4
3
 
5
4
  This is a gem to calculate XIRR on Bisection Method or Newton Method.
6
5
 
@@ -20,24 +19,24 @@ Or install it yourself as:
20
19
 
21
20
  ## Usage
22
21
 
23
-
24
- include Xirr
22
+ ```rb
23
+ include Xirr
25
24
 
26
- cf = Cashflow.new
27
- cf << Transaction.new(-1000, date: '2014-01-01'.to_date)
28
- cf << Transaction.new(-2000, date: '2014-03-01'.to_date)
29
- cf << Transaction.new( 4500, date: '2015-12-01'.to_date)
30
- cf.xirr
31
- # 0.25159694345042327 # [BigDecimal]
32
-
33
- flow = []
34
- flow << Transaction.new(-1000, date: '2014-01-01'.to_date)
35
- flow << Transaction.new(-2000, date: '2014-03-01'.to_date)
36
- flow << Transaction.new( 4500, date: '2015-12-01'.to_date)
37
-
38
- cf = Cashflow.new flow: flow
39
- cf.xirr
40
-
25
+ cf = Xirr::Cashflow.new
26
+ cf << Xirr::Transaction.new(-1000, date: '2014-01-01'.to_date)
27
+ cf << Xirr::Transaction.new(-2000, date: '2014-03-01'.to_date)
28
+ cf << Xirr::Transaction.new( 4500, date: '2015-12-01'.to_date)
29
+ cf.xirr
30
+ # 0.25159694345042327 # [BigDecimal]
31
+
32
+ flow = []
33
+ flow << Xirr::Transaction.new(-1000, date: '2014-01-01'.to_date)
34
+ flow << Xirr::Transaction.new(-2000, date: '2014-03-01'.to_date)
35
+ flow << Xirr::Transaction.new( 4500, date: '2015-12-01'.to_date)
36
+
37
+ cf = Xirr::Cashflow.new(flow: flow)
38
+ cf.xirr
39
+ ```
41
40
 
42
41
  ## Configuration
43
42
 
@@ -53,6 +52,17 @@ Or install it yourself as:
53
52
 
54
53
  http://rubydoc.info/github/tubedude/xirr/master/frames
55
54
 
55
+ ## Supported versions
56
+
57
+ Ruby:
58
+ - 2.2.1
59
+ - 2.3
60
+ - 2.4
61
+
62
+ ActiveSupport:
63
+ - 4.2
64
+ - 5
65
+
56
66
  ## Thanks
57
67
 
58
68
  http://puneinvestor.wordpress.com/2013/10/01/calculate-xirr-in-ruby-bisection-method/
@@ -62,6 +72,7 @@ https://github.com/wkranec/finance
62
72
 
63
73
  1. Fork it ( https://github.com/tubedude/xirr/fork )
64
74
  2. Create your feature branch (`git checkout -b my-new-feature`)
65
- 3. Commit your changes (`git commit -am 'Add some feature'`)
66
- 4. Push to the branch (`git push origin my-new-feature`)
67
- 5. Create a new Pull Request
75
+ 3. Run specs (`rake default`)
76
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
77
+ 5. Push to the branch (`git push origin my-new-feature`)
78
+ 6. Create a new Pull Request
data/Rakefile CHANGED
@@ -10,4 +10,3 @@ Rake::TestTask.new("test_units") do |t|
10
10
  t.verbose = false
11
11
  t.warning = false
12
12
  end
13
-
@@ -10,8 +10,6 @@ require 'xirr/newton_method'
10
10
  # @abstract adds a {Xirr::Cashflow} and {Xirr::Transaction} classes to calculate IRR of irregular transactions.
11
11
  # Calculates Xirr
12
12
  module Xirr
13
-
14
13
  autoload :Transaction, 'xirr/transaction'
15
14
  autoload :Cashflow, 'xirr/cashflow'
16
-
17
15
  end
@@ -1,5 +1,5 @@
1
+ # frozen_string_literal: true
1
2
  module Xirr
2
-
3
3
  # Base module for XIRR calculation Methods
4
4
  module Base
5
5
  extend ActiveSupport::Concern
@@ -24,7 +24,7 @@ module Xirr
24
24
  # @return [BigDecimal]
25
25
  def xnpv(rate)
26
26
  cf.inject(0) do |sum, t|
27
- sum += xnpv_c rate, t.amount, periods_from_start(t.date)
27
+ sum + (xnpv_c rate, t.amount, periods_from_start(t.date))
28
28
  end
29
29
  end
30
30
 
@@ -35,6 +35,5 @@ module Xirr
35
35
  return amount / pow(1 + rate, period);
36
36
  }'
37
37
  }
38
-
39
38
  end
40
39
  end
@@ -1,5 +1,5 @@
1
+ # frozen_string_literal: true
1
2
  module Xirr
2
-
3
3
  # Methods that will be included in Cashflow to calculate XIRR
4
4
  class Bisection
5
5
  include Base
@@ -8,11 +8,11 @@ module Xirr
8
8
  # @return [BigDecimal]
9
9
  # @param midpoint [Float]
10
10
  # An initial guess rate will override the {Cashflow#irr_guess}
11
- def xirr midpoint, options
11
+ def xirr(midpoint, options)
12
12
 
13
13
  # Initial values
14
- left = [BigDecimal.new(-0.99999999, Xirr::PRECISION), cf.irr_guess].min
15
- right = [BigDecimal.new(9.99999999, Xirr::PRECISION), cf.irr_guess + 1].max
14
+ left = [BigDecimal(-0.99999999, Xirr::PRECISION), cf.irr_guess].min
15
+ right = [BigDecimal(9.99999999, Xirr::PRECISION), cf.irr_guess + 1].max
16
16
  @original_right = right
17
17
  midpoint ||= cf.irr_guess
18
18
 
@@ -38,9 +38,10 @@ module Xirr
38
38
  # @return [Array]
39
39
  # Calculates the Bisections
40
40
  def bisection(left, midpoint, right)
41
- _left, _mid = npv_positive?(left), npv_positive?(midpoint)
41
+ _left = xnpv(left).positive?
42
+ _mid = xnpv(midpoint).positive?
42
43
  if _left && _mid
43
- return left, left, left, true if npv_positive?(right) # Not Enough Precision in the left to find the IRR
44
+ return left, left, left, true if xnpv(right).positive? # Not Enough Precision in the left to find the IRR
44
45
  end
45
46
  if _left == _mid
46
47
  return midpoint, format_irr(midpoint, right), right, false # Result is to the Right
@@ -49,13 +50,6 @@ module Xirr
49
50
  end
50
51
  end
51
52
 
52
- # @param midpoint [Float]
53
- # @return [Bolean]
54
- # Returns true if result is to the right ot the range
55
- def npv_positive?(midpoint)
56
- xnpv(midpoint) > 0
57
- end
58
-
59
53
  # @param left [Float]
60
54
  # @param right [Float]
61
55
  # @return [Float] IRR of the Cashflow
@@ -78,19 +72,15 @@ module Xirr
78
72
  def loop_rates(left, midpoint, right, iteration_limit)
79
73
  runs = 0
80
74
  while (right - left).abs > Xirr::EPS && runs < iteration_limit do
81
- runs += 1
75
+ runs += 1
82
76
  left, midpoint, right, should_stop = bisection(left, midpoint, right)
83
77
  break if should_stop
84
78
  if right_limit_reached?(midpoint)
85
- right = right * 2
86
- @original_right = @original_right * 2
79
+ right *= 2
80
+ @original_right *= 2
87
81
  end
88
82
  end
89
83
  return midpoint, runs
90
84
  end
91
-
92
-
93
85
  end
94
-
95
86
  end
96
-
@@ -1,5 +1,5 @@
1
+ # frozen_string_literal: true
1
2
  module Xirr
2
-
3
3
  # Expands [Array] to store a set of transactions which will be used to calculate the XIRR
4
4
  # @note A Cashflow should consist of at least two transactions, one positive and one negative.
5
5
  class Cashflow < Array
@@ -59,7 +59,7 @@ module Xirr
59
59
  method, options = process_options(method, options)
60
60
  if invalid?
61
61
  raise ArgumentError, invalid_message if options[:raise_exception]
62
- BigDecimal.new(0, Xirr::PRECISION)
62
+ BigDecimal(0, Xirr::PRECISION)
63
63
  else
64
64
  xirr = choose_(method).send :xirr, guess, options
65
65
  xirr = choose_(other_calculation_method(method)).send(:xirr, guess, options) if (xirr.nil? || xirr.nan?) && fallback
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'bigdecimal/newton'
2
3
  include Newton
3
4
 
@@ -20,7 +21,7 @@ module Xirr
20
21
  # define default values
21
22
  values.each do |key, value|
22
23
  define_method key do
23
- BigDecimal.new(value, Xirr::PRECISION)
24
+ BigDecimal(value, Xirr::PRECISION)
24
25
  end
25
26
  end
26
27
 
@@ -35,8 +36,8 @@ module Xirr
35
36
  # Necessary for #nlsolve
36
37
  # @param x [BigDecimal]
37
38
  def values(x)
38
- value = @transactions.send(@function, BigDecimal.new(x[0].to_s, Xirr::PRECISION))
39
- [BigDecimal.new(value.to_s, Xirr::PRECISION)]
39
+ value = @transactions.send(@function, BigDecimal(x[0].to_s, Xirr::PRECISION))
40
+ [BigDecimal(value.to_s, Xirr::PRECISION)]
40
41
  end
41
42
  end
42
43
 
@@ -1,5 +1,5 @@
1
+ # frozen_string_literal: true
1
2
  module Xirr
2
-
3
3
  # A unit of the Cashflow.
4
4
  class Transaction
5
5
  attr_reader :amount, :date
@@ -1,4 +1,4 @@
1
1
  module Xirr
2
2
  # Version of the Gem
3
- VERSION = '0.5.4'
3
+ VERSION = '0.6.1'
4
4
  end
@@ -1,7 +1,6 @@
1
1
  require_relative 'test_helper'
2
2
 
3
3
  describe 'Cashflows' do
4
-
5
4
  describe 'of an ok investment' do
6
5
  before(:all) do
7
6
  @cf = Cashflow.new
@@ -39,7 +38,6 @@ describe 'Cashflows' do
39
38
  end
40
39
  end
41
40
 
42
-
43
41
  describe 'of an inverted ok investment' do
44
42
  before(:all) do
45
43
  @cf = Cashflow.new
@@ -136,10 +134,9 @@ describe 'Cashflows' do
136
134
  end
137
135
 
138
136
  it 'returns 0 instead of exception ' do
139
- assert_equal BigDecimal.new(0, 6), @cf.xirr
137
+ assert_equal BigDecimal(0, 6), @cf.xirr
140
138
  end
141
139
 
142
-
143
140
  it 'with a wrong method is invalid' do
144
141
  assert_raises(ArgumentError) { @cf.xirr raise_exception: true, method: :no_method }
145
142
  end
@@ -151,7 +148,6 @@ describe 'Cashflows' do
151
148
  it 'raises error when xirr is called' do
152
149
  assert true, !@cf.irr_guess
153
150
  end
154
-
155
151
  end
156
152
 
157
153
  describe 'an all-positive Cashflow' do
@@ -194,7 +190,6 @@ describe 'Cashflows' do
194
190
  it 'has an educated guess' do
195
191
  assert_equal -0.022, @cf.irr_guess
196
192
  end
197
-
198
193
  end
199
194
 
200
195
  describe 'of a long investment' do
@@ -213,7 +208,6 @@ describe 'Cashflows' do
213
208
  it 'has an educated guess' do
214
209
  assert_equal 0.112, @cf.irr_guess.round(6)
215
210
  end
216
-
217
211
  end
218
212
 
219
213
  describe 'reapeated cashflow' do
@@ -232,7 +226,6 @@ describe 'Cashflows' do
232
226
  it 'sums all transactions' do
233
227
  assert_equal -3000.0, @cf.compact_cf.map(&:amount).inject(&:+)
234
228
  end
235
-
236
229
  end
237
230
 
238
231
  describe 'of a real case' do
@@ -278,7 +271,6 @@ describe 'Cashflows' do
278
271
  it 'is a long and bad investment and newton generates an error' do
279
272
  assert_equal '-1.0'.to_f, @cf.xirr #(method: :newton_method)
280
273
  end
281
-
282
274
  end
283
275
 
284
276
  describe 'xichen27' do
@@ -290,8 +282,8 @@ describe 'Cashflows' do
290
282
  assert_equal '-0.996814607'.to_f.round(3), cf.xirr.to_f.round(3)
291
283
  end
292
284
  end
293
- describe 'marano' do
294
285
 
286
+ describe 'marano' do
295
287
  it 'it matchs Excel' do
296
288
  cf = Cashflow.new
297
289
  cf << Transaction.new(900.0, date: '2014-11-07'.to_date)
@@ -301,7 +293,6 @@ describe 'Cashflows' do
301
293
  end
302
294
 
303
295
  describe 'period' do
304
-
305
296
  it 'has zero for years of investment' do
306
297
  cf = Cashflow.new flow: [Transaction.new(105187.06, date: '2011-12-07'.to_date), Transaction.new(-105187.06 * 1.0697668105671994, date: '2011-12-07'.to_date)]
307
298
  assert_equal 0.0, cf.irr_guess
@@ -317,7 +308,5 @@ describe 'Cashflows' do
317
308
  cf = Cashflow.new period: 100, flow: [Transaction.new(-1000, date: Date.new(1957, 1, 1)), Transaction.new(390000, date: Date.new(2013, 1, 1))]
318
309
  assert_equal 0.112339, cf.xirr(period: 365.0)
319
310
  end
320
-
321
311
  end
322
-
323
312
  end
@@ -4,14 +4,16 @@ describe 'Transaction' do
4
4
  before(:all) do
5
5
  @t = Transaction.new(1000, date: Date.today)
6
6
  end
7
+
7
8
  it 'converts amount to float' do
8
9
  assert true, @t.amount.kind_of?(Float)
9
10
  end
11
+
10
12
  it 'retreives the date' do
11
13
  assert_equal Date.today, @t.date
12
14
  end
15
+
13
16
  it 'has inspect' do
14
17
  assert_equal "T(1000.0,#{Date.today})", @t.inspect
15
18
  end
16
-
17
19
  end
@@ -18,13 +18,14 @@ 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.add_development_dependency 'bundler', '~> 1.6'
22
- spec.add_development_dependency 'rake', '~> 10'
21
+ spec.required_ruby_version = '>=2.2.2'
23
22
 
24
- spec.required_ruby_version = '>=2.0'
25
- spec.add_dependency 'activesupport', '~> 4'
23
+ spec.add_dependency 'activesupport', '>= 4.1', '<= 5.3'
26
24
  spec.add_dependency 'RubyInline', '~> 3'
27
- spec.add_development_dependency 'minitest', '~> 5.4'
28
- spec.add_development_dependency 'coveralls', '~> 0'
29
25
 
26
+ spec.add_development_dependency 'activesupport', '~> 4.1.0'
27
+ spec.add_development_dependency 'minitest', '~> 5.11'
28
+ spec.add_development_dependency 'coveralls', '~> 0'
29
+ spec.add_development_dependency 'bundler', '~> 1.6'
30
+ spec.add_development_dependency 'rake', '~> 10'
30
31
  end
metadata CHANGED
@@ -1,99 +1,119 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xirr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tubedude
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-06 00:00:00.000000000 Z
11
+ date: 2019-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ - - "<="
21
+ - !ruby/object:Gem::Version
22
+ version: '5.3'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.1'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: '5.3'
33
+ - !ruby/object:Gem::Dependency
34
+ name: RubyInline
15
35
  requirement: !ruby/object:Gem::Requirement
16
36
  requirements:
17
37
  - - "~>"
18
38
  - !ruby/object:Gem::Version
19
- version: '1.6'
20
- type: :development
39
+ version: '3'
40
+ type: :runtime
21
41
  prerelease: false
22
42
  version_requirements: !ruby/object:Gem::Requirement
23
43
  requirements:
24
44
  - - "~>"
25
45
  - !ruby/object:Gem::Version
26
- version: '1.6'
46
+ version: '3'
27
47
  - !ruby/object:Gem::Dependency
28
- name: rake
48
+ name: activesupport
29
49
  requirement: !ruby/object:Gem::Requirement
30
50
  requirements:
31
51
  - - "~>"
32
52
  - !ruby/object:Gem::Version
33
- version: '10'
53
+ version: 4.1.0
34
54
  type: :development
35
55
  prerelease: false
36
56
  version_requirements: !ruby/object:Gem::Requirement
37
57
  requirements:
38
58
  - - "~>"
39
59
  - !ruby/object:Gem::Version
40
- version: '10'
60
+ version: 4.1.0
41
61
  - !ruby/object:Gem::Dependency
42
- name: activesupport
62
+ name: minitest
43
63
  requirement: !ruby/object:Gem::Requirement
44
64
  requirements:
45
65
  - - "~>"
46
66
  - !ruby/object:Gem::Version
47
- version: '4'
48
- type: :runtime
67
+ version: '5.11'
68
+ type: :development
49
69
  prerelease: false
50
70
  version_requirements: !ruby/object:Gem::Requirement
51
71
  requirements:
52
72
  - - "~>"
53
73
  - !ruby/object:Gem::Version
54
- version: '4'
74
+ version: '5.11'
55
75
  - !ruby/object:Gem::Dependency
56
- name: RubyInline
76
+ name: coveralls
57
77
  requirement: !ruby/object:Gem::Requirement
58
78
  requirements:
59
79
  - - "~>"
60
80
  - !ruby/object:Gem::Version
61
- version: '3'
62
- type: :runtime
81
+ version: '0'
82
+ type: :development
63
83
  prerelease: false
64
84
  version_requirements: !ruby/object:Gem::Requirement
65
85
  requirements:
66
86
  - - "~>"
67
87
  - !ruby/object:Gem::Version
68
- version: '3'
88
+ version: '0'
69
89
  - !ruby/object:Gem::Dependency
70
- name: minitest
90
+ name: bundler
71
91
  requirement: !ruby/object:Gem::Requirement
72
92
  requirements:
73
93
  - - "~>"
74
94
  - !ruby/object:Gem::Version
75
- version: '5.4'
95
+ version: '1.6'
76
96
  type: :development
77
97
  prerelease: false
78
98
  version_requirements: !ruby/object:Gem::Requirement
79
99
  requirements:
80
100
  - - "~>"
81
101
  - !ruby/object:Gem::Version
82
- version: '5.4'
102
+ version: '1.6'
83
103
  - !ruby/object:Gem::Dependency
84
- name: coveralls
104
+ name: rake
85
105
  requirement: !ruby/object:Gem::Requirement
86
106
  requirements:
87
107
  - - "~>"
88
108
  - !ruby/object:Gem::Version
89
- version: '0'
109
+ version: '10'
90
110
  type: :development
91
111
  prerelease: false
92
112
  version_requirements: !ruby/object:Gem::Requirement
93
113
  requirements:
94
114
  - - "~>"
95
115
  - !ruby/object:Gem::Version
96
- version: '0'
116
+ version: '10'
97
117
  description: Calculates IRR of a Cashflow, similar to Excel's, XIRR formula. It defaults
98
118
  to Newton Method, but will calculate Bisection as well.
99
119
  email:
@@ -136,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
156
  requirements:
137
157
  - - ">="
138
158
  - !ruby/object:Gem::Version
139
- version: '2.0'
159
+ version: 2.2.2
140
160
  required_rubygems_version: !ruby/object:Gem::Requirement
141
161
  requirements:
142
162
  - - ">="
@@ -144,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
164
  version: '0'
145
165
  requirements: []
146
166
  rubyforge_project:
147
- rubygems_version: 2.4.6
167
+ rubygems_version: 2.7.7
148
168
  signing_key:
149
169
  specification_version: 4
150
170
  summary: Calculates XIRR (Bisection and Newton method) of a cashflow