def rate(nper, pmt, pv, fv = 0, end_or_beginning = 0, rate_guess = 0.10)
      guess = rate_guess
      tolerancy = 1e-6
      close = false

      begin
        temp = newton_iter(guess, nper, pmt, pv, fv, end_or_beginning)
        next_guess = (guess - temp).round(20)
        diff = (next_guess - guess).abs
        close = diff < tolerancy
        guess = next_guess
      end while !close

      next_guess
    end
def rate(nper, pmt, pv, fv = 0, end_or_beginning = 0, rate_guess = 0.10)
      guess = rate_guess
      tolerancy = 1e-6
      close = false

      begin
        temp = newton_iter(guess, nper, pmt, pv, fv, end_or_beginning)
        next_guess = (guess - temp).round(20)
        diff = (next_guess - guess).abs
        close = diff < tolerancy
        guess = next_guess
      end while !close

      next_guess
    end
Calculates the interest rate of an annuity investment based on
 constant-amount periodic payments and the assumption of a constant interest rate.

 @param nper [Integer] The number of payments to be made (number of periods)
 @param pmt [Float] The amount per period to be paid
 @param pv [Float] The present value
 @param fv [Float] The future value remaining after the final payment has been made
 @param end_or_begining [Integer] Whether payments are due at the end (0) or
   beggining (1) of each period
 @param rate_guess [Float] An estimate for what the interest rate will be

 @return [Float]

 @example
   Exonio.rate(12, 363.78, -3056.00) # ==> 0.05963422268883278