Class: Finance::Amortization

Inherits:
Object
  • Object
show all
Defined in:
lib/rvgp/reconcilers/shorthand/finance_gem_hacks.rb

Overview

The default functionality in this class, specified in the finance gem, is overwritten, to support the additional_payments feature of RVGP::Reconcilers::Shorthand::Mortgage

Instance Method Summary collapse

Instance Method Details

#amortize(rate) ⇒ Object

This was copied out of : github.com/marksweston/finance/blob/master/lib/finance/amortization.rb Because bank of america doesn’t round the same way…



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rvgp/reconcilers/shorthand/finance_gem_hacks.rb', line 14

def amortize(rate)
  # For the purposes of calculating a payment, the relevant time
  # period is the remaining number of periods in the loan, not
  # necessarily the duration of the rate itself.
  periods = @periods - @period
  amount = Finance::Amortization.payment @balance, rate.monthly, periods

  pmt = Finance::Payment.new amount, period: @period

  rate.duration.to_i.times do
    # NOTE: This is the only change I made:
    #       (well, I also removed the pmt based block.call above)
    @block&.call(@period, self)

    # Do this first in case the balance is zero already.
    break if @balance.zero?

    # Compute and record interest on the outstanding balance.
    int = (@balance * rate.monthly).round(2)

    interest = Finance::Interest.new int, period: @period

    @balance += interest.amount
    @transactions << interest.dup

    # Record payment.  Don't pay more than the outstanding balance.
    pmt.amount = -@balance if pmt.amount.abs > @balance
    @transactions << pmt.dup
    @balance += pmt.amount

    @period += 1
  end
end

#balance=(val) ⇒ Object



7
8
9
# File 'lib/rvgp/reconcilers/shorthand/finance_gem_hacks.rb', line 7

def balance=(val)
  @balance = DecNum.new val
end