def calculate_apr
        payment_ratio = pmt / principal_calculation
        duration = @duration
        f = lambda {|k| (k**(duration + 1) - (k**duration * (payment_ratio + 1)) + payment_ratio)}
        f_deriv = lambda { |k| ((duration + 1) * k**duration) - (duration * (payment_ratio + 1) * k**(duration - 1))}

        root = newton_raphson(f, f_deriv, monthly_rate + 1)
        100 * 12 * (root -1).to_f
      end
def calculate_apr
        payment_ratio = pmt / principal_calculation
        duration = @duration
        f = lambda {|k| (k**(duration + 1) - (k**duration * (payment_ratio + 1)) + payment_ratio)}
        f_deriv = lambda { |k| ((duration + 1) * k**duration) - (duration * (payment_ratio + 1) * k**(duration - 1))}

        root = newton_raphson(f, f_deriv, monthly_rate + 1)
        100 * 12 * (root -1).to_f
      end
solves APR
 [a (1 + a)^N] / [(1 + a)^N - 1] - P/C = 0
 where a = APR/1200, N = duration, P = monthly payment, C = loan_amount
 Newton-Raphson finds root (the value for 'a' that makes f(a) = 0)