class MortgageBuddy::MortgageCost
Constants
- DEFAULT_FEES
- DEFAULT_PERIOD
- DEFAULT_POINTS
Attributes
fees[R]
interest_rate[R]
loan_amount[R]
period[R]
points[R]
Public Class Methods
new(params={})
click to toggle source
Parameters¶ ↑
- :loan_amount
-
Loan amount. Price of home minus down payment
- :interest_rate
-
The interest rate of the loan
- :period
-
Number of months of the loan. 30 yr is 360. 15 yr is 189
- :fees
-
Closing cost fees. Optional and defaults to 0
- :points
-
Points. Optional and defaults to 0
# File lib/mortgage_buddy/mortgage_cost.rb, line 15 def initialize(params={}) raise '[:loan_amount] required' if params[:loan_amount].blank? raise '[:interest_rate] required' if params[:interest_rate].blank? @loan_amount = safe_float params[:loan_amount] @interest_rate = safe_float params[:interest_rate] @period = safe_int params.fetch(:period, DEFAULT_PERIOD) @fees = safe_int params.fetch(:fees, DEFAULT_FEES) @points = safe_float params.fetch(:points, DEFAULT_POINTS) end
Public Instance Methods
apr()
click to toggle source
# File lib/mortgage_buddy/mortgage_cost.rb, line 25 def apr @apr ||= MortgageBuddy::AprCalculator.new(loan_amount: @loan_amount, monthly_payment_with_fees: monthly_payment_with_fees, period: period, monthly_interest_rate: monthly_interest_rate).apr end
monthly_payment()
click to toggle source
# File lib/mortgage_buddy/mortgage_cost.rb, line 32 def monthly_payment @monthly_payment ||= calculate_monthly_payment(@loan_amount, monthly_interest_rate, @period) end
monthly_payment_with_fees()
click to toggle source
# File lib/mortgage_buddy/mortgage_cost.rb, line 36 def monthly_payment_with_fees @monthly_payment_with_fees ||= calculate_monthly_payment(@loan_amount + total_fees, monthly_interest_rate, @period) end
total_fees(negative_allowed = false)
click to toggle source
# File lib/mortgage_buddy/mortgage_cost.rb, line 40 def total_fees(negative_allowed = false) #fees may not be negative (borrower is not paid) total_fees = calculate_total_fees !negative_allowed && total_fees < 0 ? 0 : total_fees end
Private Instance Methods
calculate_monthly_payment(amount, monthly_rate, period)
click to toggle source
# File lib/mortgage_buddy/mortgage_cost.rb, line 47 def calculate_monthly_payment(amount, monthly_rate, period) (amount * (monthly_rate/(1 - (1 + monthly_rate)**(-period)))).round(2) end
calculate_total_fees()
click to toggle source
# File lib/mortgage_buddy/mortgage_cost.rb, line 51 def calculate_total_fees (@fees + (@loan_amount * points/100)).round(2) end