Class: Bankroll::InterestRate
- Inherits:
-
Object
- Object
- Bankroll::InterestRate
- Extended by:
- Callable, Dry::Initializer
- Defined in:
- lib/bankroll/interest_rate.rb
Instance Method Summary collapse
Instance Method Details
#call(guess = 0.1) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bankroll/interest_rate.rb', line 16 def call(guess = 0.1) significance_required = 1e-6 stop = false next_guess = 0 loop do temp = newton_iteration( guess, @periods, @payment, @present_value, @future_value, 0 ) next_guess = (guess - temp).round(20) difference = (next_guess - guess).abs stop = difference < significance_required guess = next_guess break if stop end next_guess end |