module FinancialMath::CompoundInterest
Public Instance Methods
average_growth_rate(future_value:, present_value:, periods: 1)
click to toggle source
# File lib/financial_math/compound_interest.rb, line 30 def average_growth_rate(future_value:, present_value:, periods: 1) ((future_value / present_value)**(1.0 / periods) - 1).round(4) end
continous_future_value(present_value:, interest_rate:, periods: 1)
click to toggle source
# File lib/financial_math/compound_interest.rb, line 34 def continous_future_value(present_value:, interest_rate:, periods: 1) future_value = present_value * Math.exp(interest_rate * periods) future_value.round(2) end
continous_present_value(future_value:, interest_rate:, periods: 1)
click to toggle source
# File lib/financial_math/compound_interest.rb, line 39 def continous_present_value(future_value:, interest_rate:, periods: 1) present_value = future_value / Math.exp(interest_rate * periods) present_value.round(2) end
effective_rate(nominal_rate:, frequency: 1)
click to toggle source
# File lib/financial_math/compound_interest.rb, line 15 def effective_rate(nominal_rate:, frequency: 1) effective_rate = (1 + nominal_rate / frequency)**frequency - 1 effective_rate.round(4) end
future_value(present_value:, interest_rate:, frequency: 1.0, periods: 1)
click to toggle source
# File lib/financial_math/compound_interest.rb, line 9 def future_value(present_value:, interest_rate:, frequency: 1.0, periods: 1) factor_val = factor(interest_rate: interest_rate, frequency: frequency, periods: periods) (present_value * factor_val).round(2) end
internal_rate_of_return(future_value:, present_value:, periods: 1)
click to toggle source
# File lib/financial_math/compound_interest.rb, line 48 def internal_rate_of_return(future_value:, present_value:, periods: 1) ((future_value / present_value)**(1.0 / periods) - 1).round(4) end
nominal_rate(effective_rate:, frequency: 1.0)
click to toggle source
# File lib/financial_math/compound_interest.rb, line 20 def nominal_rate(effective_rate:, frequency: 1.0) root = nth_root(frequency: frequency) nominal_rate = ((1 + effective_rate)**root - 1) * frequency nominal_rate.round(4) end
period_of_capital_duplication(interest_rate:)
click to toggle source
# File lib/financial_math/compound_interest.rb, line 26 def period_of_capital_duplication(interest_rate:) (Math.log10(2) / Math.log10(1 + interest_rate)).round(2) end
present_value(future_value:, interest_rate:, frequency: 1.0, periods: 1)
click to toggle source
# File lib/financial_math/compound_interest.rb, line 3 def present_value(future_value:, interest_rate:, frequency: 1.0, periods: 1) factor_val = factor(interest_rate: interest_rate, frequency: frequency, periods: periods) (future_value / factor_val).round(2) end
real_rate_of_return(interest_rate:, inflation_rate:)
click to toggle source
# File lib/financial_math/compound_interest.rb, line 44 def real_rate_of_return(interest_rate:, inflation_rate:) ((interest_rate - inflation_rate) / (1 + inflation_rate)).round 4 end
Private Instance Methods
factor(interest_rate:, frequency: 1.0, periods: 1)
click to toggle source
# File lib/financial_math/compound_interest.rb, line 54 def factor(interest_rate:, frequency: 1.0, periods: 1) (1.0 + interest_rate / frequency)**(frequency * periods).to_f end
nth_root(frequency: 1)
click to toggle source
# File lib/financial_math/compound_interest.rb, line 58 def nth_root(frequency: 1) 1.0 / frequency end