Class: Mortgagerb::Calculator

Inherits:
Object
  • Object
show all
Defined in:
lib/mortgagerb/calculator.rb

Constant Summary collapse

NUMBER_OF_MONTHS =
12

Class Method Summary collapse

Class Method Details

.periodic_amortization_payment(principal, rate, n) ⇒ Object

A



16
17
18
19
# File 'lib/mortgagerb/calculator.rb', line 16

def self.periodic_amortization_payment(principal, rate, n)
  rate_multiplier = rate_plus_one_power_to_n(rate, n)
  (principal * (rate * rate_multiplier) / (rate_multiplier - 1)).round(2)
end

.periodic_interest_rate(annual_rate) ⇒ Object

r



6
7
8
# File 'lib/mortgagerb/calculator.rb', line 6

def self.periodic_interest_rate(annual_rate)
  annual_rate / 100 / NUMBER_OF_MONTHS
end

.principal_from_amortization_payment(amortization_payment, rate, n) ⇒ Object

P



22
23
24
25
# File 'lib/mortgagerb/calculator.rb', line 22

def self.principal_from_amortization_payment(amortization_payment, rate, n)
  rate_multiplier = rate_plus_one_power_to_n(rate, n)
  (amortization_payment * (1 - (1 / rate_multiplier)) / rate).round(2)
end

.total_number_of_payments(years) ⇒ Object

n



11
12
13
# File 'lib/mortgagerb/calculator.rb', line 11

def self.total_number_of_payments(years)
  years * NUMBER_OF_MONTHS
end