class MudratProjector::MortgageAmortizer
Attributes
extra_principal[RW]
Public Class Methods
new(*args, extra_principal: 0)
click to toggle source
Calls superclass method
MudratProjector::CompoundInterestAmortizer::new
# File lib/mudrat_projector/amortizer.rb, line 70 def initialize *args, extra_principal: 0 @extra_principal = extra_principal super end
Public Instance Methods
amortize()
click to toggle source
# File lib/mudrat_projector/amortizer.rb, line 86 def amortize interest_paid = 0 principal_paid = 0 mp = monthly_payment new_balance = months_amortized.times.inject initial_value do |balance, _| interest = balance * rate principal = (mp - interest) + extra_principal interest_paid += interest principal_paid += principal balance - principal end [new_balance, interest_paid, principal_paid] end
each_entry(&block)
click to toggle source
# File lib/mudrat_projector/amortizer.rb, line 79 def each_entry &block [[:credit, interest, schedule.payment_account ], [:credit, principal, schedule.payment_account ], [:debit, interest, schedule.interest_account ], [:debit, principal, schedule.principal_account]].each &block end
monthly_payment()
click to toggle source
# File lib/mudrat_projector/amortizer.rb, line 75 def monthly_payment schedule.monthly_payment end