class MortgageBuddy::Amoratizer
Attributes
extra_monthly_payment[R]
interest_rate[R]
loan_amount[R]
period[R]
Public Class Methods
new(params={})
click to toggle source
Parameters¶ ↑
- :loan_amount
-
Loan amount. Price of home minus down payment
- :interest_rate
-
The actual interest rate of the loan
- :period
-
Number of months of the loan. 30 yr is 360. 15 yr is 189
- :extra_monthly_payment
-
This is the extra monthly principal payment. Optional and defaults to 0
# File lib/mortgage_buddy/amoratizer.rb, line 12 def initialize(params={}) @interest_rate = safe_float params[:interest_rate] @loan_amount = safe_float params[:loan_amount] @period = safe_int params[:period] @extra_monthly_payment = safe_float(params.fetch(:extra_monthly_payment, 0)) @interest_rounding_strategy = params[:interest_rounding_strategy] end
Public Instance Methods
actual_monthly_payment()
click to toggle source
# File lib/mortgage_buddy/amoratizer.rb, line 33 def actual_monthly_payment (minimum_monthly_payment + @extra_monthly_payment).round(2) end
last_monthly_payment()
click to toggle source
# File lib/mortgage_buddy/amoratizer.rb, line 41 def last_monthly_payment payments.last.payment end
minimum_monthly_payment()
click to toggle source
A = [i * P * (1 + i)^n] / [(1 + i)^n - 1] A = minimum_monthly_payment
P = loan amount i = monthly interest rate n = period (number of payments)
# File lib/mortgage_buddy/amoratizer.rb, line 29 def minimum_monthly_payment @minimum_monthly_payment ||= calculate_minimum_monthly_payment end
payments()
click to toggle source
# File lib/mortgage_buddy/amoratizer.rb, line 45 def payments @payments ||= MortgageBuddy::PaymentPlan.build(loan_amount: self.loan_amount, period: self.period, monthly_payment: actual_monthly_payment, monthly_interest_rate: monthly_interest_rate, interest_rounding_strategy: @interest_rounding_strategy) end
total_interest()
click to toggle source
# File lib/mortgage_buddy/amoratizer.rb, line 20 def total_interest payments.inject(0) { |sum, pay| sum + pay.interest }.round(2) end
total_num_payments()
click to toggle source
# File lib/mortgage_buddy/amoratizer.rb, line 37 def total_num_payments payments.length end
Private Instance Methods
calculate_minimum_monthly_payment()
click to toggle source
# File lib/mortgage_buddy/amoratizer.rb, line 54 def calculate_minimum_monthly_payment period_rate = (1 + monthly_interest_rate)**(self.period) numerator = monthly_interest_rate * self.loan_amount * period_rate denominator = period_rate - 1 (numerator / denominator).round(2) end