class MudratProjector::CompoundInterestAmortizer
Attributes
schedule[R]
Public Class Methods
new(schedule, projection_range, **params)
click to toggle source
# File lib/mudrat_projector/amortizer.rb, line 9 def initialize schedule, projection_range, **params @schedule = schedule @projection_range = projection_range @balance, @interest, @principal = amortize end
Public Instance Methods
amortize()
click to toggle source
# File lib/mudrat_projector/amortizer.rb, line 15 def amortize balance = initial_value * ((1 + rate) ** months_amortized) interest = balance - initial_value [balance, interest, 0] end
each_entry(&block)
click to toggle source
# File lib/mudrat_projector/amortizer.rb, line 21 def each_entry &block [[:credit, interest, schedule.interest_account ], [:credit, principal, schedule.principal_account], [:debit, payment, schedule.payment_account ]].each &block end
initial_value()
click to toggle source
# File lib/mudrat_projector/amortizer.rb, line 27 def initial_value schedule.initial_value end
interest()
click to toggle source
# File lib/mudrat_projector/amortizer.rb, line 31 def interest @interest.round 2 end
months_amortized()
click to toggle source
# File lib/mudrat_projector/amortizer.rb, line 35 def months_amortized start = [projection_range.begin, schedule_range.begin].max finish = [projection_range.end, schedule_range.end].min DateDiff.date_diff(:month, start, finish).to_i end
next_transaction(transaction, schedule)
click to toggle source
# File lib/mudrat_projector/amortizer.rb, line 41 def next_transaction transaction, schedule Transaction.new( date: projection_range.end + 1, credits: transaction.credits, debits: transaction.debits, schedule: schedule, ) end
payment()
click to toggle source
# File lib/mudrat_projector/amortizer.rb, line 58 def payment interest + principal end
principal()
click to toggle source
# File lib/mudrat_projector/amortizer.rb, line 54 def principal @principal.round 2 end
rate()
click to toggle source
# File lib/mudrat_projector/amortizer.rb, line 50 def rate schedule.rate end
schedule_range()
click to toggle source
# File lib/mudrat_projector/amortizer.rb, line 62 def schedule_range schedule.range end