Module: FinancialMath::CompoundInterest

Defined in:
lib/financial_math/compound_interest.rb

Instance Method Summary collapse

Instance Method Details

#average_growth_rate(future_value:, present_value:, periods: 1) ⇒ Object



30
31
32
# 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) ⇒ Object



34
35
36
37
# 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) ⇒ Object



39
40
41
42
# 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) ⇒ Object



15
16
17
18
# 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) ⇒ Object



9
10
11
12
13
# 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) ⇒ Object



48
49
50
# 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) ⇒ Object



20
21
22
23
24
# 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:) ⇒ Object



26
27
28
# 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) ⇒ Object



3
4
5
6
7
# 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:) ⇒ Object



44
45
46
# 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