Class: MortgageBuddy::Amoratizer
- Inherits:
-
Object
- Object
- MortgageBuddy::Amoratizer
- Defined in:
- lib/mortgage_buddy/amoratizer.rb
Instance Attribute Summary collapse
-
#extra_monthly_payment ⇒ Object
readonly
optional.
-
#interest_rate ⇒ Object
readonly
Returns the value of attribute interest_rate.
-
#loan_amount ⇒ Object
readonly
Returns the value of attribute loan_amount.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
Instance Method Summary collapse
- #actual_monthly_payment ⇒ Object
-
#initialize(params = {}) ⇒ Amoratizer
constructor
Parameters [:loan_amount] Loan amount.
- #last_monthly_payment ⇒ Object
-
#minimum_monthly_payment ⇒ Object
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).
- #payments ⇒ Object
- #total_interest ⇒ Object
- #total_num_payments ⇒ Object
Methods included from SafeNum
Methods included from Monthly
Constructor Details
#initialize(params = {}) ⇒ Amoratizer
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
12 13 14 15 16 17 18 |
# 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 |
Instance Attribute Details
#extra_monthly_payment ⇒ Object (readonly)
optional
5 6 7 |
# File 'lib/mortgage_buddy/amoratizer.rb', line 5 def extra_monthly_payment @extra_monthly_payment end |
#interest_rate ⇒ Object (readonly)
Returns the value of attribute interest_rate.
4 5 6 |
# File 'lib/mortgage_buddy/amoratizer.rb', line 4 def interest_rate @interest_rate end |
#loan_amount ⇒ Object (readonly)
Returns the value of attribute loan_amount.
4 5 6 |
# File 'lib/mortgage_buddy/amoratizer.rb', line 4 def loan_amount @loan_amount end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
4 5 6 |
# File 'lib/mortgage_buddy/amoratizer.rb', line 4 def period @period end |
Instance Method Details
#actual_monthly_payment ⇒ Object
33 34 35 |
# File 'lib/mortgage_buddy/amoratizer.rb', line 33 def actual_monthly_payment (minimum_monthly_payment + @extra_monthly_payment).round(2) end |
#last_monthly_payment ⇒ Object
41 42 43 |
# File 'lib/mortgage_buddy/amoratizer.rb', line 41 def last_monthly_payment payments.last.payment end |
#minimum_monthly_payment ⇒ Object
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)
29 30 31 |
# File 'lib/mortgage_buddy/amoratizer.rb', line 29 def minimum_monthly_payment @minimum_monthly_payment ||= calculate_minimum_monthly_payment end |
#payments ⇒ Object
45 46 47 48 49 50 51 |
# 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 ⇒ Object
20 21 22 |
# 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 ⇒ Object
37 38 39 |
# File 'lib/mortgage_buddy/amoratizer.rb', line 37 def total_num_payments payments.length end |